(document: vs.TextDocument, position: Position, callback: (newPosition: vs.Position | undefined) => void)
| 137 | } |
| 138 | |
| 139 | public trackPosition(document: vs.TextDocument, position: Position, callback: (newPosition: vs.Position | undefined) => void): IAmDisposable { |
| 140 | const vsPosition = new vs.Position(position.line, position.character); |
| 141 | const offset = document.offsetAt(vsPosition); |
| 142 | const key = document.uri.toString(); |
| 143 | const entry: PositionTrackerEntry = { |
| 144 | offset, |
| 145 | position: vsPosition, |
| 146 | callback, |
| 147 | dispose: () => { |
| 148 | const trackers = this.trackers.get(key); |
| 149 | if (!trackers) |
| 150 | return; |
| 151 | |
| 152 | const index = trackers.indexOf(entry); |
| 153 | if (index !== -1) { |
| 154 | trackers.splice(index, 1); |
| 155 | } |
| 156 | if (trackers.length === 0) { |
| 157 | this.trackers.delete(key); |
| 158 | } |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | if (!this.trackers.has(key)) { |
| 163 | this.trackers.set(key, []); |
| 164 | } |
| 165 | this.trackers.get(key)!.push(entry); |
| 166 | |
| 167 | return entry; |
| 168 | } |
| 169 | |
| 170 | private handleDocumentChange(e: vs.TextDocumentChangeEvent) { |
| 171 | // Some "document changes" are things like metadata and don't |
no test coverage detected