@volar/language-service 1.0.16 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/out/baseDocumentService.js +13 -28
  2. package/out/baseLanguageService.d.ts +2 -2
  3. package/out/baseLanguageService.js +4 -4
  4. package/out/documentFeatures/autoInsert.js +2 -2
  5. package/out/documentFeatures/colorPresentations.js +4 -4
  6. package/out/documentFeatures/documentColors.js +3 -3
  7. package/out/documentFeatures/documentSymbols.js +4 -4
  8. package/out/documentFeatures/foldingRanges.js +1 -1
  9. package/out/documentFeatures/format.js +37 -35
  10. package/out/documentFeatures/linkedEditingRanges.js +2 -2
  11. package/out/documentFeatures/selectionRanges.js +3 -3
  12. package/out/documents.d.ts +26 -56
  13. package/out/documents.js +102 -144
  14. package/out/languageFeatures/autoInsert.js +7 -7
  15. package/out/languageFeatures/callHierarchy.d.ts +1 -1
  16. package/out/languageFeatures/callHierarchy.js +33 -34
  17. package/out/languageFeatures/codeActionResolve.js +2 -3
  18. package/out/languageFeatures/codeActions.d.ts +1 -1
  19. package/out/languageFeatures/codeActions.js +10 -10
  20. package/out/languageFeatures/codeLens.js +3 -3
  21. package/out/languageFeatures/complete.d.ts +1 -1
  22. package/out/languageFeatures/complete.js +32 -33
  23. package/out/languageFeatures/completeResolve.js +3 -4
  24. package/out/languageFeatures/definition.d.ts +2 -2
  25. package/out/languageFeatures/definition.js +24 -20
  26. package/out/languageFeatures/documentHighlights.js +15 -15
  27. package/out/languageFeatures/documentLinks.js +8 -9
  28. package/out/languageFeatures/documentSemanticTokens.js +5 -5
  29. package/out/languageFeatures/executeCommand.d.ts +1 -1
  30. package/out/languageFeatures/executeCommand.js +2 -1
  31. package/out/languageFeatures/fileReferences.js +3 -4
  32. package/out/languageFeatures/fileRename.js +4 -4
  33. package/out/languageFeatures/hover.js +3 -3
  34. package/out/languageFeatures/inlayHints.js +10 -10
  35. package/out/languageFeatures/references.js +21 -20
  36. package/out/languageFeatures/rename.d.ts +2 -2
  37. package/out/languageFeatures/rename.js +99 -80
  38. package/out/languageFeatures/renamePrepare.js +3 -3
  39. package/out/languageFeatures/signatureHelp.js +1 -1
  40. package/out/languageFeatures/validation.js +19 -18
  41. package/out/languageFeatures/workspaceSymbols.js +6 -5
  42. package/out/types.d.ts +9 -8
  43. package/out/utils/definePlugin.d.ts +3 -2
  44. package/out/utils/definePlugin.js +9 -6
  45. package/out/utils/featureWorkers.d.ts +5 -5
  46. package/out/utils/featureWorkers.js +15 -14
  47. package/package.json +7 -7
package/out/documents.js CHANGED
@@ -1,16 +1,13 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.parseSourceFileDocument = exports.parseSourceFileDocuments = exports.TeleportSourceMap = exports.EmbeddedDocumentSourceMap = exports.SourceMap = void 0;
2
+ exports.createDocumentsAndSourceMaps = exports.MirrorMapWithDocument = exports.SourceMapWithDocuments = void 0;
3
3
  const language_core_1 = require("@volar/language-core");
4
4
  const shared = require("@volar/shared");
5
- const source_map_1 = require("@volar/source-map");
6
- const reactivity_1 = require("@vue/reactivity");
7
5
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
8
- class SourceMap extends source_map_1.SourceMapBase {
9
- constructor(sourceDocument, mappedDocument, mappings) {
10
- super(mappings);
11
- this.sourceDocument = sourceDocument;
12
- this.mappedDocument = mappedDocument;
13
- this.mappings = mappings;
6
+ class SourceMapWithDocuments {
7
+ constructor(sourceFileDocument, virtualFileDocument, map) {
8
+ this.sourceFileDocument = sourceFileDocument;
9
+ this.virtualFileDocument = virtualFileDocument;
10
+ this.map = map;
14
11
  }
15
12
  // Range APIs
16
13
  toSourceRange(range, filter = () => true) {
@@ -72,13 +69,13 @@ class SourceMap extends source_map_1.SourceMapBase {
72
69
  }
73
70
  }
74
71
  toSourcePositionsBase(position, filter = () => true, baseOffset = 'left') {
75
- return this.toPositions(position, filter, this.mappedDocument, this.sourceDocument, 'generatedRange', 'sourceRange', baseOffset);
72
+ return this.toPositions(position, filter, this.virtualFileDocument, this.sourceFileDocument, 'generatedRange', 'sourceRange', baseOffset);
76
73
  }
77
74
  toGeneratedPositionsBase(position, filter = () => true, baseOffset = 'left') {
78
- return this.toPositions(position, filter, this.sourceDocument, this.mappedDocument, 'sourceRange', 'generatedRange', baseOffset);
75
+ return this.toPositions(position, filter, this.sourceFileDocument, this.virtualFileDocument, 'sourceRange', 'generatedRange', baseOffset);
79
76
  }
80
77
  *toPositions(position, filter, fromDoc, toDoc, from, to, baseOffset) {
81
- for (const mapped of this.matcing(fromDoc.offsetAt(position), from, to, baseOffset === 'right')) {
78
+ for (const mapped of this.map.matching(fromDoc.offsetAt(position), from, to, baseOffset === 'right')) {
82
79
  if (!filter(mapped[1].data)) {
83
80
  continue;
84
81
  }
@@ -91,163 +88,124 @@ class SourceMap extends source_map_1.SourceMapBase {
91
88
  }
92
89
  }
93
90
  matchSourcePosition(position, mapping, baseOffset) {
94
- let offset = this.matchOffset(this.mappedDocument.offsetAt(position), mapping['generatedRange'], mapping['sourceRange'], baseOffset === 'right');
91
+ let offset = this.map.matchOffset(this.virtualFileDocument.offsetAt(position), mapping['generatedRange'], mapping['sourceRange'], baseOffset === 'right');
95
92
  if (offset !== undefined) {
96
- return this.sourceDocument.positionAt(offset);
93
+ return this.sourceFileDocument.positionAt(offset);
97
94
  }
98
95
  }
99
96
  matchGeneratedPosition(position, mapping, baseOffset) {
100
- let offset = this.matchOffset(this.sourceDocument.offsetAt(position), mapping['sourceRange'], mapping['generatedRange'], baseOffset === 'right');
97
+ let offset = this.map.matchOffset(this.sourceFileDocument.offsetAt(position), mapping['sourceRange'], mapping['generatedRange'], baseOffset === 'right');
101
98
  if (offset !== undefined) {
102
- return this.mappedDocument.positionAt(offset);
99
+ return this.virtualFileDocument.positionAt(offset);
103
100
  }
104
101
  }
105
102
  }
106
- exports.SourceMap = SourceMap;
107
- class EmbeddedDocumentSourceMap extends SourceMap {
108
- constructor(embeddedFile, sourceDocument, mappedDocument, mappings) {
109
- super(sourceDocument, mappedDocument, mappings);
110
- this.embeddedFile = embeddedFile;
111
- this.sourceDocument = sourceDocument;
112
- this.mappedDocument = mappedDocument;
113
- }
114
- }
115
- exports.EmbeddedDocumentSourceMap = EmbeddedDocumentSourceMap;
116
- class TeleportSourceMap extends SourceMap {
117
- constructor(embeddedFile, document, mappings) {
118
- super(document, document, mappings);
119
- this.embeddedFile = embeddedFile;
103
+ exports.SourceMapWithDocuments = SourceMapWithDocuments;
104
+ class MirrorMapWithDocument extends SourceMapWithDocuments {
105
+ constructor(document, map) {
106
+ super(document, document, map);
120
107
  this.document = document;
121
108
  }
122
- *findTeleports(start) {
109
+ *findMirrorPositions(start) {
123
110
  for (const mapped of this.toGeneratedPositionsBase(start)) {
124
- yield [mapped[0], mapped[1].data.toGenedCapabilities];
111
+ yield [mapped[0], mapped[1].data[1]];
125
112
  }
126
113
  for (const mapped of this.toSourcePositionsBase(start)) {
127
- yield [mapped[0], mapped[1].data.toSourceCapabilities];
114
+ yield [mapped[0], mapped[1].data[0]];
128
115
  }
129
116
  }
130
117
  }
131
- exports.TeleportSourceMap = TeleportSourceMap;
132
- function parseSourceFileDocuments(mapper) {
133
- const _sourceFiles = new WeakMap();
134
- // reactivity
135
- const embeddedDocumentsMap = (0, reactivity_1.computed)(() => {
136
- const map = new Map();
137
- for (const vueDocument of getAll()) {
138
- for (const sourceMap of vueDocument.getSourceMaps()) {
139
- map.set(sourceMap.mappedDocument, vueDocument);
140
- }
141
- }
142
- return map;
143
- });
144
- const embeddedDocumentMaps = (0, reactivity_1.computed)(() => {
145
- const map = new Map();
146
- for (const vueDocument of getAll()) {
147
- for (const sourceMap of vueDocument.getSourceMaps()) {
148
- map.set(sourceMap.mappedDocument.uri, sourceMap);
118
+ exports.MirrorMapWithDocument = MirrorMapWithDocument;
119
+ function createDocumentsAndSourceMaps(mapper) {
120
+ let version = 0;
121
+ const _maps = new WeakMap();
122
+ const _mirrorMaps = new WeakMap();
123
+ const _documents = new WeakMap();
124
+ return {
125
+ getRootFileBySourceFileUri(sourceFileUri) {
126
+ const fileName = shared.getPathOfUri(sourceFileUri);
127
+ const rootFile = mapper.get(fileName);
128
+ if (rootFile) {
129
+ return rootFile[1];
149
130
  }
150
- }
151
- return map;
152
- });
153
- const teleports = (0, reactivity_1.computed)(() => {
154
- const map = new Map();
155
- for (const vueDocument of getAll()) {
156
- for (const teleport of vueDocument.getTeleports()) {
157
- map.set(teleport.mappedDocument.uri, teleport);
131
+ },
132
+ getVirtualFileByUri(virtualFileUri) {
133
+ var _a;
134
+ return (_a = mapper.getSourceByVirtualFileName(shared.getPathOfUri(virtualFileUri))) === null || _a === void 0 ? void 0 : _a[2];
135
+ },
136
+ getMirrorMapByUri(virtualFileUri) {
137
+ var _a;
138
+ const fileName = shared.getPathOfUri(virtualFileUri);
139
+ const virtualFile = (_a = mapper.getSourceByVirtualFileName(fileName)) === null || _a === void 0 ? void 0 : _a[2];
140
+ if (virtualFile) {
141
+ const map = mapper.getMirrorMap(virtualFile);
142
+ if (map) {
143
+ if (!_mirrorMaps.has(map)) {
144
+ _mirrorMaps.set(map, [virtualFile, new MirrorMapWithDocument(getDocumentByFileName(virtualFile.snapshot, fileName), map)]);
145
+ }
146
+ return _mirrorMaps.get(map);
147
+ }
158
148
  }
159
- }
160
- return map;
161
- });
162
- return {
163
- getAll: getAll,
164
- get: (uri) => {
165
- const fileName = shared.getPathOfUri(uri);
166
- const vueFile = mapper.get(fileName);
167
- if (vueFile) {
168
- return get(vueFile[0]);
149
+ },
150
+ getMapsBySourceFileUri(uri) {
151
+ return this.getMapsBySourceFileName(shared.getPathOfUri(uri));
152
+ },
153
+ getMapsBySourceFileName(fileName) {
154
+ const source = mapper.get(fileName);
155
+ if (source) {
156
+ const result = [];
157
+ (0, language_core_1.forEachEmbeddedFile)(source[1], (embedded) => {
158
+ for (const [sourceFileName, map] of mapper.getMaps(embedded)) {
159
+ if (sourceFileName === fileName) {
160
+ if (!_maps.has(map)) {
161
+ _maps.set(map, [
162
+ embedded,
163
+ new SourceMapWithDocuments(getDocumentByFileName(source[0], sourceFileName), getDocumentByFileName(embedded.snapshot, fileName), map)
164
+ ]);
165
+ }
166
+ if (_maps.has(map)) {
167
+ result.push(_maps.get(map));
168
+ }
169
+ }
170
+ }
171
+ });
172
+ return {
173
+ snapshot: source[0],
174
+ maps: result,
175
+ };
169
176
  }
170
177
  },
171
- fromEmbeddedDocument: (document) => {
172
- return embeddedDocumentsMap.value.get(document);
178
+ getMapsByVirtualFileUri(virtualFileUri) {
179
+ return this.getMapsByVirtualFileName(shared.getPathOfUri(virtualFileUri));
173
180
  },
174
- sourceMapFromEmbeddedDocumentUri: (uri) => {
175
- return embeddedDocumentMaps.value.get(uri);
181
+ *getMapsByVirtualFileName(virtualFileName) {
182
+ var _a, _b;
183
+ const virtualFile = (_a = mapper.getSourceByVirtualFileName(virtualFileName)) === null || _a === void 0 ? void 0 : _a[2];
184
+ if (virtualFile) {
185
+ for (const [sourceFileName, map] of mapper.getMaps(virtualFile)) {
186
+ if (!_maps.has(map)) {
187
+ const sourceSnapshot = (_b = mapper.get(sourceFileName)) === null || _b === void 0 ? void 0 : _b[0];
188
+ if (sourceSnapshot) {
189
+ _maps.set(map, [virtualFile, new SourceMapWithDocuments(getDocumentByFileName(sourceSnapshot, sourceFileName), getDocumentByFileName(virtualFile.snapshot, virtualFileName), map)]);
190
+ }
191
+ }
192
+ if (_maps.has(map)) {
193
+ yield _maps.get(map);
194
+ }
195
+ }
196
+ }
176
197
  },
177
- teleportfromEmbeddedDocumentUri: (uri) => {
178
- return teleports.value.get(uri);
198
+ getDocumentByUri(snapshot, uri) {
199
+ return this.getDocumentByFileName(snapshot, shared.getPathOfUri(uri));
179
200
  },
201
+ getDocumentByFileName,
180
202
  };
181
- function get(sourceFile) {
182
- let vueDocument = _sourceFiles.get(sourceFile);
183
- if (!vueDocument) {
184
- vueDocument = parseSourceFileDocument(sourceFile);
185
- _sourceFiles.set(sourceFile, vueDocument);
203
+ function getDocumentByFileName(snapshot, fileName) {
204
+ if (!_documents.has(snapshot)) {
205
+ _documents.set(snapshot, vscode_languageserver_textdocument_1.TextDocument.create(shared.getUriByPath(fileName), shared.syntaxToLanguageId(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength())));
186
206
  }
187
- return vueDocument;
188
- }
189
- function getAll() {
190
- return mapper.getAll().map(file => get(file[0]));
191
- }
192
- }
193
- exports.parseSourceFileDocuments = parseSourceFileDocuments;
194
- function parseSourceFileDocument(sourceFile) {
195
- let documentVersion = 0;
196
- const embeddedDocumentVersions = new Map();
197
- const embeddedDocuments = new WeakMap();
198
- const sourceMaps = new WeakMap();
199
- // computed
200
- const document = (0, reactivity_1.computed)(() => vscode_languageserver_textdocument_1.TextDocument.create(shared.getUriByPath(sourceFile.fileName), shared.syntaxToLanguageId(sourceFile.fileName.slice(sourceFile.fileName.lastIndexOf('.') + 1)), documentVersion++, sourceFile.text));
201
- const allSourceMaps = (0, reactivity_1.computed)(() => {
202
- const result = [];
203
- (0, language_core_1.forEachEmbeddeds)(sourceFile, embedded => {
204
- result.push(getSourceMap(embedded));
205
- });
206
- return result;
207
- });
208
- const teleports = (0, reactivity_1.computed)(() => {
209
- const result = [];
210
- (0, language_core_1.forEachEmbeddeds)(sourceFile, embedded => {
211
- if (embedded.teleportMappings) {
212
- const embeddedDocument = getEmbeddedDocument(embedded);
213
- const sourceMap = new TeleportSourceMap(embedded, embeddedDocument, embedded.teleportMappings);
214
- result.push(sourceMap);
215
- }
216
- });
217
- return result;
218
- });
219
- return {
220
- uri: shared.getUriByPath(sourceFile.fileName),
221
- file: sourceFile,
222
- getSourceMap,
223
- getEmbeddedDocument,
224
- getSourceMaps: () => allSourceMaps.value,
225
- getTeleports: () => teleports.value,
226
- getDocument: () => document.value,
227
- };
228
- function getSourceMap(embedded) {
229
- let cache = sourceMaps.get(embedded);
230
- if (!cache || cache[0] !== document.value.version) {
231
- cache = [
232
- document.value.version,
233
- new EmbeddedDocumentSourceMap(embedded, document.value, getEmbeddedDocument(embedded), embedded.mappings)
234
- ];
235
- sourceMaps.set(embedded, cache);
236
- }
237
- return cache[1];
238
- }
239
- function getEmbeddedDocument(embeddedFile) {
240
- var _a;
241
- let document = embeddedDocuments.get(embeddedFile);
242
- if (!document || document.getText() !== embeddedFile.text) {
243
- const uri = shared.getUriByPath(embeddedFile.fileName);
244
- const newVersion = ((_a = embeddedDocumentVersions.get(uri.toLowerCase())) !== null && _a !== void 0 ? _a : 0) + 1;
245
- embeddedDocumentVersions.set(uri.toLowerCase(), newVersion);
246
- document = vscode_languageserver_textdocument_1.TextDocument.create(uri, shared.syntaxToLanguageId(embeddedFile.fileName.split('.').pop()), newVersion, embeddedFile.text);
247
- embeddedDocuments.set(embeddedFile, document);
248
- }
249
- return document;
207
+ return _documents.get(snapshot);
250
208
  }
251
209
  }
252
- exports.parseSourceFileDocument = parseSourceFileDocument;
210
+ exports.createDocumentsAndSourceMaps = createDocumentsAndSourceMaps;
253
211
  //# sourceMappingURL=documents.js.map
@@ -3,11 +3,11 @@ exports.register = void 0;
3
3
  const featureWorkers_1 = require("../utils/featureWorkers");
4
4
  function register(context) {
5
5
  return (uri, position, autoInsertContext) => {
6
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, autoInsertContext }, function* (arg, sourceMap) {
6
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, autoInsertContext }, function* (arg, map) {
7
7
  var _a;
8
- for (const position of sourceMap.toGeneratedPositions(arg.position, data => !!data.completion)) {
9
- const rangeOffset = (_a = sourceMap.toGeneratedOffset(arg.autoInsertContext.lastChange.rangeOffset)) === null || _a === void 0 ? void 0 : _a[0];
10
- const range = sourceMap.toGeneratedRange(arg.autoInsertContext.lastChange.range);
8
+ for (const position of map.toGeneratedPositions(arg.position, data => !!data.completion)) {
9
+ const rangeOffset = (_a = map.map.toGeneratedOffset(arg.autoInsertContext.lastChange.rangeOffset)) === null || _a === void 0 ? void 0 : _a[0];
10
+ const range = map.toGeneratedRange(arg.autoInsertContext.lastChange.range);
11
11
  if (rangeOffset !== undefined && range) {
12
12
  yield {
13
13
  position,
@@ -19,10 +19,10 @@ function register(context) {
19
19
  break;
20
20
  }
21
21
  }
22
- }, (plugin, document, arg) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext); }, (item, sourceMap) => {
23
- if (!sourceMap || typeof item === 'string')
22
+ }, (plugin, document, arg) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext); }, (item, map) => {
23
+ if (!map || typeof item === 'string')
24
24
  return item;
25
- const range = sourceMap.toSourceRange(item.range);
25
+ const range = map.toSourceRange(item.range);
26
26
  if (range) {
27
27
  item.range = range;
28
28
  return item;
@@ -4,7 +4,7 @@ export interface PluginCallHierarchyData {
4
4
  uri: string;
5
5
  originalItem: vscode.CallHierarchyItem;
6
6
  pluginId: number;
7
- sourceMap: {
7
+ map: {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
10
10
  }
@@ -16,7 +16,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
16
16
  function register(context) {
17
17
  return {
18
18
  doPrepare(uri, position) {
19
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, sourceMap) => __awaiter(this, void 0, void 0, function* () {
19
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, map) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _a;
21
21
  const items = yield ((_a = plugin.callHierarchy) === null || _a === void 0 ? void 0 : _a.prepare(document, position));
22
22
  return items === null || items === void 0 ? void 0 : items.map(item => {
@@ -24,8 +24,8 @@ function register(context) {
24
24
  uri,
25
25
  originalItem: item,
26
26
  pluginId: context.plugins.indexOf(plugin),
27
- sourceMap: sourceMap ? {
28
- embeddedDocumentUri: sourceMap.mappedDocument.uri,
27
+ map: map ? {
28
+ embeddedDocumentUri: map.virtualFileDocument.uri,
29
29
  } : undefined,
30
30
  } });
31
31
  });
@@ -44,9 +44,8 @@ function register(context) {
44
44
  if (!plugin.callHierarchy)
45
45
  return incomingItems;
46
46
  const originalItem = data.originalItem;
47
- if (data.sourceMap) {
48
- const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(data.sourceMap.embeddedDocumentUri);
49
- if (sourceMap) {
47
+ if (data.map) {
48
+ if (context.documents.getVirtualFileByUri(data.map.embeddedDocumentUri)) {
50
49
  const _calls = yield plugin.callHierarchy.onIncomingCalls(originalItem);
51
50
  for (const _call of _calls) {
52
51
  const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
@@ -86,9 +85,8 @@ function register(context) {
86
85
  if (!plugin.callHierarchy)
87
86
  return items;
88
87
  const originalItem = data.originalItem;
89
- if (data.sourceMap) {
90
- const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(data.sourceMap.embeddedDocumentUri);
91
- if (sourceMap) {
88
+ if (data.map) {
89
+ if (context.documents.getVirtualFileByUri(data.map.embeddedDocumentUri)) {
92
90
  const _calls = yield plugin.callHierarchy.onOutgoingCalls(originalItem);
93
91
  for (const call of _calls) {
94
92
  const calls = transformCallHierarchyItem(call.to, call.fromRanges);
@@ -119,32 +117,33 @@ function register(context) {
119
117
  },
120
118
  };
121
119
  function transformCallHierarchyItem(tsItem, tsRanges) {
122
- const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(tsItem.uri);
123
- if (!sourceMap)
124
- return [tsItem, tsRanges]; // not virtual file
125
- let range = sourceMap.toSourceRange(tsItem.range);
126
- if (!range) {
127
- // TODO: <script> range
128
- range = {
129
- start: sourceMap.sourceDocument.positionAt(0),
130
- end: sourceMap.sourceDocument.positionAt(sourceMap.sourceDocument.getText().length),
131
- };
120
+ if (!context.documents.getVirtualFileByUri(tsItem.uri))
121
+ return [tsItem, tsRanges];
122
+ for (const [_, map] of context.documents.getMapsByVirtualFileUri(tsItem.uri)) {
123
+ let range = map.toSourceRange(tsItem.range);
124
+ if (!range) {
125
+ // TODO: <script> range
126
+ range = {
127
+ start: map.sourceFileDocument.positionAt(0),
128
+ end: map.sourceFileDocument.positionAt(map.sourceFileDocument.getText().length),
129
+ };
130
+ }
131
+ const selectionRange = map.toSourceRange(tsItem.selectionRange);
132
+ if (!selectionRange)
133
+ continue;
134
+ const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(shared.notEmpty);
135
+ const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(shared.getPathOfUri(map.virtualFileDocument.uri)) ? path_1.posix.basename(shared.getPathOfUri(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri,
136
+ // TS Bug: `range: range` not works
137
+ range: {
138
+ start: range.start,
139
+ end: range.end,
140
+ }, selectionRange: {
141
+ start: selectionRange.start,
142
+ end: selectionRange.end,
143
+ } });
144
+ selectionRange.end;
145
+ return [vueItem, vueRanges];
132
146
  }
133
- const selectionRange = sourceMap.toSourceRange(tsItem.selectionRange);
134
- if (!selectionRange)
135
- return;
136
- const vueRanges = tsRanges.map(tsRange => sourceMap.toSourceRange(tsRange)).filter(shared.notEmpty);
137
- const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(shared.getPathOfUri(sourceMap.mappedDocument.uri)) ? path_1.posix.basename(shared.getPathOfUri(sourceMap.sourceDocument.uri)) : tsItem.name, uri: sourceMap.sourceDocument.uri,
138
- // TS Bug: `range: range` not works
139
- range: {
140
- start: range.start,
141
- end: range.end,
142
- }, selectionRange: {
143
- start: selectionRange.start,
144
- end: selectionRange.end,
145
- } });
146
- selectionRange.end;
147
- return [vueItem, vueRanges];
148
147
  }
149
148
  }
150
149
  exports.register = register;
@@ -21,9 +21,8 @@ function register(context) {
21
21
  if (!((_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.resolve))
22
22
  return item;
23
23
  const originalItem = data.originalItem;
24
- if (data.sourceMap) {
25
- const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(data.sourceMap.embeddedDocumentUri);
26
- if (sourceMap) {
24
+ if (data.map) {
25
+ if (context.documents.getVirtualFileByUri(data.map.embeddedDocumentUri)) {
27
26
  const resolvedItem = yield ((_b = plugin.codeAction) === null || _b === void 0 ? void 0 : _b.resolve(originalItem));
28
27
  if (resolvedItem.edit) {
29
28
  const edit = (0, rename_1.embeddedEditToSourceEdit)(resolvedItem.edit, context.documents);
@@ -4,7 +4,7 @@ export interface PluginCodeActionData {
4
4
  uri: string;
5
5
  originalItem: vscode.CodeAction;
6
6
  pluginId: number;
7
- sourceMap: {
7
+ map: {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
10
10
  }
@@ -25,21 +25,21 @@ function register(context) {
25
25
  start: document.offsetAt(range.start),
26
26
  end: document.offsetAt(range.end),
27
27
  };
28
- let codeActions = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (_arg, sourceMap) => {
28
+ let codeActions = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (_arg, map, file) => {
29
29
  var _a, _b;
30
- if (!sourceMap.embeddedFile.capabilities.codeAction)
30
+ if (!file.capabilities.codeAction)
31
31
  return [];
32
32
  const _codeActionContext = {
33
- diagnostics: (0, transforms_1.transformLocations)(codeActionContext.diagnostics, range => sourceMap.toGeneratedRange(range)),
33
+ diagnostics: (0, transforms_1.transformLocations)(codeActionContext.diagnostics, range => map.toGeneratedRange(range)),
34
34
  only: codeActionContext.only,
35
35
  };
36
36
  let minStart;
37
37
  let maxEnd;
38
- for (const mapping of sourceMap.mappings) {
38
+ for (const mapping of map.map.mappings) {
39
39
  const overlapRange = (0, common_1.getOverlapRange)(offsetRange.start, offsetRange.end, mapping.sourceRange[0], mapping.sourceRange[1]);
40
40
  if (overlapRange) {
41
- const start = (_a = sourceMap.toGeneratedOffset(overlapRange.start)) === null || _a === void 0 ? void 0 : _a[0];
42
- const end = (_b = sourceMap.toGeneratedOffset(overlapRange.end)) === null || _b === void 0 ? void 0 : _b[0];
41
+ const start = (_a = map.map.toGeneratedOffset(overlapRange.start)) === null || _a === void 0 ? void 0 : _a[0];
42
+ const end = (_b = map.map.toGeneratedOffset(overlapRange.end)) === null || _b === void 0 ? void 0 : _b[0];
43
43
  if (start !== undefined && end !== undefined) {
44
44
  minStart = minStart === undefined ? start : Math.min(start, minStart);
45
45
  maxEnd = maxEnd === undefined ? end : Math.max(end, maxEnd);
@@ -48,12 +48,12 @@ function register(context) {
48
48
  }
49
49
  if (minStart !== undefined && maxEnd !== undefined) {
50
50
  return [{
51
- range: vscode.Range.create(sourceMap.mappedDocument.positionAt(minStart), sourceMap.mappedDocument.positionAt(maxEnd)),
51
+ range: vscode.Range.create(map.virtualFileDocument.positionAt(minStart), map.virtualFileDocument.positionAt(maxEnd)),
52
52
  codeActionContext: _codeActionContext,
53
53
  }];
54
54
  }
55
55
  return [];
56
- }, (plugin, document, arg, sourceMap) => __awaiter(this, void 0, void 0, function* () {
56
+ }, (plugin, document, arg, map) => __awaiter(this, void 0, void 0, function* () {
57
57
  var _a, _b;
58
58
  const codeActions = yield ((_b = (_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, arg.range, arg.codeActionContext));
59
59
  return codeActions === null || codeActions === void 0 ? void 0 : codeActions.map(_codeAction => {
@@ -61,8 +61,8 @@ function register(context) {
61
61
  uri,
62
62
  originalItem: _codeAction,
63
63
  pluginId: context.plugins.indexOf(plugin),
64
- sourceMap: sourceMap ? {
65
- embeddedDocumentUri: sourceMap.mappedDocument.uri,
64
+ map: map ? {
65
+ embeddedDocumentUri: map.virtualFileDocument.uri,
66
66
  } : undefined,
67
67
  } });
68
68
  });
@@ -28,10 +28,10 @@ function register(context) {
28
28
  } });
29
29
  });
30
30
  }
31
- }), (data, sourceMap) => data.map(codeLens => {
32
- if (!sourceMap)
31
+ }), (data, map) => data.map(codeLens => {
32
+ if (!map)
33
33
  return codeLens;
34
- const range = sourceMap.toSourceRange(codeLens.range);
34
+ const range = map.toSourceRange(codeLens.range);
35
35
  if (range) {
36
36
  return Object.assign(Object.assign({}, codeLens), { range });
37
37
  }
@@ -4,7 +4,7 @@ export interface PluginCompletionData {
4
4
  uri: string;
5
5
  originalItem: vscode.CompletionItem;
6
6
  pluginId: number;
7
- sourceMap: {
7
+ map: {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
10
10
  }