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

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 (75) hide show
  1. package/out/baseLanguageService.d.ts +37 -41
  2. package/out/baseLanguageService.js +11 -8
  3. package/out/documentFeatures/colorPresentations.d.ts +1 -1
  4. package/out/documentFeatures/colorPresentations.js +9 -4
  5. package/out/documentFeatures/documentColors.d.ts +1 -1
  6. package/out/documentFeatures/documentColors.js +9 -4
  7. package/out/documentFeatures/documentSymbols.d.ts +1 -1
  8. package/out/documentFeatures/documentSymbols.js +8 -4
  9. package/out/documentFeatures/foldingRanges.d.ts +2 -2
  10. package/out/documentFeatures/foldingRanges.js +7 -2
  11. package/out/documentFeatures/format.d.ts +2 -2
  12. package/out/documentFeatures/format.js +12 -6
  13. package/out/documentFeatures/linkedEditingRanges.d.ts +1 -1
  14. package/out/documentFeatures/linkedEditingRanges.js +9 -4
  15. package/out/documentFeatures/selectionRanges.d.ts +1 -1
  16. package/out/documentFeatures/selectionRanges.js +9 -4
  17. package/out/documents.js +2 -2
  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 +7 -2
  22. package/out/languageFeatures/callHierarchy.d.ts +3 -3
  23. package/out/languageFeatures/callHierarchy.js +15 -13
  24. package/out/languageFeatures/codeActionResolve.d.ts +2 -2
  25. package/out/languageFeatures/codeActionResolve.js +7 -7
  26. package/out/languageFeatures/codeActions.d.ts +1 -1
  27. package/out/languageFeatures/codeActions.js +7 -6
  28. package/out/languageFeatures/codeLens.d.ts +1 -1
  29. package/out/languageFeatures/codeLens.js +8 -6
  30. package/out/languageFeatures/codeLensResolve.d.ts +1 -1
  31. package/out/languageFeatures/codeLensResolve.js +7 -7
  32. package/out/languageFeatures/complete.d.ts +1 -1
  33. package/out/languageFeatures/complete.js +29 -23
  34. package/out/languageFeatures/completeResolve.d.ts +1 -1
  35. package/out/languageFeatures/completeResolve.js +4 -5
  36. package/out/languageFeatures/definition.d.ts +1 -1
  37. package/out/languageFeatures/definition.js +11 -12
  38. package/out/languageFeatures/documentHighlights.d.ts +1 -1
  39. package/out/languageFeatures/documentHighlights.js +11 -9
  40. package/out/languageFeatures/documentLinks.d.ts +1 -1
  41. package/out/languageFeatures/documentLinks.js +9 -4
  42. package/out/languageFeatures/documentSemanticTokens.d.ts +1 -2
  43. package/out/languageFeatures/documentSemanticTokens.js +29 -8
  44. package/out/languageFeatures/fileReferences.d.ts +1 -1
  45. package/out/languageFeatures/fileReferences.js +6 -4
  46. package/out/languageFeatures/fileRename.d.ts +2 -1
  47. package/out/languageFeatures/fileRename.js +5 -3
  48. package/out/languageFeatures/hover.d.ts +1 -1
  49. package/out/languageFeatures/hover.js +7 -2
  50. package/out/languageFeatures/inlayHints.d.ts +1 -1
  51. package/out/languageFeatures/inlayHints.js +7 -6
  52. package/out/languageFeatures/references.d.ts +1 -1
  53. package/out/languageFeatures/references.js +5 -3
  54. package/out/languageFeatures/rename.d.ts +1 -1
  55. package/out/languageFeatures/rename.js +7 -5
  56. package/out/languageFeatures/renamePrepare.d.ts +1 -1
  57. package/out/languageFeatures/renamePrepare.js +7 -2
  58. package/out/languageFeatures/signatureHelp.d.ts +2 -2
  59. package/out/languageFeatures/signatureHelp.js +19 -2
  60. package/out/languageFeatures/validation.d.ts +1 -1
  61. package/out/languageFeatures/validation.js +21 -25
  62. package/out/languageFeatures/workspaceSymbols.d.ts +1 -1
  63. package/out/languageFeatures/workspaceSymbols.js +7 -5
  64. package/out/transformer/completionItem.js +2 -2
  65. package/out/transformer/documentSymbol.js +2 -2
  66. package/out/transformer/locationsLike.js +2 -2
  67. package/out/transformer/selectionRanges.js +2 -2
  68. package/out/types.d.ts +56 -80
  69. package/out/types.js +0 -1
  70. package/out/utils/SemanticTokensBuilder.d.ts +13 -0
  71. package/out/utils/SemanticTokensBuilder.js +42 -0
  72. package/out/utils/common.d.ts +3 -0
  73. package/out/utils/common.js +25 -1
  74. package/out/utils/featureWorkers.js +14 -22
  75. package/package.json +5 -6
@@ -9,16 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
12
  const path_1 = require("path");
13
+ const common_1 = require("../utils/common");
14
14
  const dedupe = require("../utils/dedupe");
15
15
  const featureWorkers_1 = require("../utils/featureWorkers");
16
16
  function register(context) {
17
17
  return {
18
- doPrepare(uri, position) {
18
+ doPrepare(uri, position, token) {
19
19
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, map) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _a;
21
- const items = yield ((_a = plugin.callHierarchy) === null || _a === void 0 ? void 0 : _a.prepare(document, position));
21
+ if (token.isCancellationRequested)
22
+ return;
23
+ const items = yield ((_a = plugin.provideCallHierarchyItems) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token));
22
24
  items === null || items === void 0 ? void 0 : items.forEach(item => {
23
25
  item.data = {
24
26
  uri,
@@ -34,20 +36,20 @@ function register(context) {
34
36
  return items;
35
37
  }), (data, sourceMap) => !sourceMap ? data : data
36
38
  .map(item => { var _a; return (_a = transformCallHierarchyItem(item, [])) === null || _a === void 0 ? void 0 : _a[0]; })
37
- .filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat()));
39
+ .filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat()));
38
40
  },
39
- getIncomingCalls(item) {
41
+ getIncomingCalls(item, token) {
40
42
  return __awaiter(this, void 0, void 0, function* () {
41
43
  const data = item.data;
42
44
  let incomingItems = [];
43
45
  if (data) {
44
46
  const plugin = context.plugins[data.pluginId];
45
- if (!plugin.callHierarchy)
47
+ if (!plugin.provideCallHierarchyIncomingCalls)
46
48
  return incomingItems;
47
49
  Object.assign(item, data.original);
48
50
  if (data.map) {
49
51
  if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
50
- const _calls = yield plugin.callHierarchy.onIncomingCalls(item);
52
+ const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token);
51
53
  for (const _call of _calls) {
52
54
  const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
53
55
  if (!calls)
@@ -60,7 +62,7 @@ function register(context) {
60
62
  }
61
63
  }
62
64
  else {
63
- const _calls = yield plugin.callHierarchy.onIncomingCalls(item);
65
+ const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token);
64
66
  for (const _call of _calls) {
65
67
  const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
66
68
  if (!calls)
@@ -75,18 +77,18 @@ function register(context) {
75
77
  return dedupe.withCallHierarchyIncomingCalls(incomingItems);
76
78
  });
77
79
  },
78
- getOutgoingCalls(item) {
80
+ getOutgoingCalls(item, token) {
79
81
  return __awaiter(this, void 0, void 0, function* () {
80
82
  const data = item.data;
81
83
  let items = [];
82
84
  if (data) {
83
85
  const plugin = context.plugins[data.pluginId];
84
- if (!plugin.callHierarchy)
86
+ if (!plugin.provideCallHierarchyOutgoingCalls)
85
87
  return items;
86
88
  Object.assign(item, data.original);
87
89
  if (data.map) {
88
90
  if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
89
- const _calls = yield plugin.callHierarchy.onOutgoingCalls(item);
91
+ const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token);
90
92
  for (const call of _calls) {
91
93
  const calls = transformCallHierarchyItem(call.to, call.fromRanges);
92
94
  if (!calls)
@@ -99,7 +101,7 @@ function register(context) {
99
101
  }
100
102
  }
101
103
  else {
102
- const _calls = yield plugin.callHierarchy.onOutgoingCalls(item);
104
+ const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token);
103
105
  for (const call of _calls) {
104
106
  const calls = transformCallHierarchyItem(call.to, call.fromRanges);
105
107
  if (!calls)
@@ -130,7 +132,7 @@ function register(context) {
130
132
  const selectionRange = map.toSourceRange(tsItem.selectionRange);
131
133
  if (!selectionRange)
132
134
  continue;
133
- const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(shared.notEmpty);
135
+ const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(common_1.notEmpty);
134
136
  const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri,
135
137
  // TS Bug: `range: range` not works
136
138
  range: {
@@ -1,3 +1,3 @@
1
- import type { CodeAction } from 'vscode-languageserver-protocol';
1
+ import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
- export declare function register(context: LanguageServicePluginContext): (item: CodeAction) => Promise<CodeAction>;
3
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeAction, token: vscode.CancellationToken) => Promise<vscode.CodeAction>;
@@ -11,26 +11,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const rename_1 = require("./rename");
13
13
  function register(context) {
14
- return (item) => __awaiter(this, void 0, void 0, function* () {
15
- var _a, _b, _c, _d, _e, _f, _g;
14
+ return (item, token) => __awaiter(this, void 0, void 0, function* () {
15
+ var _a, _b, _c, _d, _e, _f;
16
16
  const data = item.data;
17
17
  if ((data === null || data === void 0 ? void 0 : data.type) === 'plugin') {
18
18
  const plugin = context.plugins[data.pluginId];
19
- if (!((_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.resolve))
19
+ if (!plugin.resolveCodeAction)
20
20
  return item;
21
21
  Object.assign(item, data.original);
22
- item = yield plugin.codeAction.resolve(item);
22
+ item = yield plugin.resolveCodeAction(item, token);
23
23
  if (item.edit) {
24
24
  item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents, 'codeAction', { [data.uri]: data.version });
25
25
  }
26
26
  }
27
27
  if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') {
28
- const fixes = (_d = (_c = (_b = context.ruleFixes) === null || _b === void 0 ? void 0 : _b[data.documentUri]) === null || _c === void 0 ? void 0 : _c[data.ruleId]) === null || _d === void 0 ? void 0 : _d[data.ruleFixIndex];
28
+ const fixes = (_c = (_b = (_a = context.ruleFixes) === null || _a === void 0 ? void 0 : _a[data.documentUri]) === null || _b === void 0 ? void 0 : _b[data.ruleId]) === null || _c === void 0 ? void 0 : _c[data.ruleFixIndex];
29
29
  const fix = fixes === null || fixes === void 0 ? void 0 : fixes[1][data.index];
30
30
  if (fix) {
31
- let edit = (_f = yield ((_e = fix.getWorkspaceEdit) === null || _e === void 0 ? void 0 : _e.call(fix, fixes[0]))) !== null && _f !== void 0 ? _f : undefined;
31
+ let edit = (_e = yield ((_d = fix.getWorkspaceEdit) === null || _d === void 0 ? void 0 : _d.call(fix, fixes[0]))) !== null && _e !== void 0 ? _e : undefined;
32
32
  if (!edit) {
33
- const edits = yield ((_g = fix.getEdits) === null || _g === void 0 ? void 0 : _g.call(fix, fixes[0]));
33
+ const edits = yield ((_f = fix.getEdits) === null || _f === void 0 ? void 0 : _f.call(fix, fixes[0]));
34
34
  if (edits) {
35
35
  edit = {
36
36
  documentChanges: [{
@@ -17,4 +17,4 @@ export interface RuleCodeActionData {
17
17
  ruleFixIndex: number;
18
18
  index: number;
19
19
  }
20
- export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
20
+ export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext, token: vscode.CancellationToken) => Promise<vscode.CodeAction[] | undefined>;
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
12
  const transformer = require("../transformer");
14
13
  const vscode = require("vscode-languageserver-protocol");
15
14
  const common_1 = require("../utils/common");
@@ -17,7 +16,7 @@ const dedupe = require("../utils/dedupe");
17
16
  const featureWorkers_1 = require("../utils/featureWorkers");
18
17
  const rename_1 = require("./rename");
19
18
  function register(context) {
20
- return (uri, range, codeActionContext) => __awaiter(this, void 0, void 0, function* () {
19
+ return (uri, range, codeActionContext, token) => __awaiter(this, void 0, void 0, function* () {
21
20
  var _a, _b, _c, _d, _e;
22
21
  const sourceDocument = context.getTextDocument(uri);
23
22
  if (!sourceDocument)
@@ -55,7 +54,9 @@ function register(context) {
55
54
  }
56
55
  return [];
57
56
  }, (plugin, document, { range, codeActionContext }) => __awaiter(this, void 0, void 0, function* () {
58
- var _f, _g;
57
+ var _f;
58
+ if (token.isCancellationRequested)
59
+ return;
59
60
  const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
60
61
  const diagnostics = codeActionContext.diagnostics.filter(diagnostic => {
61
62
  const data = diagnostic.data;
@@ -68,11 +69,11 @@ function register(context) {
68
69
  const data = diagnostic.data;
69
70
  return Object.assign(Object.assign({}, diagnostic), data.original);
70
71
  });
71
- const codeActions = yield ((_g = (_f = plugin.codeAction) === null || _f === void 0 ? void 0 : _f.on) === null || _g === void 0 ? void 0 : _g.call(_f, document, range, Object.assign(Object.assign({}, codeActionContext), { diagnostics })));
72
+ const codeActions = yield ((_f = plugin.provideCodeActions) === null || _f === void 0 ? void 0 : _f.call(plugin, document, range, Object.assign(Object.assign({}, codeActionContext), { diagnostics }), token));
72
73
  codeActions === null || codeActions === void 0 ? void 0 : codeActions.forEach(codeAction => {
73
74
  codeAction.data = {
74
75
  uri,
75
- version: document.version,
76
+ version: sourceDocument.version,
76
77
  type: 'plugin',
77
78
  original: {
78
79
  data: codeAction.data,
@@ -95,7 +96,7 @@ function register(context) {
95
96
  else {
96
97
  return _codeAction;
97
98
  }
98
- }).filter(shared.notEmpty), arr => dedupe.withCodeAction(arr.flat()));
99
+ }).filter(common_1.notEmpty), arr => dedupe.withCodeAction(arr.flat()));
99
100
  const ruleActions = [];
100
101
  for (const diagnostic of codeActionContext.diagnostics) {
101
102
  const data = diagnostic.data;
@@ -12,4 +12,4 @@ export interface PluginReferencesCodeLensData {
12
12
  location: vscode.Location;
13
13
  pluginId: string;
14
14
  }
15
- export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.CodeLens[]>;
15
+ export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.CodeLens[]>;
@@ -9,16 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
12
  const featureWorkers_1 = require("../utils/featureWorkers");
14
13
  const vscode = require("vscode-languageserver-protocol");
14
+ const common_1 = require("../utils/common");
15
15
  function register(context) {
16
- return (uri) => __awaiter(this, void 0, void 0, function* () {
16
+ return (uri, token) => __awaiter(this, void 0, void 0, function* () {
17
17
  var _a, _b, _c;
18
18
  const referencesCodeLendsEnabled = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.codeLens.references'))) !== null && _b !== void 0 ? _b : true;
19
19
  return (_c = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () {
20
- var _d, _e, _f, _g;
21
- let codeLens = yield ((_e = (_d = plugin.codeLens) === null || _d === void 0 ? void 0 : _d.on) === null || _e === void 0 ? void 0 : _e.call(_d, document));
20
+ var _d, _e;
21
+ if (token.isCancellationRequested)
22
+ return;
23
+ let codeLens = yield ((_d = plugin.provideCodeLenses) === null || _d === void 0 ? void 0 : _d.call(plugin, document, token));
22
24
  const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
23
25
  codeLens === null || codeLens === void 0 ? void 0 : codeLens.forEach(codeLens => {
24
26
  codeLens.data = {
@@ -31,7 +33,7 @@ function register(context) {
31
33
  };
32
34
  });
33
35
  if (referencesCodeLendsEnabled) {
34
- const referencesCodeLensLocs = yield ((_g = (_f = plugin.referencesCodeLens) === null || _f === void 0 ? void 0 : _f.on) === null || _g === void 0 ? void 0 : _g.call(_f, document));
36
+ const referencesCodeLensLocs = yield ((_e = plugin.provideReferencesCodeLenses) === null || _e === void 0 ? void 0 : _e.call(plugin, document, token));
35
37
  const referencesCodeLens = referencesCodeLensLocs === null || referencesCodeLensLocs === void 0 ? void 0 : referencesCodeLensLocs.map(loc => vscode.CodeLens.create(loc.range, {
36
38
  kind: 'references',
37
39
  uri,
@@ -51,7 +53,7 @@ function register(context) {
51
53
  if (range) {
52
54
  return Object.assign(Object.assign({}, codeLens), { range });
53
55
  }
54
- }).filter(shared.notEmpty), arr => arr.flat())) !== null && _c !== void 0 ? _c : [];
56
+ }).filter(common_1.notEmpty), arr => arr.flat())) !== null && _c !== void 0 ? _c : [];
55
57
  });
56
58
  }
57
59
  exports.register = register;
@@ -2,4 +2,4 @@ import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
3
  export declare const showReferencesCommand: string;
4
4
  export type ShowReferencesCommandData = [string, vscode.Position, vscode.Location[]];
5
- export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
5
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens, token: vscode.CancellationToken) => Promise<vscode.CodeLens>;
@@ -13,23 +13,23 @@ const references = require("./references");
13
13
  exports.showReferencesCommand = `volar.${Math.random().toString(36).slice(2)}.show-references`;
14
14
  function register(context) {
15
15
  const findReferences = references.register(context);
16
- return (item) => __awaiter(this, void 0, void 0, function* () {
17
- var _a, _b, _c;
16
+ return (item, token) => __awaiter(this, void 0, void 0, function* () {
17
+ var _a;
18
18
  const data = item.data;
19
19
  if ((data === null || data === void 0 ? void 0 : data.kind) === 'normal') {
20
20
  const plugin = context.plugins[data.pluginId];
21
- if (!((_a = plugin.codeLens) === null || _a === void 0 ? void 0 : _a.resolve))
21
+ if (!plugin.resolveCodeLens)
22
22
  return item;
23
23
  Object.assign(item, data.original);
24
- item = yield plugin.codeLens.resolve(item);
24
+ item = yield plugin.resolveCodeLens(item, token);
25
25
  // item.range already transformed in codeLens request
26
26
  }
27
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 : [];
28
+ let references = (_a = yield findReferences(data.uri, item.range.start, token)) !== null && _a !== void 0 ? _a : [];
29
29
  const plugin = context.plugins[data.pluginId];
30
30
  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);
31
+ if (document && plugin.resolveReferencesCodeLens) {
32
+ references = yield plugin.resolveReferencesCodeLens(document, data.location, references, token);
33
33
  }
34
34
  item.command = {
35
35
  title: references.length === 1 ? '1 reference' : `${references.length} references`,
@@ -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>;
@@ -14,8 +14,11 @@ const vscode = require("vscode-languageserver-protocol");
14
14
  const definePlugin_1 = require("../utils/definePlugin");
15
15
  function register(context) {
16
16
  let cache;
17
- return (uri, position, completionContext) => __awaiter(this, void 0, void 0, function* () {
18
- var _a, _b, _c, _d, _e;
17
+ return (uri, position, completionContext, token) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b;
19
+ completionContext !== null && completionContext !== void 0 ? completionContext : (completionContext = {
20
+ triggerKind: vscode.CompletionTriggerKind.Invoked,
21
+ });
19
22
  let document;
20
23
  if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerKind) === vscode.CompletionTriggerKind.TriggerForIncompleteCompletions
21
24
  && (cache === null || cache === void 0 ? void 0 : cache.uri) === uri) {
@@ -25,9 +28,9 @@ function register(context) {
25
28
  if (cacheData.map) {
26
29
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(cacheData.map.embeddedDocumentUri)) {
27
30
  for (const mapped of map.toGeneratedPositions(position, data => !!data.completion)) {
28
- if (!((_a = cacheData.plugin.complete) === null || _a === void 0 ? void 0 : _a.on))
31
+ if (!cacheData.plugin.provideCompletionItems)
29
32
  continue;
30
- const embeddedCompletionList = yield cacheData.plugin.complete.on(map.virtualFileDocument, mapped, completionContext);
33
+ const embeddedCompletionList = yield cacheData.plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token);
31
34
  if (!embeddedCompletionList) {
32
35
  cacheData.list.isIncomplete = false;
33
36
  continue;
@@ -48,9 +51,9 @@ function register(context) {
48
51
  }
49
52
  }
50
53
  else if (document = context.getTextDocument(uri)) {
51
- if (!((_b = cacheData.plugin.complete) === null || _b === void 0 ? void 0 : _b.on))
54
+ if (!cacheData.plugin.provideCompletionItems)
52
55
  continue;
53
- const completionList = yield cacheData.plugin.complete.on(document, position, completionContext);
56
+ const completionList = yield cacheData.plugin.provideCompletionItems(document, position, completionContext, token);
54
57
  if (!completionList) {
55
58
  cacheData.list.isIncomplete = false;
56
59
  continue;
@@ -71,7 +74,7 @@ function register(context) {
71
74
  }
72
75
  }
73
76
  else {
74
- const rootFile = (_c = context.documents.getSourceByUri(uri)) === null || _c === void 0 ? void 0 : _c.root;
77
+ const rootFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root;
75
78
  cache = {
76
79
  uri,
77
80
  data: [],
@@ -81,7 +84,7 @@ function register(context) {
81
84
  let isFirstMapping = true;
82
85
  if (rootFile) {
83
86
  yield (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, (_, map) => __awaiter(this, void 0, void 0, function* () {
84
- var _f, _g;
87
+ var _c;
85
88
  const plugins = Object.values(context.plugins).sort(sortPlugins);
86
89
  let _data;
87
90
  for (const mapped of map.toGeneratedPositions(position, data => {
@@ -89,19 +92,21 @@ function register(context) {
89
92
  return !!data.completion;
90
93
  })) {
91
94
  for (const plugin of plugins) {
92
- if (!((_f = plugin.complete) === null || _f === void 0 ? void 0 : _f.on))
95
+ if (token.isCancellationRequested)
96
+ break;
97
+ if (!plugin.provideCompletionItems)
93
98
  continue;
94
- if (plugin.complete.isAdditional && !isFirstMapping)
99
+ if (plugin.isAdditionalCompletion && !isFirstMapping)
95
100
  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)))
101
+ if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_c = plugin.triggerCharacters) === null || _c === void 0 ? void 0 : _c.includes(completionContext.triggerCharacter)))
97
102
  continue;
98
- const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.complete.isAdditional;
103
+ const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.isAdditionalCompletion;
99
104
  if (cache.mainCompletion && (!isAdditional || (cache === null || cache === void 0 ? void 0 : cache.mainCompletion.documentUri) !== map.virtualFileDocument.uri))
100
105
  continue;
101
106
  // 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)))
107
+ if (plugin.isAdditionalCompletion && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin)))
103
108
  continue;
104
- const embeddedCompletionList = yield plugin.complete.on(map.virtualFileDocument, mapped, completionContext);
109
+ const embeddedCompletionList = yield plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token);
105
110
  if (!embeddedCompletionList || !embeddedCompletionList.items.length)
106
111
  continue;
107
112
  if (typeof (_data === null || _data === void 0 ? void 0 : _data.completion) === 'object' && _data.completion.autoImportOnly) {
@@ -138,21 +143,23 @@ function register(context) {
138
143
  if (document = context.getTextDocument(uri)) {
139
144
  const plugins = Object.values(context.plugins).sort(sortPlugins);
140
145
  for (const plugin of plugins) {
141
- if (!((_d = plugin.complete) === null || _d === void 0 ? void 0 : _d.on))
146
+ if (token.isCancellationRequested)
147
+ break;
148
+ if (!plugin.provideCompletionItems)
142
149
  continue;
143
- if (plugin.complete.isAdditional && !isFirstMapping)
150
+ if (plugin.isAdditionalCompletion && !isFirstMapping)
144
151
  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)))
152
+ if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_b = plugin.triggerCharacters) === null || _b === void 0 ? void 0 : _b.includes(completionContext.triggerCharacter)))
146
153
  continue;
147
- if (cache.mainCompletion && (!plugin.complete.isAdditional || cache.mainCompletion.documentUri !== document.uri))
154
+ if (cache.mainCompletion && (!plugin.isAdditionalCompletion || cache.mainCompletion.documentUri !== document.uri))
148
155
  continue;
149
156
  // 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)))
157
+ if (plugin.isAdditionalCompletion && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin)))
151
158
  continue;
152
- const completionList = yield plugin.complete.on(document, position, completionContext);
159
+ const completionList = yield plugin.provideCompletionItems(document, position, completionContext, token);
153
160
  if (!completionList || !completionList.items.length)
154
161
  continue;
155
- if (!plugin.complete.isAdditional) {
162
+ if (!plugin.isAdditionalCompletion) {
156
163
  cache.mainCompletion = { documentUri: document.uri };
157
164
  }
158
165
  completionList.items.forEach(item => {
@@ -177,8 +184,7 @@ function register(context) {
177
184
  }
178
185
  return combineCompletionList(cache.data.map(cacheData => cacheData.list));
179
186
  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);
187
+ return (b.isAdditionalCompletion ? -1 : 1) - (a.isAdditionalCompletion ? -1 : 1);
182
188
  }
183
189
  function combineCompletionList(lists) {
184
190
  var _a;
@@ -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>;
@@ -11,17 +11,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const transformer = require("../transformer");
13
13
  function register(context) {
14
- return (item) => __awaiter(this, void 0, void 0, function* () {
15
- var _a;
14
+ return (item, token) => __awaiter(this, void 0, void 0, function* () {
16
15
  const data = item.data;
17
16
  if (data) {
18
17
  const plugin = context.plugins[data.pluginId];
19
- if (!((_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.resolve))
18
+ if (!plugin.resolveCompletionItem)
20
19
  return item;
21
20
  item = Object.assign(item, data.original);
22
21
  if (data.map) {
23
22
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.map.embeddedDocumentUri)) {
24
- item = yield plugin.complete.resolve(item);
23
+ item = yield plugin.resolveCompletionItem(item, token);
25
24
  item = transformer.asCompletionItem(item, embeddedRange => {
26
25
  var _a;
27
26
  let range = (_a = plugin.resolveEmbeddedRange) === null || _a === void 0 ? void 0 : _a.call(plugin, embeddedRange);
@@ -32,7 +31,7 @@ function register(context) {
32
31
  }
33
32
  }
34
33
  else {
35
- item = yield plugin.complete.resolve(item);
34
+ item = yield plugin.resolveCompletionItem(item, token);
36
35
  }
37
36
  }
38
37
  // TODO: monkey fix import ts file icon
@@ -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>;
@@ -9,33 +9,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
12
  const featureWorkers_1 = require("../utils/featureWorkers");
14
13
  const dedupe = require("../utils/dedupe");
15
- function register(context, api, isValidMapping, isValidMirrorPosition) {
16
- return (uri, position) => {
14
+ const common_1 = require("../utils/common");
15
+ function register(context, apiName, isValidMapping, isValidMirrorPosition) {
16
+ return (uri, position, token) => {
17
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* () {
18
+ if (token.isCancellationRequested)
19
+ return;
18
20
  const recursiveChecker = dedupe.createLocationSet();
19
21
  const result = [];
20
22
  yield withMirrors(document, position, undefined);
21
23
  return result;
22
24
  function withMirrors(document, position, originDefinition) {
23
- var _a, _b, _c, _d;
25
+ var _a, _b;
24
26
  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)
27
+ const api = plugin[apiName];
28
+ if (!api)
30
29
  return;
31
30
  if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
32
31
  return;
33
32
  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 : [];
33
+ const definitions = (_a = yield (api === null || api === void 0 ? void 0 : api(document, position, token))) !== null && _a !== void 0 ? _a : [];
35
34
  for (const definition of definitions) {
36
35
  let foundMirrorPosition = false;
37
36
  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];
37
+ const mirrorMap = (_b = context.documents.getMirrorMapByUri(definition.targetUri)) === null || _b === void 0 ? void 0 : _b[1];
39
38
  if (mirrorMap) {
40
39
  for (const mapped of mirrorMap.findMirrorPositions(definition.targetSelectionRange.start)) {
41
40
  if (!isValidMirrorPosition(mapped[1]))
@@ -80,7 +79,7 @@ function register(context, api, isValidMapping, isValidMirrorPosition) {
80
79
  return;
81
80
  }
82
81
  return link;
83
- }).filter(shared.notEmpty), arr => dedupe.withLocationLinks(arr.flat()));
82
+ }).filter(common_1.notEmpty), arr => dedupe.withLocationLinks(arr.flat()));
84
83
  };
85
84
  }
86
85
  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>;
@@ -9,14 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
12
  const featureWorkers_1 = require("../utils/featureWorkers");
14
13
  const dedupe = require("../utils/dedupe");
14
+ const common_1 = require("../utils/common");
15
15
  function register(context) {
16
- return (uri, position) => {
16
+ return (uri, position, token) => {
17
17
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position,
18
18
  // note https://github.com/johnsoncodehk/volar/issues/2009
19
19
  data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () {
20
+ if (token.isCancellationRequested)
21
+ return;
20
22
  const recursiveChecker = dedupe.createLocationSet();
21
23
  const result = [];
22
24
  yield withMirrors(document, position);
@@ -24,12 +26,12 @@ function register(context) {
24
26
  function withMirrors(document, position) {
25
27
  var _a, _b;
26
28
  return __awaiter(this, void 0, void 0, function* () {
27
- if (!plugin.findDocumentHighlights)
29
+ if (!plugin.provideDocumentHighlights)
28
30
  return;
29
31
  if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
30
32
  return;
31
33
  recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
32
- const references = (_a = yield plugin.findDocumentHighlights(document, position)) !== null && _a !== void 0 ? _a : [];
34
+ const references = (_a = yield plugin.provideDocumentHighlights(document, position, token)) !== null && _a !== void 0 ? _a : [];
33
35
  for (const reference of references) {
34
36
  let foundMirrorPosition = false;
35
37
  recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
@@ -50,14 +52,14 @@ function register(context) {
50
52
  }
51
53
  });
52
54
  }
53
- }), (data, map) => data.map(highlisht => {
55
+ }), (data, map) => data.map(highlight => {
54
56
  if (!map)
55
- return highlisht;
56
- const range = map.toSourceRange(highlisht.range);
57
+ return highlight;
58
+ const range = map.toSourceRange(highlight.range);
57
59
  if (range) {
58
- return Object.assign(Object.assign({}, highlisht), { range });
60
+ return Object.assign(Object.assign({}, highlight), { range });
59
61
  }
60
- }).filter(shared.notEmpty), arr => arr.flat());
62
+ }).filter(common_1.notEmpty), arr => arr.flat());
61
63
  };
62
64
  }
63
65
  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[]>;
@@ -9,19 +9,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
- const shared = require("@volar/shared");
13
12
  const featureWorkers_1 = require("../utils/featureWorkers");
13
+ const common_1 = require("../utils/common");
14
14
  function register(context) {
15
- return (uri) => __awaiter(this, void 0, void 0, function* () {
15
+ return (uri, token) => __awaiter(this, void 0, void 0, function* () {
16
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 => {
17
+ const pluginLinks = (_a = yield (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => {
18
+ var _a;
19
+ if (token.isCancellationRequested)
20
+ return;
21
+ return (_a = plugin.provideLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token);
22
+ }, (data, map) => data.map(link => {
18
23
  if (!map)
19
24
  return link;
20
25
  const range = map.toSourceRange(link.range);
21
26
  if (range) {
22
27
  return Object.assign(Object.assign({}, link), { range });
23
28
  }
24
- }).filter(shared.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : [];
29
+ }).filter(common_1.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : [];
25
30
  const maps = context.documents.getMapsBySourceFileUri(uri);
26
31
  const fictitiousLinks = maps ? getFictitiousLinks(context.documents.getDocumentByUri(maps.snapshot, uri), maps.maps) : [];
27
32
  return [