MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / trackPosition

Method trackPosition

src/shared/vscode/trackers.ts:139–168  ·  view source on GitHub ↗
(document: vs.TextDocument, position: Position, callback: (newPosition: vs.Position | undefined) => void)

Source from the content-addressed store, hash-verified

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

Callers 2

trackRangeMethod · 0.80

Calls 5

deleteMethod · 0.80
hasMethod · 0.80
setMethod · 0.80
toStringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected