@volar/language-service 2.4.31 → 2.4.32

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.
@@ -7,14 +7,19 @@ const cancellation_1 = require("../utils/cancellation");
7
7
  const featureWorkers_1 = require("../utils/featureWorkers");
8
8
  const transform_1 = require("../utils/transform");
9
9
  function register(context) {
10
+ // The result of the most recently started request that finished without
11
+ // being cancelled: what a TriggerForIncompleteCompletions request refreshes.
12
+ // Only a finished request writes it; a request reads and fills its own result.
10
13
  let lastResult;
14
+ let started = 0;
11
15
  return async (uri, position, completionContext = {
12
16
  triggerKind: 1,
13
17
  }, 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;
18
+ const currentResult = {
19
+ uri,
20
+ order: ++started,
21
+ results: [],
22
+ };
18
23
  let langaugeIdAndSnapshot;
19
24
  let sourceScript;
20
25
  const decoded = context.decodeEmbeddedDocumentUri(uri);
@@ -33,8 +38,11 @@ function register(context) {
33
38
  }
34
39
  if (completionContext?.triggerKind === 3
35
40
  && lastResult?.uri.toString() === uri.toString()) {
36
- currentResult = lastResult;
41
+ currentResult.results = lastResult.results.map(cacheData => ({ ...cacheData }));
37
42
  for (const cacheData of currentResult.results) {
43
+ if (token.isCancellationRequested) {
44
+ break;
45
+ }
38
46
  if (!cacheData.list?.isIncomplete) {
39
47
  continue;
40
48
  }
@@ -109,10 +117,6 @@ function register(context) {
109
117
  }
110
118
  }
111
119
  else {
112
- currentResult = lastResult = {
113
- uri,
114
- results: [],
115
- };
116
120
  // monky fix https://github.com/johnsoncodehk/volar/issues/1358
117
121
  let isFirstMapping = true;
118
122
  let mainCompletionUri;
@@ -198,6 +202,9 @@ function register(context) {
198
202
  await worker(document, position);
199
203
  }
200
204
  }
205
+ if (!token.isCancellationRequested && (!lastResult || currentResult.order > lastResult.order)) {
206
+ lastResult = currentResult;
207
+ }
201
208
  return combineCompletionList(currentResult.results.map(cacheData => cacheData.list));
202
209
  function sortServices(a, b) {
203
210
  return (b.isAdditionalCompletion ? -1 : 1) - (a.isAdditionalCompletion ? -1 : 1);
@@ -37,9 +37,18 @@ function createLocationSet() {
37
37
  }
38
38
  }
39
39
  function withCodeAction(items) {
40
- return dedupe(items, item => [
41
- item.title,
42
- ].join(':'));
40
+ return dedupe(items, item => {
41
+ // Two actions are the same when they do the same thing to the source file.
42
+ if (item.edit || item.command) {
43
+ // The effect is here (the edit is already mapped to the source file): compare it.
44
+ return JSON.stringify([item.title, item.kind, item.edit, item.command]);
45
+ }
46
+ // Resolved lazily: the effect is known only to the plugin, after resolve. The plugin's
47
+ // data is the identity of an unresolved action, so actions are merged only when the
48
+ // same plugin gave them the same data, never by title alone.
49
+ const data = item.data;
50
+ return JSON.stringify([item.title, item.kind, data?.pluginIndex, data?.original?.data]);
51
+ });
43
52
  }
44
53
  function withTextEdits(items) {
45
54
  return dedupe(items, item => [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "2.4.31",
3
+ "version": "2.4.32",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-service"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.4.31",
15
+ "@volar/language-core": "2.4.32",
16
16
  "vscode-languageserver-protocol": "^3.17.5",
17
17
  "vscode-languageserver-textdocument": "^1.0.11",
18
18
  "vscode-uri": "^3.0.8"