@volar/language-service 2.3.0-alpha.4 → 2.3.0-alpha.5

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.
@@ -125,19 +125,17 @@ function register(context) {
125
125
  if (!virtualCode) {
126
126
  return [tsItem, tsRanges];
127
127
  }
128
- for (const map of context.documents.getMaps(virtualCode)) {
129
- let range = map.getSourceRange(tsItem.range);
130
- if (!range) {
131
- // TODO: <script> range
132
- range = {
133
- start: map.sourceDocument.positionAt(0),
134
- end: map.sourceDocument.positionAt(map.sourceDocument.getText().length),
135
- };
136
- }
137
- const selectionRange = map.getSourceRange(tsItem.selectionRange);
138
- if (!selectionRange) {
139
- continue;
140
- }
128
+ const map = context.documents.getSourceMap(virtualCode);
129
+ let range = map.getSourceRange(tsItem.range);
130
+ if (!range) {
131
+ // TODO: <script> range
132
+ range = {
133
+ start: map.sourceDocument.positionAt(0),
134
+ end: map.sourceDocument.positionAt(map.sourceDocument.getText().length),
135
+ };
136
+ }
137
+ const selectionRange = map.getSourceRange(tsItem.selectionRange);
138
+ if (selectionRange) {
141
139
  const vueRanges = tsRanges.map(tsRange => map.getSourceRange(tsRange)).filter(common_1.notEmpty);
142
140
  const vueItem = {
143
141
  ...tsItem,
@@ -30,29 +30,28 @@ function register(context) {
30
30
  if (!virtualCode) {
31
31
  continue;
32
32
  }
33
- for (const map of context.documents.getMaps(virtualCode)) {
34
- for (const mapped of map.getGeneratedPositions(position, data => (0, language_core_1.isCompletionEnabled)(data))) {
35
- if (!cacheData.plugin.provideCompletionItems) {
36
- continue;
37
- }
38
- cacheData.list = await cacheData.plugin.provideCompletionItems(map.embeddedDocument, mapped, completionContext, token);
39
- if (!cacheData.list) {
40
- continue;
41
- }
42
- for (const item of cacheData.list.items) {
43
- item.data = {
44
- uri: uri.toString(),
45
- original: {
46
- additionalTextEdits: item.additionalTextEdits,
47
- textEdit: item.textEdit,
48
- data: item.data,
49
- },
50
- pluginIndex: pluginIndex,
51
- embeddedDocumentUri: map.embeddedDocument.uri,
52
- };
53
- }
54
- cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => map.getSourceRange(range), map.embeddedDocument, context);
33
+ const map = context.documents.getSourceMap(virtualCode);
34
+ for (const mapped of map.getGeneratedPositions(position, data => (0, language_core_1.isCompletionEnabled)(data))) {
35
+ if (!cacheData.plugin.provideCompletionItems) {
36
+ continue;
55
37
  }
38
+ cacheData.list = await cacheData.plugin.provideCompletionItems(map.embeddedDocument, mapped, completionContext, token);
39
+ if (!cacheData.list) {
40
+ continue;
41
+ }
42
+ for (const item of cacheData.list.items) {
43
+ item.data = {
44
+ uri: uri.toString(),
45
+ original: {
46
+ additionalTextEdits: item.additionalTextEdits,
47
+ textEdit: item.textEdit,
48
+ data: item.data,
49
+ },
50
+ pluginIndex: pluginIndex,
51
+ embeddedDocumentUri: map.embeddedDocument.uri,
52
+ };
53
+ }
54
+ cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => map.getSourceRange(range), map.embeddedDocument, context);
56
55
  }
57
56
  }
58
57
  else {
@@ -65,41 +65,39 @@ function register(context, apiName, isValidPosition) {
65
65
  }
66
66
  link.originSelectionRange = originSelectionRange;
67
67
  }
68
- let foundTargetSelectionRange = false;
69
68
  const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(link.targetUri));
70
69
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
71
70
  const targetVirtualFile = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
72
71
  if (targetVirtualFile) {
73
- for (const targetSourceMap of context.documents.getMaps(targetVirtualFile)) {
74
- const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
75
- if (!targetSelectionRange) {
76
- continue;
77
- }
78
- foundTargetSelectionRange = true;
72
+ const targetSourceMap = context.documents.getSourceMap(targetVirtualFile);
73
+ const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
74
+ if (targetSelectionRange) {
79
75
  let targetRange = targetSourceMap.getSourceRange(link.targetRange);
80
76
  link.targetUri = targetSourceMap.sourceDocument.uri;
81
77
  // loose range mapping to for template slots, slot properties
82
78
  link.targetRange = targetRange ?? targetSelectionRange;
83
79
  link.targetSelectionRange = targetSelectionRange;
84
80
  }
85
- if (apiName === 'provideDefinition' && !foundTargetSelectionRange) {
86
- for (const targetMap of context.documents.getMaps(targetVirtualFile)) {
87
- if (targetMap && targetMap.sourceDocument.uri !== uri.toString()) {
88
- return {
89
- ...link,
90
- targetUri: targetMap.sourceDocument.uri,
91
- targetRange: {
92
- start: { line: 0, character: 0 },
93
- end: { line: 0, character: 0 },
94
- },
95
- targetSelectionRange: {
96
- start: { line: 0, character: 0 },
97
- end: { line: 0, character: 0 },
98
- },
99
- };
100
- }
81
+ else if (apiName === 'provideDefinition') {
82
+ const targetMap = context.documents.getSourceMap(targetVirtualFile);
83
+ // cross file definition
84
+ if (targetMap.sourceDocument.uri !== uri.toString()) {
85
+ return {
86
+ ...link,
87
+ targetUri: targetMap.sourceDocument.uri,
88
+ targetRange: {
89
+ start: { line: 0, character: 0 },
90
+ end: { line: 0, character: 0 },
91
+ },
92
+ targetSelectionRange: {
93
+ start: { line: 0, character: 0 },
94
+ end: { line: 0, character: 0 },
95
+ },
96
+ };
97
+ }
98
+ else {
99
+ return;
101
100
  }
102
- return;
103
101
  }
104
102
  }
105
103
  return link;
@@ -204,17 +204,16 @@ function register(context) {
204
204
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
205
205
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
206
206
  if (virtualCode) {
207
- for (const map of context.documents.getMaps(virtualCode)) {
208
- const range = map.getSourceRange(info.location.range, filter);
209
- if (range) {
210
- relatedInfos.push({
211
- location: {
212
- uri: map.sourceDocument.uri,
213
- range,
214
- },
215
- message: info.message,
216
- });
217
- }
207
+ const map = context.documents.getSourceMap(virtualCode);
208
+ const range = map.getSourceRange(info.location.range, filter);
209
+ if (range) {
210
+ relatedInfos.push({
211
+ location: {
212
+ uri: map.sourceDocument.uri,
213
+ range,
214
+ },
215
+ message: info.message,
216
+ });
218
217
  }
219
218
  }
220
219
  else {
@@ -8,7 +8,6 @@ const documents_1 = require("../documents");
8
8
  const cancellation_1 = require("../utils/cancellation");
9
9
  const common_1 = require("../utils/common");
10
10
  const featureWorkers_1 = require("../utils/featureWorkers");
11
- const uriMap_1 = require("../utils/uriMap");
12
11
  function register(context) {
13
12
  let fakeVersion = 0;
14
13
  return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
@@ -179,17 +178,9 @@ function register(context) {
179
178
  }
180
179
  };
181
180
  function createDocMap(virtualCode, documentUri, sourceLanguageId, _sourceSnapshot) {
182
- const mapOfMap = (0, uriMap_1.createUriMap)();
183
- (0, language_core_1.updateVirtualCodeMapOfMap)(virtualCode, mapOfMap, sourceFileUri2 => {
184
- if (!sourceFileUri2) {
185
- return [documentUri, _sourceSnapshot];
186
- }
187
- });
188
- if (mapOfMap.has(documentUri) && mapOfMap.get(documentUri)[0] === _sourceSnapshot) {
189
- const map = mapOfMap.get(documentUri);
190
- const version = fakeVersion++;
191
- return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(documentUri.toString(), sourceLanguageId, version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(context.encodeEmbeddedDocumentUri(documentUri, virtualCode.id).toString(), virtualCode.languageId, version, virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength())), map[1], virtualCode);
192
- }
181
+ const map = new language_core_1.SourceMap(virtualCode.mappings);
182
+ const version = fakeVersion++;
183
+ return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(documentUri.toString(), sourceLanguageId, version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(context.encodeEmbeddedDocumentUri(documentUri, virtualCode.id).toString(), virtualCode.languageId, version, virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength())), map, virtualCode);
193
184
  }
194
185
  }
195
186
  exports.register = register;
@@ -7,7 +7,8 @@ const cancellation_1 = require("../utils/cancellation");
7
7
  const common_1 = require("../utils/common");
8
8
  const featureWorkers_1 = require("../utils/featureWorkers");
9
9
  function register(context) {
10
- return async (uri, range, legend, token = cancellation_1.NoneCancellationToken, _reportProgress) => {
10
+ return async (uri, range, legend, token = cancellation_1.NoneCancellationToken, _reportProgress // TODO
11
+ ) => {
11
12
  const sourceScript = context.language.scripts.get(uri);
12
13
  if (!sourceScript) {
13
14
  return;
@@ -47,7 +48,9 @@ function register(context) {
47
48
  }
48
49
  })
49
50
  .filter(common_1.notEmpty);
50
- }, tokens => tokens.flat());
51
+ }, tokens => tokens.flat()
52
+ // tokens => reportProgress?.(buildTokens(tokens)), // TODO: this has no effect with LSP
53
+ );
51
54
  if (tokens) {
52
55
  return buildTokens(tokens);
53
56
  }
@@ -22,13 +22,12 @@ function register(context) {
22
22
  if (!virtualCode) {
23
23
  return reference;
24
24
  }
25
- for (const map of context.documents.getMaps(virtualCode)) {
26
- const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
27
- if (range) {
28
- reference.uri = map.sourceDocument.uri;
29
- reference.range = range;
30
- return reference;
31
- }
25
+ const map = context.documents.getSourceMap(virtualCode);
26
+ const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
27
+ if (range) {
28
+ reference.uri = map.sourceDocument.uri;
29
+ reference.range = range;
30
+ return reference;
32
31
  }
33
32
  })
34
33
  .filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat()));
@@ -55,14 +55,13 @@ function register(context) {
55
55
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
56
56
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
57
57
  if (virtualCode) {
58
- for (const map of context.documents.getMaps(virtualCode)) {
59
- const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
60
- if (range) {
61
- results.push({
62
- uri: map.sourceDocument.uri,
63
- range,
64
- });
65
- }
58
+ const map = context.documents.getSourceMap(virtualCode);
59
+ const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
60
+ if (range) {
61
+ results.push({
62
+ uri: map.sourceDocument.uri,
63
+ range,
64
+ });
66
65
  }
67
66
  }
68
67
  else {
@@ -27,11 +27,10 @@ function register(context) {
27
27
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
28
28
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
29
29
  if (virtualCode) {
30
- for (const map of context.documents.getMaps(virtualCode)) {
31
- const range = map.getSourceRange(loc.range);
32
- if (range) {
33
- return { uri: map.sourceDocument.uri, range };
34
- }
30
+ const map = context.documents.getSourceMap(virtualCode);
31
+ const range = map.getSourceRange(loc.range);
32
+ if (range) {
33
+ return { uri: map.sourceDocument.uri, range };
35
34
  }
36
35
  }
37
36
  else {
@@ -18,10 +18,9 @@ function register(context) {
18
18
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
19
19
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
20
20
  if (virtualCode) {
21
- for (const map of context.documents.getMaps(virtualCode)) {
22
- item = await plugin[1].resolveCompletionItem(item, token);
23
- item = plugin[1].transformCompletionItem?.(item) ?? (0, transform_1.transformCompletionItem)(item, embeddedRange => map.getSourceRange(embeddedRange), map.embeddedDocument, context);
24
- }
21
+ const map = context.documents.getSourceMap(virtualCode);
22
+ item = await plugin[1].resolveCompletionItem(item, token);
23
+ item = plugin[1].transformCompletionItem?.(item) ?? (0, transform_1.transformCompletionItem)(item, embeddedRange => map.getSourceRange(embeddedRange), map.embeddedDocument, context);
25
24
  }
26
25
  }
27
26
  else {
@@ -59,14 +59,15 @@ function createLanguageService(language, plugins, env) {
59
59
  }
60
60
  return map.get(uri);
61
61
  },
62
- *getMaps(virtualCode) {
63
- for (const [uri, [snapshot, map]] of context.language.maps.forEach(virtualCode)) {
64
- if (!map2DocMap.has(map)) {
65
- const embeddedUri = context.encodeEmbeddedDocumentUri(uri, virtualCode.id);
66
- map2DocMap.set(map, new documents_1.SourceMapWithDocuments(this.get(uri, context.language.scripts.get(uri).languageId, snapshot), this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
67
- }
68
- yield map2DocMap.get(map);
62
+ getSourceMap(virtualCode) {
63
+ const map = context.language.maps.get(virtualCode);
64
+ let result = map2DocMap.get(map);
65
+ if (!result) {
66
+ const sourceScript = context.language.scripts.fromVirtualCode(virtualCode);
67
+ const embeddedUri = context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
68
+ map2DocMap.set(map, result = new documents_1.SourceMapWithDocuments(this.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot), this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
69
69
  }
70
+ return result;
70
71
  },
71
72
  getLinkedCodeMap(virtualCode, documentUri) {
72
73
  const map = context.language.linkedCodeMaps.get(virtualCode);
package/lib/types.d.ts CHANGED
@@ -49,7 +49,7 @@ export interface LanguageServiceContext {
49
49
  };
50
50
  documents: {
51
51
  get(uri: URI, languageId: string, snapshot: ts.IScriptSnapshot): TextDocument;
52
- getMaps(virtualCode: VirtualCode): Generator<SourceMapWithDocuments>;
52
+ getSourceMap(virtualCode: VirtualCode): SourceMapWithDocuments;
53
53
  getLinkedCodeMap(virtualCode: VirtualCode, documentUri: URI): LinkedCodeMapWithDocument | undefined;
54
54
  };
55
55
  plugins: [LanguageServicePlugin, LanguageServicePluginInstance][];
@@ -5,7 +5,7 @@ export declare function createLocationSet(): {
5
5
  };
6
6
  export declare function withCodeAction<T extends vscode.CodeAction>(items: T[]): T[];
7
7
  export declare function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[];
8
- export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.TextDocumentEdit | vscode.CreateFile | vscode.RenameFile | vscode.DeleteFile)[];
8
+ export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.CreateFile | vscode.TextDocumentEdit | vscode.RenameFile | vscode.DeleteFile)[];
9
9
  export declare function withDiagnostics<T extends vscode.Diagnostic>(items: T[]): T[];
10
10
  export declare function withLocations<T extends vscode.Location>(items: T[]): T[];
11
11
  export declare function withLocationLinks<T extends vscode.LocationLink>(items: T[]): T[];
@@ -89,11 +89,9 @@ function* forEachEmbeddedDocument(context, sourceScriptId, current) {
89
89
  yield* forEachEmbeddedDocument(context, sourceScriptId, embeddedCode);
90
90
  }
91
91
  }
92
- for (const map of context.documents.getMaps(current)) {
93
- if (sourceScriptId.toString() === map.sourceDocument.uri
94
- && !context.disabledEmbeddedDocumentUris.get(context.encodeEmbeddedDocumentUri(sourceScriptId, current.id))) {
95
- yield map;
96
- }
92
+ const map = context.documents.getSourceMap(current);
93
+ if (!context.disabledEmbeddedDocumentUris.get(context.encodeEmbeddedDocumentUri(sourceScriptId, current.id))) {
94
+ yield map;
97
95
  }
98
96
  }
99
97
  exports.forEachEmbeddedDocument = forEachEmbeddedDocument;
@@ -15,10 +15,8 @@ function transformDocumentLinkTarget(_target, context) {
15
15
  const virtualCode = sourceScript?.generated?.embeddedCodes.get(decoded[1]);
16
16
  target = decoded[0];
17
17
  if (embeddedRange && virtualCode) {
18
- for (const map of context.documents.getMaps(virtualCode)) {
19
- if (!map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
20
- continue;
21
- }
18
+ const map = context.documents.getSourceMap(virtualCode);
19
+ if (map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
22
20
  const startLine = Number(embeddedRange[1]) - 1;
23
21
  const startCharacter = Number(embeddedRange[3] ?? 1) - 1;
24
22
  if (embeddedRange[5] !== undefined) {
@@ -33,7 +31,6 @@ function transformDocumentLinkTarget(_target, context) {
33
31
  fragment: 'L' + (sourceRange.start.line + 1) + ',' + (sourceRange.start.character + 1)
34
32
  + '-L' + (sourceRange.end.line + 1) + ',' + (sourceRange.end.character + 1),
35
33
  });
36
- break;
37
34
  }
38
35
  }
39
36
  else {
@@ -42,7 +39,6 @@ function transformDocumentLinkTarget(_target, context) {
42
39
  target = target.with({
43
40
  fragment: 'L' + (sourcePos.line + 1) + ',' + (sourcePos.character + 1),
44
41
  });
45
- break;
46
42
  }
47
43
  }
48
44
  }
@@ -276,11 +272,10 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
276
272
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
277
273
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
278
274
  if (virtualCode) {
279
- for (const map of context.documents.getMaps(virtualCode)) {
280
- // TODO: check capability?
281
- const uri = map.sourceDocument.uri;
282
- sourceResult.changeAnnotations[uri] = tsAnno;
283
- }
275
+ const map = context.documents.getSourceMap(virtualCode);
276
+ // TODO: check capability?
277
+ const uri = map.sourceDocument.uri;
278
+ sourceResult.changeAnnotations[uri] = tsAnno;
284
279
  }
285
280
  else {
286
281
  sourceResult.changeAnnotations[tsUri] = tsAnno;
@@ -292,31 +287,30 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
292
287
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
293
288
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
294
289
  if (virtualCode) {
295
- for (const map of context.documents.getMaps(virtualCode)) {
296
- const tsEdits = edit.changes[tsUri];
297
- for (const tsEdit of tsEdits) {
298
- if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
299
- let _data;
300
- const range = map.getSourceRange(tsEdit.range, data => {
301
- _data = data;
302
- return (0, language_core_1.isRenameEnabled)(data);
290
+ const map = context.documents.getSourceMap(virtualCode);
291
+ const tsEdits = edit.changes[tsUri];
292
+ for (const tsEdit of tsEdits) {
293
+ if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
294
+ let _data;
295
+ const range = map.getSourceRange(tsEdit.range, data => {
296
+ _data = data;
297
+ return (0, language_core_1.isRenameEnabled)(data);
298
+ });
299
+ if (range) {
300
+ sourceResult.changes[map.sourceDocument.uri] ??= [];
301
+ sourceResult.changes[map.sourceDocument.uri].push({
302
+ newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
303
+ range,
303
304
  });
304
- if (range) {
305
- sourceResult.changes[map.sourceDocument.uri] ??= [];
306
- sourceResult.changes[map.sourceDocument.uri].push({
307
- newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
308
- range,
309
- });
310
- hasResult = true;
311
- }
305
+ hasResult = true;
312
306
  }
313
- else {
314
- const range = map.getSourceRange(tsEdit.range);
315
- if (range) {
316
- sourceResult.changes[map.sourceDocument.uri] ??= [];
317
- sourceResult.changes[map.sourceDocument.uri].push({ newText: tsEdit.newText, range });
318
- hasResult = true;
319
- }
307
+ }
308
+ else {
309
+ const range = map.getSourceRange(tsEdit.range);
310
+ if (range) {
311
+ sourceResult.changes[map.sourceDocument.uri] ??= [];
312
+ sourceResult.changes[map.sourceDocument.uri].push({ newText: tsEdit.newText, range });
313
+ hasResult = true;
320
314
  }
321
315
  }
322
316
  }
@@ -335,45 +329,44 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
335
329
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
336
330
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
337
331
  if (virtualCode) {
338
- for (const map of context.documents.getMaps(virtualCode)) {
339
- sourceEdit = {
340
- textDocument: {
341
- uri: map.sourceDocument.uri,
342
- version: versions[map.sourceDocument.uri] ?? null,
343
- },
344
- edits: [],
345
- };
346
- for (const tsEdit of tsDocEdit.edits) {
347
- if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
348
- let _data;
349
- const range = map.getSourceRange(tsEdit.range, data => {
350
- _data = data;
351
- // fix https://github.com/johnsoncodehk/volar/issues/1091
352
- return (0, language_core_1.isRenameEnabled)(data);
332
+ const map = context.documents.getSourceMap(virtualCode);
333
+ sourceEdit = {
334
+ textDocument: {
335
+ uri: map.sourceDocument.uri,
336
+ version: versions[map.sourceDocument.uri] ?? null,
337
+ },
338
+ edits: [],
339
+ };
340
+ for (const tsEdit of tsDocEdit.edits) {
341
+ if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
342
+ let _data;
343
+ const range = map.getSourceRange(tsEdit.range, data => {
344
+ _data = data;
345
+ // fix https://github.com/johnsoncodehk/volar/issues/1091
346
+ return (0, language_core_1.isRenameEnabled)(data);
347
+ });
348
+ if (range) {
349
+ sourceEdit.edits.push({
350
+ annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
351
+ newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
352
+ range,
353
353
  });
354
- if (range) {
355
- sourceEdit.edits.push({
356
- annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
357
- newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
358
- range,
359
- });
360
- }
361
- }
362
- else {
363
- const range = map.getSourceRange(tsEdit.range);
364
- if (range) {
365
- sourceEdit.edits.push({
366
- annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
367
- newText: tsEdit.newText,
368
- range,
369
- });
370
- }
371
354
  }
372
355
  }
373
- if (!sourceEdit.edits.length) {
374
- sourceEdit = undefined;
356
+ else {
357
+ const range = map.getSourceRange(tsEdit.range);
358
+ if (range) {
359
+ sourceEdit.edits.push({
360
+ annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
361
+ newText: tsEdit.newText,
362
+ range,
363
+ });
364
+ }
375
365
  }
376
366
  }
367
+ if (!sourceEdit.edits.length) {
368
+ sourceEdit = undefined;
369
+ }
377
370
  }
378
371
  else {
379
372
  sourceEdit = tsDocEdit;
@@ -387,16 +380,15 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
387
380
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
388
381
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
389
382
  if (virtualCode) {
390
- for (const map of context.documents.getMaps(virtualCode)) {
391
- // TODO: check capability?
392
- sourceEdit = {
393
- kind: 'rename',
394
- oldUri: map.sourceDocument.uri,
395
- newUri: tsDocEdit.newUri /* TODO: remove .ts? */,
396
- options: tsDocEdit.options,
397
- annotationId: tsDocEdit.annotationId,
398
- };
399
- }
383
+ const map = context.documents.getSourceMap(virtualCode);
384
+ // TODO: check capability?
385
+ sourceEdit = {
386
+ kind: 'rename',
387
+ oldUri: map.sourceDocument.uri,
388
+ newUri: tsDocEdit.newUri /* TODO: remove .ts? */,
389
+ options: tsDocEdit.options,
390
+ annotationId: tsDocEdit.annotationId,
391
+ };
400
392
  }
401
393
  else {
402
394
  sourceEdit = tsDocEdit;
@@ -407,15 +399,14 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
407
399
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
408
400
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
409
401
  if (virtualCode) {
410
- for (const map of context.documents.getMaps(virtualCode)) {
411
- // TODO: check capability?
412
- sourceEdit = {
413
- kind: 'delete',
414
- uri: map.sourceDocument.uri,
415
- options: tsDocEdit.options,
416
- annotationId: tsDocEdit.annotationId,
417
- };
418
- }
402
+ const map = context.documents.getSourceMap(virtualCode);
403
+ // TODO: check capability?
404
+ sourceEdit = {
405
+ kind: 'delete',
406
+ uri: map.sourceDocument.uri,
407
+ options: tsDocEdit.options,
408
+ annotationId: tsDocEdit.annotationId,
409
+ };
419
410
  }
420
411
  else {
421
412
  sourceEdit = tsDocEdit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "2.3.0-alpha.4",
3
+ "version": "2.3.0-alpha.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,10 +12,10 @@
12
12
  "directory": "packages/language-service"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.3.0-alpha.4",
15
+ "@volar/language-core": "2.3.0-alpha.5",
16
16
  "vscode-languageserver-protocol": "^3.17.5",
17
17
  "vscode-languageserver-textdocument": "^1.0.11",
18
18
  "vscode-uri": "^3.0.8"
19
19
  },
20
- "gitHead": "8ab3ce02b06a410e9321eea3e9f23d36f97fedda"
20
+ "gitHead": "c3f6867de39095913ceaa2256ad35a9ca1a90487"
21
21
  }