@volar/language-service 1.4.0-alpha.0 → 1.4.0-alpha.10

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 (95) hide show
  1. package/out/baseLanguageService.d.ts +88 -37
  2. package/out/baseLanguageService.js +114 -21
  3. package/out/documentFeatures/colorPresentations.d.ts +1 -1
  4. package/out/documentFeatures/colorPresentations.js +4 -3
  5. package/out/documentFeatures/documentColors.d.ts +1 -1
  6. package/out/documentFeatures/documentColors.js +3 -3
  7. package/out/documentFeatures/documentSymbols.d.ts +1 -1
  8. package/out/documentFeatures/documentSymbols.js +7 -16
  9. package/out/documentFeatures/foldingRanges.d.ts +2 -2
  10. package/out/documentFeatures/foldingRanges.js +4 -3
  11. package/out/documentFeatures/format.d.ts +1 -1
  12. package/out/documentFeatures/format.js +38 -46
  13. package/out/documentFeatures/linkedEditingRanges.d.ts +1 -1
  14. package/out/documentFeatures/linkedEditingRanges.js +4 -3
  15. package/out/documentFeatures/selectionRanges.d.ts +1 -1
  16. package/out/documentFeatures/selectionRanges.js +31 -14
  17. package/out/documents.d.ts +1 -1
  18. package/out/documents.js +32 -18
  19. package/out/index.d.ts +0 -1
  20. package/out/index.js +2 -3
  21. package/out/languageFeatures/autoInsert.d.ts +1 -1
  22. package/out/languageFeatures/autoInsert.js +10 -7
  23. package/out/languageFeatures/callHierarchy.d.ts +3 -5
  24. package/out/languageFeatures/callHierarchy.js +68 -77
  25. package/out/languageFeatures/codeActionResolve.d.ts +2 -2
  26. package/out/languageFeatures/codeActionResolve.js +11 -19
  27. package/out/languageFeatures/codeActions.d.ts +1 -1
  28. package/out/languageFeatures/codeActions.js +31 -38
  29. package/out/languageFeatures/codeLens.d.ts +2 -2
  30. package/out/languageFeatures/codeLens.js +18 -25
  31. package/out/languageFeatures/codeLensResolve copy.d.ts +3 -0
  32. package/out/languageFeatures/codeLensResolve copy.js +31 -0
  33. package/out/languageFeatures/codeLensResolve.d.ts +1 -3
  34. package/out/languageFeatures/codeLensResolve.js +12 -25
  35. package/out/languageFeatures/complete.d.ts +2 -4
  36. package/out/languageFeatures/complete.js +27 -47
  37. package/out/languageFeatures/completeResolve.d.ts +1 -1
  38. package/out/languageFeatures/completeResolve.js +9 -17
  39. package/out/languageFeatures/definition.d.ts +1 -1
  40. package/out/languageFeatures/definition.js +39 -46
  41. package/out/languageFeatures/documentHighlights.d.ts +1 -1
  42. package/out/languageFeatures/documentHighlights.js +33 -40
  43. package/out/languageFeatures/documentLinkResolve copy.d.ts +3 -0
  44. package/out/languageFeatures/documentLinkResolve copy.js +19 -0
  45. package/out/languageFeatures/documentLinkResolve.d.ts +3 -0
  46. package/out/languageFeatures/documentLinkResolve.js +19 -0
  47. package/out/languageFeatures/documentLinks copy.d.ts +8 -0
  48. package/out/languageFeatures/documentLinks copy.js +62 -0
  49. package/out/languageFeatures/documentLinks.d.ts +6 -1
  50. package/out/languageFeatures/documentLinks.js +22 -18
  51. package/out/languageFeatures/documentSemanticTokens.d.ts +1 -1
  52. package/out/languageFeatures/documentSemanticTokens.js +8 -17
  53. package/out/languageFeatures/fileReferences.d.ts +1 -1
  54. package/out/languageFeatures/fileReferences.js +7 -15
  55. package/out/languageFeatures/fileRename.d.ts +1 -2
  56. package/out/languageFeatures/fileRename.js +8 -16
  57. package/out/languageFeatures/hover.d.ts +1 -1
  58. package/out/languageFeatures/hover.js +7 -10
  59. package/out/languageFeatures/inlayHintResolve.d.ts +3 -0
  60. package/out/languageFeatures/inlayHintResolve.js +19 -0
  61. package/out/languageFeatures/inlayHints.d.ts +6 -1
  62. package/out/languageFeatures/inlayHints.js +25 -20
  63. package/out/languageFeatures/references.d.ts +1 -1
  64. package/out/languageFeatures/references.js +30 -40
  65. package/out/languageFeatures/rename.d.ts +1 -1
  66. package/out/languageFeatures/rename.js +61 -74
  67. package/out/languageFeatures/renamePrepare.d.ts +1 -1
  68. package/out/languageFeatures/renamePrepare.js +3 -3
  69. package/out/languageFeatures/signatureHelp.d.ts +1 -1
  70. package/out/languageFeatures/signatureHelp.js +9 -10
  71. package/out/languageFeatures/validation.d.ts +1 -1
  72. package/out/languageFeatures/validation.js +141 -168
  73. package/out/languageFeatures/workspaceSymbols.d.ts +1 -1
  74. package/out/languageFeatures/workspaceSymbols.js +5 -13
  75. package/out/transformer/completionItem.js +9 -3
  76. package/out/transformer/completionList.js +7 -3
  77. package/out/transformer/documentSymbol.js +9 -3
  78. package/out/transformer/foldingRanges.js +3 -3
  79. package/out/transformer/hover.js +6 -2
  80. package/out/transformer/index.js +1 -0
  81. package/out/transformer/locationLike.js +5 -1
  82. package/out/transformer/locationsLike.js +1 -0
  83. package/out/transformer/selectionRange.js +1 -0
  84. package/out/transformer/selectionRanges.js +1 -0
  85. package/out/transformer/textEdit.js +21 -5
  86. package/out/transformer/workspaceSymbol.js +5 -1
  87. package/out/types.d.ts +24 -8
  88. package/out/types.js +1 -0
  89. package/out/utils/SemanticTokensBuilder.js +1 -0
  90. package/out/utils/common.d.ts +2 -1
  91. package/out/utils/common.js +7 -5
  92. package/out/utils/dedupe.js +1 -0
  93. package/out/utils/definePlugin.js +12 -23
  94. package/out/utils/featureWorkers.js +127 -146
  95. package/package.json +5 -5
@@ -1,68 +1,44 @@
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
- };
1
+ "use strict";
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  exports.register = void 0;
12
4
  const path_1 = require("path");
5
+ const vscode = require("vscode-languageserver-protocol");
13
6
  const common_1 = require("../utils/common");
14
7
  const dedupe = require("../utils/dedupe");
15
8
  const featureWorkers_1 = require("../utils/featureWorkers");
16
9
  function register(context) {
17
10
  return {
18
- doPrepare(uri, position, token) {
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
- var _a;
11
+ doPrepare(uri, position, token = vscode.CancellationToken.None) {
12
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), async (plugin, document, position, map) => {
21
13
  if (token.isCancellationRequested)
22
14
  return;
23
- const items = yield ((_a = plugin.provideCallHierarchyItems) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token));
24
- items === null || items === void 0 ? void 0 : items.forEach(item => {
15
+ const items = await plugin.provideCallHierarchyItems?.(document, position, token);
16
+ items?.forEach(item => {
25
17
  item.data = {
26
18
  uri,
27
19
  original: {
28
20
  data: item.data,
29
21
  },
30
22
  pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
31
- map: map ? {
32
- embeddedDocumentUri: map.virtualFileDocument.uri,
33
- } : undefined,
23
+ virtualDocumentUri: map?.virtualFileDocument.uri,
34
24
  };
35
25
  });
36
26
  return items;
37
- }), (data, sourceMap) => !sourceMap ? data : data
38
- .map(item => { var _a; return (_a = transformCallHierarchyItem(item, [])) === null || _a === void 0 ? void 0 : _a[0]; })
27
+ }, (data, sourceMap) => !sourceMap ? data : data
28
+ .map(item => transformCallHierarchyItem(item, [])?.[0])
39
29
  .filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat()));
40
30
  },
41
- getIncomingCalls(item, token) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const data = item.data;
44
- let incomingItems = [];
45
- if (data) {
46
- const plugin = context.plugins[data.pluginId];
47
- if (!plugin.provideCallHierarchyIncomingCalls)
48
- return incomingItems;
49
- Object.assign(item, data.original);
50
- if (data.map) {
51
- if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
52
- const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token);
53
- for (const _call of _calls) {
54
- const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
55
- if (!calls)
56
- continue;
57
- incomingItems.push({
58
- from: calls[0],
59
- fromRanges: calls[1],
60
- });
61
- }
62
- }
63
- }
64
- else {
65
- const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token);
31
+ async getIncomingCalls(item, token) {
32
+ const data = item.data;
33
+ let incomingItems = [];
34
+ if (data) {
35
+ const plugin = context.plugins[data.pluginId];
36
+ if (!plugin.provideCallHierarchyIncomingCalls)
37
+ return incomingItems;
38
+ Object.assign(item, data.original);
39
+ if (data.virtualDocumentUri) {
40
+ if (context.documents.isVirtualFileUri(data.virtualDocumentUri)) {
41
+ const _calls = await plugin.provideCallHierarchyIncomingCalls(item, token);
66
42
  for (const _call of _calls) {
67
43
  const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
68
44
  if (!calls)
@@ -74,34 +50,32 @@ function register(context) {
74
50
  }
75
51
  }
76
52
  }
77
- return dedupe.withCallHierarchyIncomingCalls(incomingItems);
78
- });
79
- },
80
- getOutgoingCalls(item, token) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- const data = item.data;
83
- let items = [];
84
- if (data) {
85
- const plugin = context.plugins[data.pluginId];
86
- if (!plugin.provideCallHierarchyOutgoingCalls)
87
- return items;
88
- Object.assign(item, data.original);
89
- if (data.map) {
90
- if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
91
- const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token);
92
- for (const call of _calls) {
93
- const calls = transformCallHierarchyItem(call.to, call.fromRanges);
94
- if (!calls)
95
- continue;
96
- items.push({
97
- to: calls[0],
98
- fromRanges: calls[1],
99
- });
100
- }
101
- }
53
+ else {
54
+ const _calls = await plugin.provideCallHierarchyIncomingCalls(item, token);
55
+ for (const _call of _calls) {
56
+ const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
57
+ if (!calls)
58
+ continue;
59
+ incomingItems.push({
60
+ from: calls[0],
61
+ fromRanges: calls[1],
62
+ });
102
63
  }
103
- else {
104
- const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token);
64
+ }
65
+ }
66
+ return dedupe.withCallHierarchyIncomingCalls(incomingItems);
67
+ },
68
+ async getOutgoingCalls(item, token) {
69
+ const data = item.data;
70
+ let items = [];
71
+ if (data) {
72
+ const plugin = context.plugins[data.pluginId];
73
+ if (!plugin.provideCallHierarchyOutgoingCalls)
74
+ return items;
75
+ Object.assign(item, data.original);
76
+ if (data.virtualDocumentUri) {
77
+ if (context.documents.isVirtualFileUri(data.virtualDocumentUri)) {
78
+ const _calls = await plugin.provideCallHierarchyOutgoingCalls(item, token);
105
79
  for (const call of _calls) {
106
80
  const calls = transformCallHierarchyItem(call.to, call.fromRanges);
107
81
  if (!calls)
@@ -113,12 +87,24 @@ function register(context) {
113
87
  }
114
88
  }
115
89
  }
116
- return dedupe.withCallHierarchyOutgoingCalls(items);
117
- });
90
+ else {
91
+ const _calls = await plugin.provideCallHierarchyOutgoingCalls(item, token);
92
+ for (const call of _calls) {
93
+ const calls = transformCallHierarchyItem(call.to, call.fromRanges);
94
+ if (!calls)
95
+ continue;
96
+ items.push({
97
+ to: calls[0],
98
+ fromRanges: calls[1],
99
+ });
100
+ }
101
+ }
102
+ }
103
+ return dedupe.withCallHierarchyOutgoingCalls(items);
118
104
  },
119
105
  };
120
106
  function transformCallHierarchyItem(tsItem, tsRanges) {
121
- if (!context.documents.hasVirtualFileByUri(tsItem.uri))
107
+ if (!context.documents.isVirtualFileUri(tsItem.uri))
122
108
  return [tsItem, tsRanges];
123
109
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(tsItem.uri)) {
124
110
  let range = map.toSourceRange(tsItem.range);
@@ -133,15 +119,20 @@ function register(context) {
133
119
  if (!selectionRange)
134
120
  continue;
135
121
  const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(common_1.notEmpty);
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,
122
+ const vueItem = {
123
+ ...tsItem,
124
+ name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name,
125
+ uri: map.sourceFileDocument.uri,
137
126
  // TS Bug: `range: range` not works
138
127
  range: {
139
128
  start: range.start,
140
129
  end: range.end,
141
- }, selectionRange: {
130
+ },
131
+ selectionRange: {
142
132
  start: selectionRange.start,
143
133
  end: selectionRange.end,
144
- } });
134
+ },
135
+ };
145
136
  selectionRange.end;
146
137
  return [vueItem, vueRanges];
147
138
  }
@@ -1,3 +1,3 @@
1
- import type * as vscode from 'vscode-languageserver-protocol';
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
- export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeAction, token: vscode.CancellationToken) => Promise<vscode.CodeAction>;
3
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeAction, token?: vscode.CancellationToken) => Promise<vscode.CodeAction>;
@@ -1,36 +1,28 @@
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
- };
1
+ "use strict";
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  exports.register = void 0;
4
+ const vscode = require("vscode-languageserver-protocol");
12
5
  const rename_1 = require("./rename");
13
6
  function register(context) {
14
- return (item, token) => __awaiter(this, void 0, void 0, function* () {
15
- var _a, _b, _c, _d, _e, _f;
7
+ return async (item, token = vscode.CancellationToken.None) => {
16
8
  const data = item.data;
17
- if ((data === null || data === void 0 ? void 0 : data.type) === 'plugin') {
9
+ if (data?.type === 'plugin') {
18
10
  const plugin = context.plugins[data.pluginId];
19
11
  if (!plugin.resolveCodeAction)
20
12
  return item;
21
13
  Object.assign(item, data.original);
22
- item = yield plugin.resolveCodeAction(item, token);
14
+ item = await plugin.resolveCodeAction(item, token);
23
15
  if (item.edit) {
24
16
  item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents, 'codeAction', { [data.uri]: data.version });
25
17
  }
26
18
  }
27
- if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') {
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
- const fix = fixes === null || fixes === void 0 ? void 0 : fixes[1][data.index];
19
+ if (data?.type === 'rule') {
20
+ const fixes = context.ruleFixes?.[data.documentUri]?.[data.ruleId]?.[data.ruleFixIndex];
21
+ const fix = fixes?.[1][data.index];
30
22
  if (fix) {
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;
23
+ let edit = await fix.getWorkspaceEdit?.(fixes[0]) ?? undefined;
32
24
  if (!edit) {
33
- const edits = yield ((_f = fix.getEdits) === null || _f === void 0 ? void 0 : _f.call(fix, fixes[0]));
25
+ const edits = await fix.getEdits?.(fixes[0]);
34
26
  if (edits) {
35
27
  edit = {
36
28
  documentChanges: [{
@@ -49,7 +41,7 @@ function register(context) {
49
41
  }
50
42
  }
51
43
  return item;
52
- });
44
+ };
53
45
  }
54
46
  exports.register = register;
55
47
  //# sourceMappingURL=codeActionResolve.js.map
@@ -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, token: vscode.CancellationToken) => 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>;
@@ -1,12 +1,4 @@
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
- };
1
+ "use strict";
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  exports.register = void 0;
12
4
  const transformer = require("../transformer");
@@ -16,8 +8,7 @@ const dedupe = require("../utils/dedupe");
16
8
  const featureWorkers_1 = require("../utils/featureWorkers");
17
9
  const rename_1 = require("./rename");
18
10
  function register(context) {
19
- return (uri, range, codeActionContext, token) => __awaiter(this, void 0, void 0, function* () {
20
- var _a, _b, _c, _d, _e;
11
+ return async (uri, range, codeActionContext, token = vscode.CancellationToken.None) => {
21
12
  const sourceDocument = context.getTextDocument(uri);
22
13
  if (!sourceDocument)
23
14
  return;
@@ -25,8 +16,7 @@ function register(context) {
25
16
  start: sourceDocument.offsetAt(range.start),
26
17
  end: sourceDocument.offsetAt(range.end),
27
18
  };
28
- const pluginActions = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (_arg, map, file) => {
29
- var _a, _b;
19
+ const pluginActions = await (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (_arg, map, file) => {
30
20
  if (!file.capabilities.codeAction)
31
21
  return [];
32
22
  const _codeActionContext = {
@@ -38,8 +28,8 @@ function register(context) {
38
28
  for (const mapping of map.map.mappings) {
39
29
  const overlapRange = (0, common_1.getOverlapRange)(offsetRange.start, offsetRange.end, mapping.sourceRange[0], mapping.sourceRange[1]);
40
30
  if (overlapRange) {
41
- const start = (_a = map.map.toGeneratedOffset(overlapRange.start)) === null || _a === void 0 ? void 0 : _a[0];
42
- const end = (_b = map.map.toGeneratedOffset(overlapRange.end)) === null || _b === void 0 ? void 0 : _b[0];
31
+ const start = map.map.toGeneratedOffset(overlapRange.start)?.[0];
32
+ const end = map.map.toGeneratedOffset(overlapRange.end)?.[0];
43
33
  if (start !== undefined && end !== undefined) {
44
34
  minStart = minStart === undefined ? start : Math.min(start, minStart);
45
35
  maxEnd = maxEnd === undefined ? end : Math.max(end, maxEnd);
@@ -53,8 +43,7 @@ function register(context) {
53
43
  }];
54
44
  }
55
45
  return [];
56
- }, (plugin, document, { range, codeActionContext }) => __awaiter(this, void 0, void 0, function* () {
57
- var _f;
46
+ }, async (plugin, document, { range, codeActionContext }) => {
58
47
  if (token.isCancellationRequested)
59
48
  return;
60
49
  const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
@@ -64,13 +53,19 @@ function register(context) {
64
53
  // console.warn('[volar/plugin-api] diagnostic version mismatch', data.version, sourceDocument.version);
65
54
  return false;
66
55
  }
67
- return (data === null || data === void 0 ? void 0 : data.type) === 'plugin' && (data === null || data === void 0 ? void 0 : data.pluginOrRuleId) === pluginId;
56
+ return data?.type === 'plugin' && data?.pluginOrRuleId === pluginId;
68
57
  }).map(diagnostic => {
69
58
  const data = diagnostic.data;
70
- return Object.assign(Object.assign({}, diagnostic), data.original);
59
+ return {
60
+ ...diagnostic,
61
+ ...data.original,
62
+ };
71
63
  });
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));
73
- codeActions === null || codeActions === void 0 ? void 0 : codeActions.forEach(codeAction => {
64
+ const codeActions = await plugin.provideCodeActions?.(document, range, {
65
+ ...codeActionContext,
66
+ diagnostics,
67
+ }, token);
68
+ codeActions?.forEach(codeAction => {
74
69
  codeAction.data = {
75
70
  uri,
76
71
  version: sourceDocument.version,
@@ -83,19 +78,17 @@ function register(context) {
83
78
  };
84
79
  });
85
80
  return codeActions;
86
- }), (_codeActions, sourceMap) => _codeActions.map(_codeAction => {
87
- if (!sourceMap)
88
- return _codeAction;
89
- if (_codeAction.edit) {
90
- const edit = (0, rename_1.embeddedEditToSourceEdit)(_codeAction.edit, context.documents, 'codeAction');
91
- if (edit) {
92
- _codeAction.edit = edit;
93
- return _codeAction;
81
+ }, (actions, map) => actions.map(action => {
82
+ if (!map)
83
+ return action;
84
+ if (action.edit) {
85
+ const edit = (0, rename_1.embeddedEditToSourceEdit)(action.edit, context.documents, 'codeAction');
86
+ if (!edit) {
87
+ return;
94
88
  }
89
+ action.edit = edit;
95
90
  }
96
- else {
97
- return _codeAction;
98
- }
91
+ return action;
99
92
  }).filter(common_1.notEmpty), arr => dedupe.withCodeAction(arr.flat()));
100
93
  const ruleActions = [];
101
94
  for (const diagnostic of codeActionContext.diagnostics) {
@@ -104,8 +97,8 @@ function register(context) {
104
97
  // console.warn('[volar/rules-api] diagnostic version mismatch', data.version, sourceDocument.version);
105
98
  continue;
106
99
  }
107
- if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') {
108
- const fixes = (_c = (_b = (_a = context.ruleFixes) === null || _a === void 0 ? void 0 : _a[data.documentUri]) === null || _b === void 0 ? void 0 : _b[data.pluginOrRuleId]) === null || _c === void 0 ? void 0 : _c[data.ruleFixIndex];
100
+ if (data?.type === 'rule') {
101
+ const fixes = context.ruleFixes?.[data.documentUri]?.[data.pluginOrRuleId]?.[data.ruleFixIndex];
109
102
  if (fixes) {
110
103
  for (let i = 0; i < fixes[1].length; i++) {
111
104
  const fix = fixes[1][i];
@@ -114,7 +107,7 @@ function register(context) {
114
107
  matchKinds.push(undefined);
115
108
  }
116
109
  else {
117
- for (const kind of (_d = fix.kinds) !== null && _d !== void 0 ? _d : ['quickfix']) {
110
+ for (const kind of fix.kinds ?? ['quickfix']) {
118
111
  const matchOnly = matchOnlyKind(codeActionContext.only, kind);
119
112
  if (matchOnly) {
120
113
  matchKinds.push(matchOnly);
@@ -123,7 +116,7 @@ function register(context) {
123
116
  }
124
117
  for (const matchKind of matchKinds) {
125
118
  const action = {
126
- title: (_e = fix.title) !== null && _e !== void 0 ? _e : `Fix: ${diagnostic.message}`,
119
+ title: fix.title ?? `Fix: ${diagnostic.message}`,
127
120
  kind: matchKind,
128
121
  diagnostics: [diagnostic],
129
122
  data: {
@@ -144,10 +137,10 @@ function register(context) {
144
137
  }
145
138
  }
146
139
  return [
147
- ...pluginActions !== null && pluginActions !== void 0 ? pluginActions : [],
140
+ ...pluginActions ?? [],
148
141
  ...ruleActions,
149
142
  ];
150
- });
143
+ };
151
144
  }
152
145
  exports.register = register;
153
146
  function matchOnlyKind(only, kind) {
@@ -9,7 +9,7 @@ export interface PluginCodeLensData {
9
9
  export interface PluginReferencesCodeLensData {
10
10
  kind: 'references';
11
11
  uri: string;
12
- location: vscode.Location;
12
+ range: vscode.Range;
13
13
  pluginId: string;
14
14
  }
15
- export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.CodeLens[]>;
15
+ export declare function register(context: LanguageServicePluginContext): (uri: string, token?: vscode.CancellationToken) => Promise<vscode.CodeLens[]>;
@@ -1,28 +1,18 @@
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
- };
1
+ "use strict";
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  exports.register = void 0;
12
4
  const featureWorkers_1 = require("../utils/featureWorkers");
13
5
  const vscode = require("vscode-languageserver-protocol");
14
6
  const common_1 = require("../utils/common");
15
7
  function register(context) {
16
- return (uri, token) => __awaiter(this, void 0, void 0, function* () {
17
- var _a, _b, _c;
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
- 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;
8
+ return async (uri, token = vscode.CancellationToken.None) => {
9
+ const referencesCodeLendsEnabled = await context.configurationHost?.getConfiguration('volar.codeLens.references') ?? true;
10
+ return await (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], async (plugin, document) => {
21
11
  if (token.isCancellationRequested)
22
12
  return;
23
- let codeLens = yield ((_d = plugin.provideCodeLenses) === null || _d === void 0 ? void 0 : _d.call(plugin, document, token));
13
+ let codeLens = await plugin.provideCodeLenses?.(document, token);
24
14
  const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
25
- codeLens === null || codeLens === void 0 ? void 0 : codeLens.forEach(codeLens => {
15
+ codeLens?.forEach(codeLens => {
26
16
  codeLens.data = {
27
17
  kind: 'normal',
28
18
  uri,
@@ -33,28 +23,31 @@ function register(context) {
33
23
  };
34
24
  });
35
25
  if (referencesCodeLendsEnabled) {
36
- const referencesCodeLensLocs = yield ((_e = plugin.provideReferencesCodeLenses) === null || _e === void 0 ? void 0 : _e.call(plugin, document, token));
37
- const referencesCodeLens = referencesCodeLensLocs === null || referencesCodeLensLocs === void 0 ? void 0 : referencesCodeLensLocs.map(loc => vscode.CodeLens.create(loc.range, {
26
+ const ranges = await plugin.provideReferencesCodeLensRanges?.(document, token);
27
+ const referencesCodeLens = ranges?.map(range => vscode.CodeLens.create(range, {
38
28
  kind: 'references',
39
29
  uri,
40
- location: loc,
30
+ range,
41
31
  pluginId,
42
32
  }));
43
33
  codeLens = [
44
- ...codeLens !== null && codeLens !== void 0 ? codeLens : [],
45
- ...referencesCodeLens !== null && referencesCodeLens !== void 0 ? referencesCodeLens : [],
34
+ ...codeLens ?? [],
35
+ ...referencesCodeLens ?? [],
46
36
  ];
47
37
  }
48
38
  return codeLens;
49
- }), (data, map) => data.map(codeLens => {
39
+ }, (data, map) => data.map(codeLens => {
50
40
  if (!map)
51
41
  return codeLens;
52
42
  const range = map.toSourceRange(codeLens.range);
53
43
  if (range) {
54
- return Object.assign(Object.assign({}, codeLens), { range });
44
+ return {
45
+ ...codeLens,
46
+ range,
47
+ };
55
48
  }
56
- }).filter(common_1.notEmpty), arr => arr.flat())) !== null && _c !== void 0 ? _c : [];
57
- });
49
+ }).filter(common_1.notEmpty), arr => arr.flat()) ?? [];
50
+ };
58
51
  }
59
52
  exports.register = register;
60
53
  //# sourceMappingURL=codeLens.js.map
@@ -0,0 +1,3 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens, token?: vscode.CancellationToken) => Promise<vscode.CodeLens>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.register = void 0;
4
+ const vscode = require("vscode-languageserver-protocol");
5
+ const references = require("./references");
6
+ function register(context) {
7
+ const findReferences = references.register(context);
8
+ return async (item, token = vscode.CancellationToken.None) => {
9
+ const data = item.data;
10
+ if (data?.kind === 'normal') {
11
+ const plugin = context.plugins[data.pluginId];
12
+ if (!plugin.resolveCodeLens)
13
+ return item;
14
+ Object.assign(item, data.original);
15
+ item = await plugin.resolveCodeLens(item, token);
16
+ // item.range already transformed in codeLens request
17
+ }
18
+ if (data?.kind === 'references') {
19
+ let references = await findReferences(data.uri, item.range.start, token) ?? [];
20
+ const plugin = context.plugins[data.pluginId];
21
+ const document = context.getTextDocument(data.uri);
22
+ if (document && plugin.resolveReferencesCodeLensLocations) {
23
+ references = await plugin.resolveReferencesCodeLensLocations(document, data.range, references, token);
24
+ }
25
+ item.command = context.commands.createShowReferencesCommand(data.uri, data.range.start, references);
26
+ }
27
+ return item;
28
+ };
29
+ }
30
+ exports.register = register;
31
+ //# sourceMappingURL=codeLensResolve%20copy.js.map
@@ -1,5 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServicePluginContext } from '../types';
3
- export declare const showReferencesCommand: string;
4
- export type ShowReferencesCommandData = [string, vscode.Position, vscode.Location[]];
5
- export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens, token: vscode.CancellationToken) => Promise<vscode.CodeLens>;
3
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens, token?: vscode.CancellationToken) => Promise<vscode.CodeLens>;
@@ -1,44 +1,31 @@
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
- };
1
+ "use strict";
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.register = exports.showReferencesCommand = void 0;
3
+ exports.register = void 0;
4
+ const vscode = require("vscode-languageserver-protocol");
12
5
  const references = require("./references");
13
- exports.showReferencesCommand = `volar.${Math.random().toString(36).slice(2)}.show-references`;
14
6
  function register(context) {
15
7
  const findReferences = references.register(context);
16
- return (item, token) => __awaiter(this, void 0, void 0, function* () {
17
- var _a;
8
+ return async (item, token = vscode.CancellationToken.None) => {
18
9
  const data = item.data;
19
- if ((data === null || data === void 0 ? void 0 : data.kind) === 'normal') {
10
+ if (data?.kind === 'normal') {
20
11
  const plugin = context.plugins[data.pluginId];
21
12
  if (!plugin.resolveCodeLens)
22
13
  return item;
23
14
  Object.assign(item, data.original);
24
- item = yield plugin.resolveCodeLens(item, token);
15
+ item = await plugin.resolveCodeLens(item, token);
25
16
  // item.range already transformed in codeLens request
26
17
  }
27
- if ((data === null || data === void 0 ? void 0 : data.kind) === 'references') {
28
- let references = (_a = yield findReferences(data.uri, item.range.start, token)) !== null && _a !== void 0 ? _a : [];
18
+ if (data?.kind === 'references') {
19
+ let references = await findReferences(data.uri, item.range.start, token) ?? [];
29
20
  const plugin = context.plugins[data.pluginId];
30
21
  const document = context.getTextDocument(data.uri);
31
- if (document && plugin.resolveReferencesCodeLens) {
32
- references = yield plugin.resolveReferencesCodeLens(document, data.location, references, token);
22
+ if (document && plugin.resolveReferencesCodeLensLocations) {
23
+ references = await plugin.resolveReferencesCodeLensLocations(document, data.range, references, token);
33
24
  }
34
- item.command = {
35
- title: references.length === 1 ? '1 reference' : `${references.length} references`,
36
- command: exports.showReferencesCommand,
37
- arguments: [data.uri, data.location.range.start, references],
38
- };
25
+ item.command = context.commands.createShowReferencesCommand(data.uri, data.range.start, references);
39
26
  }
40
27
  return item;
41
- });
28
+ };
42
29
  }
43
30
  exports.register = register;
44
31
  //# sourceMappingURL=codeLensResolve.js.map
@@ -4,8 +4,6 @@ export interface PluginCompletionData {
4
4
  uri: string;
5
5
  original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
6
6
  pluginId: string;
7
- map: {
8
- embeddedDocumentUri: string;
9
- } | undefined;
7
+ virtualDocumentUri: string | undefined;
10
8
  }
11
- export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext: vscode.CompletionContext | undefined, token: vscode.CancellationToken) => Promise<vscode.CompletionList>;
9
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext, token?: vscode.CancellationToken) => Promise<vscode.CompletionList>;