@volar/language-service 2.4.27 → 2.4.29

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.
@@ -11,6 +11,10 @@ function register(context) {
11
11
  return async (uri, position, completionContext = {
12
12
  triggerKind: 1,
13
13
  }, token = cancellation_1.NoneCancellationToken) => {
14
+ // The results of this request. `lastResult` is only a cache for the
15
+ // TriggerForIncompleteCompletions case; requests that overlap must not
16
+ // push into each other's list.
17
+ let currentResult;
14
18
  let langaugeIdAndSnapshot;
15
19
  let sourceScript;
16
20
  const decoded = context.decodeEmbeddedDocumentUri(uri);
@@ -29,7 +33,8 @@ function register(context) {
29
33
  }
30
34
  if (completionContext?.triggerKind === 3
31
35
  && lastResult?.uri.toString() === uri.toString()) {
32
- for (const cacheData of lastResult.results) {
36
+ currentResult = lastResult;
37
+ for (const cacheData of currentResult.results) {
33
38
  if (!cacheData.list?.isIncomplete) {
34
39
  continue;
35
40
  }
@@ -104,7 +109,7 @@ function register(context) {
104
109
  }
105
110
  }
106
111
  else {
107
- lastResult = {
112
+ currentResult = lastResult = {
108
113
  uri,
109
114
  results: [],
110
115
  };
@@ -135,7 +140,7 @@ function register(context) {
135
140
  continue;
136
141
  }
137
142
  // avoid duplicate items with .vue and .vue.html
138
- if (plugin[1].isAdditionalCompletion && lastResult?.results.some(data => data.plugin === plugin[1])) {
143
+ if (plugin[1].isAdditionalCompletion && currentResult.results.some(data => data.plugin === plugin[1])) {
139
144
  continue;
140
145
  }
141
146
  let completionList = await plugin[1].provideCompletionItems(document, position, completionContext, token);
@@ -169,7 +174,7 @@ function register(context) {
169
174
  if (docs) {
170
175
  completionList = (0, transform_1.transformCompletionList)(completionList, range => (0, featureWorkers_1.getSourceRange)(docs, range, language_core_1.isCompletionEnabled), document, context);
171
176
  }
172
- lastResult?.results.push({
177
+ currentResult.results.push({
173
178
  embeddedDocumentUri: docs ? vscode_uri_1.URI.parse(document.uri) : undefined,
174
179
  plugin: plugin[1],
175
180
  list: completionList,
@@ -193,7 +198,7 @@ function register(context) {
193
198
  await worker(document, position);
194
199
  }
195
200
  }
196
- return combineCompletionList(lastResult.results.map(cacheData => cacheData.list));
201
+ return combineCompletionList(currentResult.results.map(cacheData => cacheData.list));
197
202
  function sortServices(a, b) {
198
203
  return (b.isAdditionalCompletion ? -1 : 1) - (a.isAdditionalCompletion ? -1 : 1);
199
204
  }
@@ -18,7 +18,11 @@ function register(context) {
18
18
  ?? (item.edit
19
19
  ? {
20
20
  ...item,
21
- edit: (0, transform_1.transformWorkspaceEdit)(item.edit, context, 'codeAction', { [data.uri]: data.version }),
21
+ // No `versions`: `data.version` is the service's own document counter
22
+ // (see `context.documents.get`), not the version the client sent. Reporting
23
+ // it makes strict clients reject the edit as stale, so leave it `null`, as
24
+ // `provideCodeActions` already does.
25
+ edit: (0, transform_1.transformWorkspaceEdit)(item.edit, context, 'codeAction'),
22
26
  }
23
27
  : item);
24
28
  }
@@ -280,6 +280,9 @@ function transformWorkspaceSymbol(symbol, getOtherLocation) {
280
280
  }
281
281
  function transformWorkspaceEdit(edit, context, mode, versions = {}) {
282
282
  const sourceResult = {};
283
+ // A code action applied partially can leave the document broken, so it is dropped
284
+ // as a whole when any of its edits has no source range.
285
+ const unmappedEdits = new Set();
283
286
  let hasResult = false;
284
287
  for (const tsUri in edit.changeAnnotations) {
285
288
  sourceResult.changeAnnotations ??= {};
@@ -306,10 +309,13 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
306
309
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
307
310
  if (sourceScript && virtualCode) {
308
311
  const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
312
+ const tsEdits = edit.changes[tsUri];
313
+ for (const tsEdit of tsEdits) {
314
+ unmappedEdits.add(tsEdit);
315
+ }
309
316
  for (const [sourceScript, map] of context.language.maps.forEach(virtualCode)) {
310
317
  const sourceDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
311
318
  const docs = [sourceDocument, embeddedDocument, map];
312
- const tsEdits = edit.changes[tsUri];
313
319
  for (const tsEdit of tsEdits) {
314
320
  if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
315
321
  let _data;
@@ -318,6 +324,7 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
318
324
  return (0, language_core_1.isRenameEnabled)(data);
319
325
  });
320
326
  if (range) {
327
+ unmappedEdits.delete(tsEdit);
321
328
  sourceResult.changes[sourceDocument.uri] ??= [];
322
329
  sourceResult.changes[sourceDocument.uri].push({
323
330
  newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
@@ -329,6 +336,7 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
329
336
  else {
330
337
  const range = (0, featureWorkers_1.getSourceRange)(docs, tsEdit.range);
331
338
  if (range) {
339
+ unmappedEdits.delete(tsEdit);
332
340
  sourceResult.changes[sourceDocument.uri] ??= [];
333
341
  sourceResult.changes[sourceDocument.uri].push({ newText: tsEdit.newText, range });
334
342
  hasResult = true;
@@ -352,6 +360,9 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
352
360
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
353
361
  if (sourceScript && virtualCode) {
354
362
  const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
363
+ for (const tsEdit of tsDocEdit.edits) {
364
+ unmappedEdits.add(tsEdit);
365
+ }
355
366
  for (const [sourceScript, map] of context.language.maps.forEach(virtualCode)) {
356
367
  const sourceDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
357
368
  const docs = [sourceDocument, embeddedDocument, map];
@@ -371,6 +382,7 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
371
382
  return (0, language_core_1.isRenameEnabled)(data);
372
383
  });
373
384
  if (range) {
385
+ unmappedEdits.delete(tsEdit);
374
386
  sourceEdit.edits.push({
375
387
  annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
376
388
  newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
@@ -381,6 +393,7 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
381
393
  else {
382
394
  const range = (0, featureWorkers_1.getSourceRange)(docs, tsEdit.range);
383
395
  if (range) {
396
+ unmappedEdits.delete(tsEdit);
384
397
  sourceEdit.edits.push({
385
398
  annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
386
399
  newText: tsEdit.newText,
@@ -446,6 +459,9 @@ function transformWorkspaceEdit(edit, context, mode, versions = {}) {
446
459
  }
447
460
  }
448
461
  }
462
+ if (mode === 'codeAction' && unmappedEdits.size) {
463
+ return;
464
+ }
449
465
  if (hasResult) {
450
466
  return sourceResult;
451
467
  }
package/package.json CHANGED
@@ -1,20 +1,28 @@
1
1
  {
2
- "name": "@volar/language-service",
3
- "version": "2.4.27",
4
- "license": "MIT",
5
- "files": [
6
- "**/*.js",
7
- "**/*.d.ts"
8
- ],
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/volarjs/volar.js.git",
12
- "directory": "packages/language-service"
13
- },
14
- "dependencies": {
15
- "@volar/language-core": "2.4.27",
16
- "vscode-languageserver-protocol": "^3.17.5",
17
- "vscode-languageserver-textdocument": "^1.0.11",
18
- "vscode-uri": "^3.0.8"
19
- }
20
- }
2
+ "name": "@volar/language-service",
3
+ "version": "2.4.29",
4
+ "license": "MIT",
5
+ "files": [
6
+ "**/*.js",
7
+ "**/*.d.ts"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/volarjs/volar.js.git",
12
+ "directory": "packages/language-service"
13
+ },
14
+ "dependencies": {
15
+ "@volar/language-core": "2.4.29",
16
+ "vscode-languageserver-protocol": "^3.17.5",
17
+ "vscode-languageserver-textdocument": "^1.0.11",
18
+ "vscode-uri": "^3.0.8"
19
+ },
20
+ "peerDependencies": {
21
+ "typescript": "*"
22
+ },
23
+ "peerDependenciesMeta": {
24
+ "typescript": {
25
+ "optional": true
26
+ }
27
+ }
28
+ }