@volar/language-service 1.3.0-alpha.3 → 1.4.0-alpha.1

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 (82) hide show
  1. package/out/baseLanguageService.d.ts +37 -41
  2. package/out/baseLanguageService.js +26 -19
  3. package/out/documentFeatures/colorPresentations.d.ts +1 -1
  4. package/out/documentFeatures/colorPresentations.js +8 -4
  5. package/out/documentFeatures/documentColors.d.ts +1 -1
  6. package/out/documentFeatures/documentColors.js +8 -4
  7. package/out/documentFeatures/documentSymbols.d.ts +1 -1
  8. package/out/documentFeatures/documentSymbols.js +8 -15
  9. package/out/documentFeatures/foldingRanges.d.ts +2 -2
  10. package/out/documentFeatures/foldingRanges.js +6 -2
  11. package/out/documentFeatures/format.d.ts +2 -2
  12. package/out/documentFeatures/format.js +32 -39
  13. package/out/documentFeatures/linkedEditingRanges.d.ts +1 -1
  14. package/out/documentFeatures/linkedEditingRanges.js +8 -4
  15. package/out/documentFeatures/selectionRanges.d.ts +1 -1
  16. package/out/documentFeatures/selectionRanges.js +8 -4
  17. package/out/documents.js +3 -4
  18. package/out/index.d.ts +2 -0
  19. package/out/index.js +41 -1
  20. package/out/languageFeatures/autoInsert.d.ts +2 -2
  21. package/out/languageFeatures/autoInsert.js +12 -6
  22. package/out/languageFeatures/callHierarchy.d.ts +3 -3
  23. package/out/languageFeatures/callHierarchy.js +69 -76
  24. package/out/languageFeatures/codeActionResolve.d.ts +2 -2
  25. package/out/languageFeatures/codeActionResolve.js +10 -20
  26. package/out/languageFeatures/codeActions.d.ts +1 -1
  27. package/out/languageFeatures/codeActions.js +26 -31
  28. package/out/languageFeatures/codeLens.d.ts +1 -1
  29. package/out/languageFeatures/codeLens.js +19 -25
  30. package/out/languageFeatures/codeLensResolve.d.ts +1 -1
  31. package/out/languageFeatures/codeLensResolve.js +9 -19
  32. package/out/languageFeatures/complete.d.ts +1 -1
  33. package/out/languageFeatures/complete.js +35 -41
  34. package/out/languageFeatures/completeResolve.d.ts +1 -1
  35. package/out/languageFeatures/completeResolve.js +6 -17
  36. package/out/languageFeatures/definition.d.ts +1 -1
  37. package/out/languageFeatures/definition.js +41 -51
  38. package/out/languageFeatures/documentHighlights.d.ts +1 -1
  39. package/out/languageFeatures/documentHighlights.js +37 -44
  40. package/out/languageFeatures/documentLinks.d.ts +1 -1
  41. package/out/languageFeatures/documentLinks.js +13 -16
  42. package/out/languageFeatures/documentSemanticTokens.d.ts +1 -2
  43. package/out/languageFeatures/documentSemanticTokens.js +19 -8
  44. package/out/languageFeatures/fileReferences.d.ts +1 -1
  45. package/out/languageFeatures/fileReferences.js +8 -16
  46. package/out/languageFeatures/fileRename.d.ts +2 -1
  47. package/out/languageFeatures/fileRename.js +8 -16
  48. package/out/languageFeatures/hover.d.ts +1 -1
  49. package/out/languageFeatures/hover.js +10 -9
  50. package/out/languageFeatures/inlayHints.d.ts +1 -1
  51. package/out/languageFeatures/inlayHints.js +16 -21
  52. package/out/languageFeatures/references.d.ts +1 -1
  53. package/out/languageFeatures/references.js +29 -39
  54. package/out/languageFeatures/rename.d.ts +1 -1
  55. package/out/languageFeatures/rename.js +57 -69
  56. package/out/languageFeatures/renamePrepare.d.ts +1 -1
  57. package/out/languageFeatures/renamePrepare.js +6 -2
  58. package/out/languageFeatures/signatureHelp.d.ts +2 -2
  59. package/out/languageFeatures/signatureHelp.js +18 -2
  60. package/out/languageFeatures/validation.d.ts +1 -1
  61. package/out/languageFeatures/validation.js +143 -165
  62. package/out/languageFeatures/workspaceSymbols.d.ts +1 -1
  63. package/out/languageFeatures/workspaceSymbols.js +8 -15
  64. package/out/transformer/completionItem.js +9 -4
  65. package/out/transformer/completionList.js +6 -3
  66. package/out/transformer/documentSymbol.js +9 -4
  67. package/out/transformer/foldingRanges.js +2 -3
  68. package/out/transformer/hover.js +5 -2
  69. package/out/transformer/locationLike.js +4 -1
  70. package/out/transformer/locationsLike.js +2 -2
  71. package/out/transformer/selectionRanges.js +2 -2
  72. package/out/transformer/textEdit.js +20 -5
  73. package/out/transformer/workspaceSymbol.js +4 -1
  74. package/out/types.d.ts +56 -80
  75. package/out/types.js +0 -1
  76. package/out/utils/SemanticTokensBuilder.d.ts +13 -0
  77. package/out/utils/SemanticTokensBuilder.js +42 -0
  78. package/out/utils/common.d.ts +3 -0
  79. package/out/utils/common.js +25 -1
  80. package/out/utils/definePlugin.js +11 -23
  81. package/out/utils/featureWorkers.js +127 -155
  82. package/package.json +5 -6
@@ -1,35 +1,25 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.register = exports.showReferencesCommand = void 0;
12
3
  const references = require("./references");
13
4
  exports.showReferencesCommand = `volar.${Math.random().toString(36).slice(2)}.show-references`;
14
5
  function register(context) {
15
6
  const findReferences = references.register(context);
16
- return (item) => __awaiter(this, void 0, void 0, function* () {
17
- var _a, _b, _c;
7
+ return async (item, token) => {
18
8
  const data = item.data;
19
- if ((data === null || data === void 0 ? void 0 : data.kind) === 'normal') {
9
+ if (data?.kind === 'normal') {
20
10
  const plugin = context.plugins[data.pluginId];
21
- if (!((_a = plugin.codeLens) === null || _a === void 0 ? void 0 : _a.resolve))
11
+ if (!plugin.resolveCodeLens)
22
12
  return item;
23
13
  Object.assign(item, data.original);
24
- item = yield plugin.codeLens.resolve(item);
14
+ item = await plugin.resolveCodeLens(item, token);
25
15
  // item.range already transformed in codeLens request
26
16
  }
27
- if ((data === null || data === void 0 ? void 0 : data.kind) === 'references') {
28
- let references = (_b = yield findReferences(data.uri, item.range.start)) !== null && _b !== void 0 ? _b : [];
17
+ if (data?.kind === 'references') {
18
+ let references = await findReferences(data.uri, item.range.start, token) ?? [];
29
19
  const plugin = context.plugins[data.pluginId];
30
20
  const document = context.getTextDocument(data.uri);
31
- if (document && ((_c = plugin.referencesCodeLens) === null || _c === void 0 ? void 0 : _c.resolve)) {
32
- references = yield plugin.referencesCodeLens.resolve(document, data.location, references);
21
+ if (document && plugin.resolveReferencesCodeLens) {
22
+ references = await plugin.resolveReferencesCodeLens(document, data.location, references, token);
33
23
  }
34
24
  item.command = {
35
25
  title: references.length === 1 ? '1 reference' : `${references.length} references`,
@@ -38,7 +28,7 @@ function register(context) {
38
28
  };
39
29
  }
40
30
  return item;
41
- });
31
+ };
42
32
  }
43
33
  exports.register = register;
44
34
  //# sourceMappingURL=codeLensResolve.js.map
@@ -8,4 +8,4 @@ export interface PluginCompletionData {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
10
10
  }
11
- export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext) => Promise<vscode.CompletionList>;
11
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext: vscode.CompletionContext | undefined, token: vscode.CancellationToken) => Promise<vscode.CompletionList>;
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.register = void 0;
12
3
  const transformer = require("../transformer");
@@ -14,20 +5,22 @@ const vscode = require("vscode-languageserver-protocol");
14
5
  const definePlugin_1 = require("../utils/definePlugin");
15
6
  function register(context) {
16
7
  let cache;
17
- return (uri, position, completionContext) => __awaiter(this, void 0, void 0, function* () {
18
- var _a, _b, _c, _d, _e;
8
+ return async (uri, position, completionContext, token) => {
9
+ completionContext ??= {
10
+ triggerKind: vscode.CompletionTriggerKind.Invoked,
11
+ };
19
12
  let document;
20
- if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerKind) === vscode.CompletionTriggerKind.TriggerForIncompleteCompletions
21
- && (cache === null || cache === void 0 ? void 0 : cache.uri) === uri) {
13
+ if (completionContext?.triggerKind === vscode.CompletionTriggerKind.TriggerForIncompleteCompletions
14
+ && cache?.uri === uri) {
22
15
  for (const cacheData of cache.data) {
23
16
  if (!cacheData.list.isIncomplete)
24
17
  continue;
25
18
  if (cacheData.map) {
26
19
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(cacheData.map.embeddedDocumentUri)) {
27
20
  for (const mapped of map.toGeneratedPositions(position, data => !!data.completion)) {
28
- if (!((_a = cacheData.plugin.complete) === null || _a === void 0 ? void 0 : _a.on))
21
+ if (!cacheData.plugin.provideCompletionItems)
29
22
  continue;
30
- const embeddedCompletionList = yield cacheData.plugin.complete.on(map.virtualFileDocument, mapped, completionContext);
23
+ const embeddedCompletionList = await cacheData.plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token);
31
24
  if (!embeddedCompletionList) {
32
25
  cacheData.list.isIncomplete = false;
33
26
  continue;
@@ -48,9 +41,9 @@ function register(context) {
48
41
  }
49
42
  }
50
43
  else if (document = context.getTextDocument(uri)) {
51
- if (!((_b = cacheData.plugin.complete) === null || _b === void 0 ? void 0 : _b.on))
44
+ if (!cacheData.plugin.provideCompletionItems)
52
45
  continue;
53
- const completionList = yield cacheData.plugin.complete.on(document, position, completionContext);
46
+ const completionList = await cacheData.plugin.provideCompletionItems(document, position, completionContext, token);
54
47
  if (!completionList) {
55
48
  cacheData.list.isIncomplete = false;
56
49
  continue;
@@ -71,7 +64,7 @@ function register(context) {
71
64
  }
72
65
  }
73
66
  else {
74
- const rootFile = (_c = context.documents.getSourceByUri(uri)) === null || _c === void 0 ? void 0 : _c.root;
67
+ const rootFile = context.documents.getSourceByUri(uri)?.root;
75
68
  cache = {
76
69
  uri,
77
70
  data: [],
@@ -80,8 +73,7 @@ function register(context) {
80
73
  // monky fix https://github.com/johnsoncodehk/volar/issues/1358
81
74
  let isFirstMapping = true;
82
75
  if (rootFile) {
83
- yield (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, (_, map) => __awaiter(this, void 0, void 0, function* () {
84
- var _f, _g;
76
+ await (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, async (_, map) => {
85
77
  const plugins = Object.values(context.plugins).sort(sortPlugins);
86
78
  let _data;
87
79
  for (const mapped of map.toGeneratedPositions(position, data => {
@@ -89,22 +81,24 @@ function register(context) {
89
81
  return !!data.completion;
90
82
  })) {
91
83
  for (const plugin of plugins) {
92
- if (!((_f = plugin.complete) === null || _f === void 0 ? void 0 : _f.on))
84
+ if (token.isCancellationRequested)
85
+ break;
86
+ if (!plugin.provideCompletionItems)
93
87
  continue;
94
- if (plugin.complete.isAdditional && !isFirstMapping)
88
+ if (plugin.isAdditionalCompletion && !isFirstMapping)
95
89
  continue;
96
- if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_g = plugin.complete.triggerCharacters) === null || _g === void 0 ? void 0 : _g.includes(completionContext.triggerCharacter)))
90
+ if (completionContext?.triggerCharacter && !plugin.triggerCharacters?.includes(completionContext.triggerCharacter))
97
91
  continue;
98
- const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.complete.isAdditional;
99
- if (cache.mainCompletion && (!isAdditional || (cache === null || cache === void 0 ? void 0 : cache.mainCompletion.documentUri) !== map.virtualFileDocument.uri))
92
+ const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.isAdditionalCompletion;
93
+ if (cache.mainCompletion && (!isAdditional || cache?.mainCompletion.documentUri !== map.virtualFileDocument.uri))
100
94
  continue;
101
95
  // avoid duplicate items with .vue and .vue.html
102
- if (plugin.complete.isAdditional && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin)))
96
+ if (plugin.isAdditionalCompletion && cache?.data.some(data => data.plugin === plugin))
103
97
  continue;
104
- const embeddedCompletionList = yield plugin.complete.on(map.virtualFileDocument, mapped, completionContext);
98
+ const embeddedCompletionList = await plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token);
105
99
  if (!embeddedCompletionList || !embeddedCompletionList.items.length)
106
100
  continue;
107
- if (typeof (_data === null || _data === void 0 ? void 0 : _data.completion) === 'object' && _data.completion.autoImportOnly) {
101
+ if (typeof _data?.completion === 'object' && _data.completion.autoImportOnly) {
108
102
  embeddedCompletionList.items = embeddedCompletionList.items.filter(item => !!item.labelDetails);
109
103
  }
110
104
  if (!isAdditional) {
@@ -133,26 +127,28 @@ function register(context) {
133
127
  isFirstMapping = false;
134
128
  }
135
129
  return true;
136
- }));
130
+ });
137
131
  }
138
132
  if (document = context.getTextDocument(uri)) {
139
133
  const plugins = Object.values(context.plugins).sort(sortPlugins);
140
134
  for (const plugin of plugins) {
141
- if (!((_d = plugin.complete) === null || _d === void 0 ? void 0 : _d.on))
135
+ if (token.isCancellationRequested)
136
+ break;
137
+ if (!plugin.provideCompletionItems)
142
138
  continue;
143
- if (plugin.complete.isAdditional && !isFirstMapping)
139
+ if (plugin.isAdditionalCompletion && !isFirstMapping)
144
140
  continue;
145
- if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_e = plugin.complete.triggerCharacters) === null || _e === void 0 ? void 0 : _e.includes(completionContext.triggerCharacter)))
141
+ if (completionContext?.triggerCharacter && !plugin.triggerCharacters?.includes(completionContext.triggerCharacter))
146
142
  continue;
147
- if (cache.mainCompletion && (!plugin.complete.isAdditional || cache.mainCompletion.documentUri !== document.uri))
143
+ if (cache.mainCompletion && (!plugin.isAdditionalCompletion || cache.mainCompletion.documentUri !== document.uri))
148
144
  continue;
149
145
  // avoid duplicate items with .vue and .vue.html
150
- if (plugin.complete.isAdditional && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin)))
146
+ if (plugin.isAdditionalCompletion && cache?.data.some(data => data.plugin === plugin))
151
147
  continue;
152
- const completionList = yield plugin.complete.on(document, position, completionContext);
148
+ const completionList = await plugin.provideCompletionItems(document, position, completionContext, token);
153
149
  if (!completionList || !completionList.items.length)
154
150
  continue;
155
- if (!plugin.complete.isAdditional) {
151
+ if (!plugin.isAdditionalCompletion) {
156
152
  cache.mainCompletion = { documentUri: document.uri };
157
153
  }
158
154
  completionList.items.forEach(item => {
@@ -177,18 +173,16 @@ function register(context) {
177
173
  }
178
174
  return combineCompletionList(cache.data.map(cacheData => cacheData.list));
179
175
  function sortPlugins(a, b) {
180
- var _a, _b;
181
- return (((_a = b.complete) === null || _a === void 0 ? void 0 : _a.isAdditional) ? -1 : 1) - (((_b = a.complete) === null || _b === void 0 ? void 0 : _b.isAdditional) ? -1 : 1);
176
+ return (b.isAdditionalCompletion ? -1 : 1) - (a.isAdditionalCompletion ? -1 : 1);
182
177
  }
183
178
  function combineCompletionList(lists) {
184
- var _a;
185
179
  return {
186
180
  isIncomplete: lists.some(list => list.isIncomplete),
187
- itemDefaults: (_a = lists.find(list => list.itemDefaults)) === null || _a === void 0 ? void 0 : _a.itemDefaults,
181
+ itemDefaults: lists.find(list => list.itemDefaults)?.itemDefaults,
188
182
  items: lists.map(list => list.items).flat(),
189
183
  };
190
184
  }
191
- });
185
+ };
192
186
  }
193
187
  exports.register = register;
194
188
  //# sourceMappingURL=complete.js.map
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
- export declare function register(context: LanguageServicePluginContext): (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
3
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CompletionItem, token: vscode.CancellationToken) => Promise<vscode.CompletionItem>;
@@ -1,30 +1,19 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.register = void 0;
12
3
  const transformer = require("../transformer");
13
4
  function register(context) {
14
- return (item) => __awaiter(this, void 0, void 0, function* () {
15
- var _a;
5
+ return async (item, token) => {
16
6
  const data = item.data;
17
7
  if (data) {
18
8
  const plugin = context.plugins[data.pluginId];
19
- if (!((_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.resolve))
9
+ if (!plugin.resolveCompletionItem)
20
10
  return item;
21
11
  item = Object.assign(item, data.original);
22
12
  if (data.map) {
23
13
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.map.embeddedDocumentUri)) {
24
- item = yield plugin.complete.resolve(item);
14
+ item = await plugin.resolveCompletionItem(item, token);
25
15
  item = transformer.asCompletionItem(item, embeddedRange => {
26
- var _a;
27
- let range = (_a = plugin.resolveEmbeddedRange) === null || _a === void 0 ? void 0 : _a.call(plugin, embeddedRange);
16
+ let range = plugin.resolveEmbeddedRange?.(embeddedRange);
28
17
  if (range)
29
18
  return range;
30
19
  return map.toSourceRange(embeddedRange);
@@ -32,7 +21,7 @@ function register(context) {
32
21
  }
33
22
  }
34
23
  else {
35
- item = yield plugin.complete.resolve(item);
24
+ item = await plugin.resolveCompletionItem(item, token);
36
25
  }
37
26
  }
38
27
  // TODO: monkey fix import ts file icon
@@ -40,7 +29,7 @@ function register(context) {
40
29
  item.detail = item.detail;
41
30
  }
42
31
  return item;
43
- });
32
+ };
44
33
  }
45
34
  exports.register = register;
46
35
  //# sourceMappingURL=completeResolve.js.map
@@ -1,4 +1,4 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
3
  import { FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core';
4
- export declare function register(context: LanguageServicePluginContext, api: 'findDefinition' | 'findTypeDefinition' | 'findImplementations', isValidMapping: (data: FileRangeCapabilities) => boolean, isValidMirrorPosition: (mirrorData: MirrorBehaviorCapabilities) => boolean): (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
4
+ export declare function register(context: LanguageServicePluginContext, apiName: 'provideDefinition' | 'provideTypeDefinition' | 'provideImplementation', isValidMapping: (data: FileRangeCapabilities) => boolean, isValidMirrorPosition: (mirrorData: MirrorBehaviorCapabilities) => boolean): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
@@ -1,63 +1,53 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
3
  const featureWorkers_1 = require("../utils/featureWorkers");
14
4
  const dedupe = require("../utils/dedupe");
15
- function register(context, api, isValidMapping, isValidMirrorPosition) {
16
- return (uri, position) => {
17
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, isValidMapping), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () {
5
+ const common_1 = require("../utils/common");
6
+ function register(context, apiName, isValidMapping, isValidMirrorPosition) {
7
+ return (uri, position, token) => {
8
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, isValidMapping), async (plugin, document, position) => {
9
+ if (token.isCancellationRequested)
10
+ return;
18
11
  const recursiveChecker = dedupe.createLocationSet();
19
12
  const result = [];
20
- yield withMirrors(document, position, undefined);
13
+ await withMirrors(document, position, undefined);
21
14
  return result;
22
- function withMirrors(document, position, originDefinition) {
23
- var _a, _b, _c, _d;
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const _api = api === 'findDefinition' ? (_a = plugin.definition) === null || _a === void 0 ? void 0 : _a.on :
26
- api === 'findTypeDefinition' ? (_b = plugin.definition) === null || _b === void 0 ? void 0 : _b.onType :
27
- api === 'findImplementations' ? plugin.findImplementations :
28
- undefined;
29
- if (!_api)
30
- return;
31
- if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
32
- return;
33
- recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
34
- const definitions = (_c = yield (_api === null || _api === void 0 ? void 0 : _api(document, position))) !== null && _c !== void 0 ? _c : [];
35
- for (const definition of definitions) {
36
- let foundMirrorPosition = false;
37
- recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } });
38
- const mirrorMap = (_d = context.documents.getMirrorMapByUri(definition.targetUri)) === null || _d === void 0 ? void 0 : _d[1];
39
- if (mirrorMap) {
40
- for (const mapped of mirrorMap.findMirrorPositions(definition.targetSelectionRange.start)) {
41
- if (!isValidMirrorPosition(mapped[1]))
42
- continue;
43
- if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } }))
44
- continue;
45
- foundMirrorPosition = true;
46
- yield withMirrors(mirrorMap.document, mapped[0], originDefinition !== null && originDefinition !== void 0 ? originDefinition : definition);
47
- }
15
+ async function withMirrors(document, position, originDefinition) {
16
+ const api = plugin[apiName];
17
+ if (!api)
18
+ return;
19
+ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
20
+ return;
21
+ recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
22
+ const definitions = await api?.(document, position, token) ?? [];
23
+ for (const definition of definitions) {
24
+ let foundMirrorPosition = false;
25
+ recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } });
26
+ const mirrorMap = context.documents.getMirrorMapByUri(definition.targetUri)?.[1];
27
+ if (mirrorMap) {
28
+ for (const mapped of mirrorMap.findMirrorPositions(definition.targetSelectionRange.start)) {
29
+ if (!isValidMirrorPosition(mapped[1]))
30
+ continue;
31
+ if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } }))
32
+ continue;
33
+ foundMirrorPosition = true;
34
+ await withMirrors(mirrorMap.document, mapped[0], originDefinition ?? definition);
35
+ }
36
+ }
37
+ if (!foundMirrorPosition) {
38
+ if (originDefinition) {
39
+ result.push({
40
+ ...definition,
41
+ originSelectionRange: originDefinition.originSelectionRange,
42
+ });
48
43
  }
49
- if (!foundMirrorPosition) {
50
- if (originDefinition) {
51
- result.push(Object.assign(Object.assign({}, definition), { originSelectionRange: originDefinition.originSelectionRange }));
52
- }
53
- else {
54
- result.push(definition);
55
- }
44
+ else {
45
+ result.push(definition);
56
46
  }
57
47
  }
58
- });
48
+ }
59
49
  }
60
- }), (data, sourceMap) => data.map(link => {
50
+ }, (data, sourceMap) => data.map(link => {
61
51
  if (link.originSelectionRange && sourceMap) {
62
52
  const originSelectionRange = toSourcePositionPreferSurroundedPosition(sourceMap, link.originSelectionRange, position);
63
53
  if (!originSelectionRange)
@@ -73,14 +63,14 @@ function register(context, api, isValidMapping, isValidMirrorPosition) {
73
63
  let targetRange = targetSourceMap.toSourceRange(link.targetRange);
74
64
  link.targetUri = targetSourceMap.sourceFileDocument.uri;
75
65
  // loose range mapping to for template slots, slot properties
76
- link.targetRange = targetRange !== null && targetRange !== void 0 ? targetRange : targetSelectionRange;
66
+ link.targetRange = targetRange ?? targetSelectionRange;
77
67
  link.targetSelectionRange = targetSelectionRange;
78
68
  }
79
69
  if (context.documents.hasVirtualFileByUri(link.targetUri) && !foundTargetSelectionRange) {
80
70
  return;
81
71
  }
82
72
  return link;
83
- }).filter(shared.notEmpty), arr => dedupe.withLocationLinks(arr.flat()));
73
+ }).filter(common_1.notEmpty), arr => dedupe.withLocationLinks(arr.flat()));
84
74
  };
85
75
  }
86
76
  exports.register = register;
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
- export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.DocumentHighlight[] | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<vscode.DocumentHighlight[] | undefined>;
@@ -1,63 +1,56 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
3
  const featureWorkers_1 = require("../utils/featureWorkers");
14
4
  const dedupe = require("../utils/dedupe");
5
+ const common_1 = require("../utils/common");
15
6
  function register(context) {
16
- return (uri, position) => {
7
+ return (uri, position, token) => {
17
8
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position,
18
9
  // note https://github.com/johnsoncodehk/volar/issues/2009
19
- data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () {
10
+ data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), async (plugin, document, position) => {
11
+ if (token.isCancellationRequested)
12
+ return;
20
13
  const recursiveChecker = dedupe.createLocationSet();
21
14
  const result = [];
22
- yield withMirrors(document, position);
15
+ await withMirrors(document, position);
23
16
  return result;
24
- function withMirrors(document, position) {
25
- var _a, _b;
26
- return __awaiter(this, void 0, void 0, function* () {
27
- if (!plugin.findDocumentHighlights)
28
- return;
29
- if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
30
- return;
31
- recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
32
- const references = (_a = yield plugin.findDocumentHighlights(document, position)) !== null && _a !== void 0 ? _a : [];
33
- for (const reference of references) {
34
- let foundMirrorPosition = false;
35
- recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
36
- const mirrorMap = (_b = context.documents.getMirrorMapByUri(document.uri)) === null || _b === void 0 ? void 0 : _b[1];
37
- if (mirrorMap) {
38
- for (const mapped of mirrorMap.findMirrorPositions(reference.range.start)) {
39
- if (!mapped[1].references)
40
- continue;
41
- if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } }))
42
- continue;
43
- foundMirrorPosition = true;
44
- yield withMirrors(mirrorMap.document, mapped[0]);
45
- }
46
- }
47
- if (!foundMirrorPosition) {
48
- result.push(reference);
17
+ async function withMirrors(document, position) {
18
+ if (!plugin.provideDocumentHighlights)
19
+ return;
20
+ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
21
+ return;
22
+ recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
23
+ const references = await plugin.provideDocumentHighlights(document, position, token) ?? [];
24
+ for (const reference of references) {
25
+ let foundMirrorPosition = false;
26
+ recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
27
+ const mirrorMap = context.documents.getMirrorMapByUri(document.uri)?.[1];
28
+ if (mirrorMap) {
29
+ for (const mapped of mirrorMap.findMirrorPositions(reference.range.start)) {
30
+ if (!mapped[1].references)
31
+ continue;
32
+ if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } }))
33
+ continue;
34
+ foundMirrorPosition = true;
35
+ await withMirrors(mirrorMap.document, mapped[0]);
49
36
  }
50
37
  }
51
- });
38
+ if (!foundMirrorPosition) {
39
+ result.push(reference);
40
+ }
41
+ }
52
42
  }
53
- }), (data, map) => data.map(highlisht => {
43
+ }, (data, map) => data.map(highlight => {
54
44
  if (!map)
55
- return highlisht;
56
- const range = map.toSourceRange(highlisht.range);
45
+ return highlight;
46
+ const range = map.toSourceRange(highlight.range);
57
47
  if (range) {
58
- return Object.assign(Object.assign({}, highlisht), { range });
48
+ return {
49
+ ...highlight,
50
+ range,
51
+ };
59
52
  }
60
- }).filter(shared.notEmpty), arr => arr.flat());
53
+ }).filter(common_1.notEmpty), arr => arr.flat());
61
54
  };
62
55
  }
63
56
  exports.register = register;
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
- export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.DocumentLink[]>;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.DocumentLink[]>;
@@ -1,27 +1,24 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
3
  const featureWorkers_1 = require("../utils/featureWorkers");
4
+ const common_1 = require("../utils/common");
14
5
  function register(context) {
15
- return (uri) => __awaiter(this, void 0, void 0, function* () {
16
- var _a;
17
- const pluginLinks = (_a = yield (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { var _a; return (_a = plugin.findDocumentLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => data.map(link => {
6
+ return async (uri, token) => {
7
+ const pluginLinks = await (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => {
8
+ if (token.isCancellationRequested)
9
+ return;
10
+ return plugin.provideLinks?.(document, token);
11
+ }, (data, map) => data.map(link => {
18
12
  if (!map)
19
13
  return link;
20
14
  const range = map.toSourceRange(link.range);
21
15
  if (range) {
22
- return Object.assign(Object.assign({}, link), { range });
16
+ return {
17
+ ...link,
18
+ range,
19
+ };
23
20
  }
24
- }).filter(shared.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : [];
21
+ }).filter(common_1.notEmpty), arr => arr.flat()) ?? [];
25
22
  const maps = context.documents.getMapsBySourceFileUri(uri);
26
23
  const fictitiousLinks = maps ? getFictitiousLinks(context.documents.getDocumentByUri(maps.snapshot, uri), maps.maps) : [];
27
24
  return [
@@ -47,7 +44,7 @@ function register(context) {
47
44
  }
48
45
  return result;
49
46
  }
50
- });
47
+ };
51
48
  }
52
49
  exports.register = register;
53
50
  //# sourceMappingURL=documentLinks.js.map
@@ -1,4 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import { SemanticToken } from '@volar/language-service';
3
2
  import type { LanguageServicePluginContext } from '../types';
4
- export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range | undefined, legend: vscode.SemanticTokensLegend, cancelToken: vscode.CancellationToken, reportProgress?: ((tokens: SemanticToken[]) => void) | undefined) => Promise<SemanticToken[] | undefined> | undefined;
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range | undefined, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken, reportProgress?: ((tokens: vscode.SemanticTokens) => void) | undefined) => Promise<vscode.SemanticTokens | undefined>;