@volar/language-service 2.3.0-alpha.3 → 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;
@@ -10,43 +10,35 @@ function transformDocumentLinkTarget(_target, context) {
10
10
  if (!decoded) {
11
11
  return target;
12
12
  }
13
- target = decoded[0];
14
- const sourceScript = context.language.scripts.get(target);
13
+ const embeddedRange = target.fragment.match(/^L(\d+)(,(\d+))?(-L(\d+)(,(\d+))?)?$/);
14
+ const sourceScript = context.language.scripts.get(decoded[0]);
15
15
  const virtualCode = sourceScript?.generated?.embeddedCodes.get(decoded[1]);
16
- if (virtualCode) {
17
- for (const map of context.documents.getMaps(virtualCode)) {
18
- if (!map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
19
- continue;
20
- }
21
- target = vscode_uri_1.URI.parse(map.sourceDocument.uri);
22
- const hash = target.fragment;
23
- const range = hash.match(/^L(\d+)(,(\d+))?(-L(\d+)(,(\d+))?)?$/);
24
- if (range) {
25
- const startLine = Number(range[1]) - 1;
26
- const startCharacter = Number(range[3] ?? 1) - 1;
27
- if (range[5] !== undefined) {
28
- const endLine = Number(range[5]) - 1;
29
- const endCharacter = Number(range[7] ?? 1) - 1;
30
- const sourceRange = map.getSourceRange({
31
- start: { line: startLine, character: startCharacter },
32
- end: { line: endLine, character: endCharacter },
16
+ target = decoded[0];
17
+ if (embeddedRange && virtualCode) {
18
+ const map = context.documents.getSourceMap(virtualCode);
19
+ if (map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
20
+ const startLine = Number(embeddedRange[1]) - 1;
21
+ const startCharacter = Number(embeddedRange[3] ?? 1) - 1;
22
+ if (embeddedRange[5] !== undefined) {
23
+ const endLine = Number(embeddedRange[5]) - 1;
24
+ const endCharacter = Number(embeddedRange[7] ?? 1) - 1;
25
+ const sourceRange = map.getSourceRange({
26
+ start: { line: startLine, character: startCharacter },
27
+ end: { line: endLine, character: endCharacter },
28
+ });
29
+ if (sourceRange) {
30
+ target = target.with({
31
+ fragment: 'L' + (sourceRange.start.line + 1) + ',' + (sourceRange.start.character + 1)
32
+ + '-L' + (sourceRange.end.line + 1) + ',' + (sourceRange.end.character + 1),
33
33
  });
34
- if (sourceRange) {
35
- target = target.with({
36
- fragment: 'L' + (sourceRange.start.line + 1) + ',' + (sourceRange.start.character + 1)
37
- + '-L' + (sourceRange.end.line + 1) + ',' + (sourceRange.end.character + 1),
38
- });
39
- break;
40
- }
41
34
  }
42
- else {
43
- const sourcePos = map.getSourcePosition({ line: startLine, character: startCharacter });
44
- if (sourcePos) {
45
- target = target.with({
46
- fragment: 'L' + (sourcePos.line + 1) + ',' + (sourcePos.character + 1),
47
- });
48
- break;
49
- }
35
+ }
36
+ else {
37
+ const sourcePos = map.getSourcePosition({ line: startLine, character: startCharacter });
38
+ if (sourcePos) {
39
+ target = target.with({
40
+ fragment: 'L' + (sourcePos.line + 1) + ',' + (sourcePos.character + 1),
41
+ });
50
42
  }
51
43
  }
52
44
  }
@@ -280,11 +272,10 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
280
272
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
281
273
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
282
274
  if (virtualCode) {
283
- for (const map of context.documents.getMaps(virtualCode)) {
284
- // TODO: check capability?
285
- const uri = map.sourceDocument.uri;
286
- sourceResult.changeAnnotations[uri] = tsAnno;
287
- }
275
+ const map = context.documents.getSourceMap(virtualCode);
276
+ // TODO: check capability?
277
+ const uri = map.sourceDocument.uri;
278
+ sourceResult.changeAnnotations[uri] = tsAnno;
288
279
  }
289
280
  else {
290
281
  sourceResult.changeAnnotations[tsUri] = tsAnno;
@@ -296,31 +287,30 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
296
287
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
297
288
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
298
289
  if (virtualCode) {
299
- for (const map of context.documents.getMaps(virtualCode)) {
300
- const tsEdits = edit.changes[tsUri];
301
- for (const tsEdit of tsEdits) {
302
- if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
303
- let _data;
304
- const range = map.getSourceRange(tsEdit.range, data => {
305
- _data = data;
306
- 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,
307
304
  });
308
- if (range) {
309
- sourceResult.changes[map.sourceDocument.uri] ??= [];
310
- sourceResult.changes[map.sourceDocument.uri].push({
311
- newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
312
- range,
313
- });
314
- hasResult = true;
315
- }
305
+ hasResult = true;
316
306
  }
317
- else {
318
- const range = map.getSourceRange(tsEdit.range);
319
- if (range) {
320
- sourceResult.changes[map.sourceDocument.uri] ??= [];
321
- sourceResult.changes[map.sourceDocument.uri].push({ newText: tsEdit.newText, range });
322
- hasResult = true;
323
- }
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;
324
314
  }
325
315
  }
326
316
  }
@@ -339,45 +329,44 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
339
329
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
340
330
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
341
331
  if (virtualCode) {
342
- for (const map of context.documents.getMaps(virtualCode)) {
343
- sourceEdit = {
344
- textDocument: {
345
- uri: map.sourceDocument.uri,
346
- version: versions[map.sourceDocument.uri] ?? null,
347
- },
348
- edits: [],
349
- };
350
- for (const tsEdit of tsDocEdit.edits) {
351
- if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
352
- let _data;
353
- const range = map.getSourceRange(tsEdit.range, data => {
354
- _data = data;
355
- // fix https://github.com/johnsoncodehk/volar/issues/1091
356
- 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,
357
353
  });
358
- if (range) {
359
- sourceEdit.edits.push({
360
- annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
361
- newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
362
- range,
363
- });
364
- }
365
- }
366
- else {
367
- const range = map.getSourceRange(tsEdit.range);
368
- if (range) {
369
- sourceEdit.edits.push({
370
- annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
371
- newText: tsEdit.newText,
372
- range,
373
- });
374
- }
375
354
  }
376
355
  }
377
- if (!sourceEdit.edits.length) {
378
- 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
+ }
379
365
  }
380
366
  }
367
+ if (!sourceEdit.edits.length) {
368
+ sourceEdit = undefined;
369
+ }
381
370
  }
382
371
  else {
383
372
  sourceEdit = tsDocEdit;
@@ -391,16 +380,15 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
391
380
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
392
381
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
393
382
  if (virtualCode) {
394
- for (const map of context.documents.getMaps(virtualCode)) {
395
- // TODO: check capability?
396
- sourceEdit = {
397
- kind: 'rename',
398
- oldUri: map.sourceDocument.uri,
399
- newUri: tsDocEdit.newUri /* TODO: remove .ts? */,
400
- options: tsDocEdit.options,
401
- annotationId: tsDocEdit.annotationId,
402
- };
403
- }
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
+ };
404
392
  }
405
393
  else {
406
394
  sourceEdit = tsDocEdit;
@@ -411,15 +399,14 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
411
399
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
412
400
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
413
401
  if (virtualCode) {
414
- for (const map of context.documents.getMaps(virtualCode)) {
415
- // TODO: check capability?
416
- sourceEdit = {
417
- kind: 'delete',
418
- uri: map.sourceDocument.uri,
419
- options: tsDocEdit.options,
420
- annotationId: tsDocEdit.annotationId,
421
- };
422
- }
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
+ };
423
410
  }
424
411
  else {
425
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.3",
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.3",
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": "d322a122012dc339a3ac5139220e91649d508522"
20
+ "gitHead": "c3f6867de39095913ceaa2256ad35a9ca1a90487"
21
21
  }