@volar/language-service 1.0.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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/out/baseDocumentService.d.ts +35 -0
  3. package/out/baseDocumentService.js +100 -0
  4. package/out/baseLanguageService.d.ts +55 -0
  5. package/out/baseLanguageService.js +114 -0
  6. package/out/documentFeatures/autoInsert.d.ts +5 -0
  7. package/out/documentFeatures/autoInsert.js +25 -0
  8. package/out/documentFeatures/colorPresentations.d.ts +4 -0
  9. package/out/documentFeatures/colorPresentations.js +35 -0
  10. package/out/documentFeatures/documentColors.d.ts +4 -0
  11. package/out/documentFeatures/documentColors.js +21 -0
  12. package/out/documentFeatures/documentSymbols.d.ts +4 -0
  13. package/out/documentFeatures/documentSymbols.js +21 -0
  14. package/out/documentFeatures/foldingRanges.d.ts +4 -0
  15. package/out/documentFeatures/foldingRanges.js +16 -0
  16. package/out/documentFeatures/format.d.ts +7 -0
  17. package/out/documentFeatures/format.js +242 -0
  18. package/out/documentFeatures/linkedEditingRanges.d.ts +4 -0
  19. package/out/documentFeatures/linkedEditingRanges.js +23 -0
  20. package/out/documentFeatures/selectionRanges.d.ts +4 -0
  21. package/out/documentFeatures/selectionRanges.js +19 -0
  22. package/out/documents.d.ts +106 -0
  23. package/out/documents.js +227 -0
  24. package/out/index.d.ts +8 -0
  25. package/out/index.js +27 -0
  26. package/out/languageFeatures/autoInsert.d.ts +4 -0
  27. package/out/languageFeatures/autoInsert.js +35 -0
  28. package/out/languageFeatures/callHierarchy.d.ts +15 -0
  29. package/out/languageFeatures/callHierarchy.js +148 -0
  30. package/out/languageFeatures/codeActionResolve.d.ts +3 -0
  31. package/out/languageFeatures/codeActionResolve.js +45 -0
  32. package/out/languageFeatures/codeActions.d.ts +11 -0
  33. package/out/languageFeatures/codeActions.js +89 -0
  34. package/out/languageFeatures/codeLens.d.ts +8 -0
  35. package/out/languageFeatures/codeLens.js +45 -0
  36. package/out/languageFeatures/codeLensResolve.d.ts +3 -0
  37. package/out/languageFeatures/codeLensResolve.js +30 -0
  38. package/out/languageFeatures/complete.d.ts +14 -0
  39. package/out/languageFeatures/complete.js +181 -0
  40. package/out/languageFeatures/completeResolve.d.ts +3 -0
  41. package/out/languageFeatures/completeResolve.js +60 -0
  42. package/out/languageFeatures/definition.d.ts +4 -0
  43. package/out/languageFeatures/definition.js +85 -0
  44. package/out/languageFeatures/documentHighlights.d.ts +3 -0
  45. package/out/languageFeatures/documentHighlights.js +65 -0
  46. package/out/languageFeatures/documentLinks.d.ts +3 -0
  47. package/out/languageFeatures/documentLinks.js +53 -0
  48. package/out/languageFeatures/documentSemanticTokens.d.ts +4 -0
  49. package/out/languageFeatures/documentSemanticTokens.js +59 -0
  50. package/out/languageFeatures/executeCommand.d.ts +11 -0
  51. package/out/languageFeatures/executeCommand.js +31 -0
  52. package/out/languageFeatures/fileReferences.d.ts +4 -0
  53. package/out/languageFeatures/fileReferences.js +37 -0
  54. package/out/languageFeatures/fileRename.d.ts +3 -0
  55. package/out/languageFeatures/fileRename.js +36 -0
  56. package/out/languageFeatures/hover.d.ts +3 -0
  57. package/out/languageFeatures/hover.js +48 -0
  58. package/out/languageFeatures/inlayHints.d.ts +3 -0
  59. package/out/languageFeatures/inlayHints.js +65 -0
  60. package/out/languageFeatures/references.d.ts +3 -0
  61. package/out/languageFeatures/references.js +68 -0
  62. package/out/languageFeatures/rename.d.ts +19 -0
  63. package/out/languageFeatures/rename.js +226 -0
  64. package/out/languageFeatures/renamePrepare.d.ts +3 -0
  65. package/out/languageFeatures/renamePrepare.js +41 -0
  66. package/out/languageFeatures/signatureHelp.d.ts +3 -0
  67. package/out/languageFeatures/signatureHelp.js +14 -0
  68. package/out/languageFeatures/validation.d.ts +7 -0
  69. package/out/languageFeatures/validation.js +237 -0
  70. package/out/languageFeatures/workspaceSymbols.d.ts +3 -0
  71. package/out/languageFeatures/workspaceSymbols.js +34 -0
  72. package/out/plugin.d.ts +93 -0
  73. package/out/plugin.js +3 -0
  74. package/out/types.d.ts +43 -0
  75. package/out/types.js +4 -0
  76. package/out/utils/dedupe.d.ts +15 -0
  77. package/out/utils/dedupe.js +132 -0
  78. package/out/utils/definePlugin.d.ts +2 -0
  79. package/out/utils/definePlugin.js +27 -0
  80. package/out/utils/featureWorkers.d.ts +7 -0
  81. package/out/utils/featureWorkers.js +120 -0
  82. package/out/utils/singleFileTypeScriptService.d.ts +4 -0
  83. package/out/utils/singleFileTypeScriptService.js +30 -0
  84. package/package.json +32 -0
@@ -0,0 +1,4 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ import { EmbeddedLanguageServicePlugin } from '@volar/language-service';
4
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, autoInsertContext: Parameters<NonNullable<EmbeddedLanguageServicePlugin['doAutoInsert']>>[2]) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>;
@@ -0,0 +1,35 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.register = void 0;
3
+ const featureWorkers_1 = require("../utils/featureWorkers");
4
+ function register(context) {
5
+ return (uri, position, autoInsertContext) => {
6
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, autoInsertContext }, function* (arg, sourceMap) {
7
+ var _a, _b, _c;
8
+ const position = (_a = sourceMap.getMappedRange(arg.position, arg.position, data => !!data.completion)) === null || _a === void 0 ? void 0 : _a[0].start;
9
+ const rangeOffset = (_b = sourceMap.getMappedRange(arg.autoInsertContext.lastChange.rangeOffset, arg.autoInsertContext.lastChange.rangeOffset, data => !!data.completion)) === null || _b === void 0 ? void 0 : _b[0].start;
10
+ const range = (_c = sourceMap.getMappedRange(arg.autoInsertContext.lastChange.range.start, arg.autoInsertContext.lastChange.range.end, data => !!data.completion)) === null || _c === void 0 ? void 0 : _c[0];
11
+ if (position && rangeOffset !== undefined && range) {
12
+ yield {
13
+ position,
14
+ autoInsertContext: {
15
+ lastChange: Object.assign(Object.assign({}, arg.autoInsertContext.lastChange), { rangeOffset,
16
+ range }),
17
+ },
18
+ };
19
+ }
20
+ }, (plugin, document, arg) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext); }, (data, sourceMap) => {
21
+ var _a;
22
+ if (!sourceMap)
23
+ return data;
24
+ if (typeof data === 'string')
25
+ return data;
26
+ const range = (_a = sourceMap.getSourceRange(data.range.start, data.range.end)) === null || _a === void 0 ? void 0 : _a[0];
27
+ if (range) {
28
+ data.range = range;
29
+ return data;
30
+ }
31
+ });
32
+ };
33
+ }
34
+ exports.register = register;
35
+ //# sourceMappingURL=autoInsert.js.map
@@ -0,0 +1,15 @@
1
+ import type * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export interface PluginCallHierarchyData {
4
+ uri: string;
5
+ originalItem: vscode.CallHierarchyItem;
6
+ pluginId: number;
7
+ sourceMap: {
8
+ embeddedDocumentUri: string;
9
+ } | undefined;
10
+ }
11
+ export declare function register(context: LanguageServiceRuntimeContext): {
12
+ doPrepare(uri: string, position: vscode.Position): Promise<vscode.CallHierarchyItem[] | undefined>;
13
+ getIncomingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyIncomingCall[]>;
14
+ getOutgoingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyOutgoingCall[]>;
15
+ };
@@ -0,0 +1,148 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.register = void 0;
12
+ const shared = require("@volar/shared");
13
+ const upath = require("upath");
14
+ const dedupe = require("../utils/dedupe");
15
+ const featureWorkers_1 = require("../utils/featureWorkers");
16
+ function register(context) {
17
+ return {
18
+ doPrepare(uri, position) {
19
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
20
+ for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.references)) {
21
+ yield mappedRange.start;
22
+ }
23
+ }, (plugin, document, position, sourceMap) => __awaiter(this, void 0, void 0, function* () {
24
+ var _a;
25
+ const items = yield ((_a = plugin.callHierarchy) === null || _a === void 0 ? void 0 : _a.prepare(document, position));
26
+ return items === null || items === void 0 ? void 0 : items.map(item => {
27
+ const data = {
28
+ uri,
29
+ originalItem: item,
30
+ pluginId: context.plugins.indexOf(plugin),
31
+ sourceMap: sourceMap ? {
32
+ embeddedDocumentUri: sourceMap.mappedDocument.uri,
33
+ } : undefined,
34
+ };
35
+ return Object.assign(Object.assign({}, item), { data: data });
36
+ });
37
+ }), (data, sourceMap) => !sourceMap ? data : data
38
+ .map(item => { var _a; return (_a = transformCallHierarchyItem(item, [])) === null || _a === void 0 ? void 0 : _a[0]; })
39
+ .filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat()));
40
+ },
41
+ getIncomingCalls(item) {
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)
48
+ return incomingItems;
49
+ if (!plugin.callHierarchy)
50
+ return incomingItems;
51
+ const originalItem = data.originalItem;
52
+ if (data.sourceMap) {
53
+ const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(data.sourceMap.embeddedDocumentUri);
54
+ if (sourceMap) {
55
+ const _calls = yield plugin.callHierarchy.onIncomingCalls(originalItem);
56
+ for (const _call of _calls) {
57
+ const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
58
+ if (!calls)
59
+ continue;
60
+ incomingItems.push({
61
+ from: calls[0],
62
+ fromRanges: calls[1],
63
+ });
64
+ }
65
+ }
66
+ }
67
+ else {
68
+ const _calls = yield plugin.callHierarchy.onIncomingCalls(item);
69
+ for (const _call of _calls) {
70
+ const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
71
+ if (!calls)
72
+ continue;
73
+ incomingItems.push({
74
+ from: calls[0],
75
+ fromRanges: calls[1],
76
+ });
77
+ }
78
+ }
79
+ }
80
+ return dedupe.withCallHierarchyIncomingCalls(incomingItems);
81
+ });
82
+ },
83
+ getOutgoingCalls(item) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const data = item.data;
86
+ let items = [];
87
+ if (data) {
88
+ const plugin = context.plugins[data.pluginId];
89
+ if (!plugin)
90
+ return items;
91
+ if (!plugin.callHierarchy)
92
+ return items;
93
+ const originalItem = data.originalItem;
94
+ if (data.sourceMap) {
95
+ const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(data.sourceMap.embeddedDocumentUri);
96
+ if (sourceMap) {
97
+ const _calls = yield plugin.callHierarchy.onOutgoingCalls(originalItem);
98
+ for (const call of _calls) {
99
+ const calls = transformCallHierarchyItem(call.to, call.fromRanges);
100
+ if (!calls)
101
+ continue;
102
+ items.push({
103
+ to: calls[0],
104
+ fromRanges: calls[1],
105
+ });
106
+ }
107
+ }
108
+ }
109
+ else {
110
+ const _calls = yield plugin.callHierarchy.onOutgoingCalls(item);
111
+ for (const call of _calls) {
112
+ const calls = transformCallHierarchyItem(call.to, call.fromRanges);
113
+ if (!calls)
114
+ continue;
115
+ items.push({
116
+ to: calls[0],
117
+ fromRanges: calls[1],
118
+ });
119
+ }
120
+ }
121
+ }
122
+ return dedupe.withCallHierarchyOutgoingCalls(items);
123
+ });
124
+ },
125
+ };
126
+ function transformCallHierarchyItem(tsItem, tsRanges) {
127
+ var _a, _b;
128
+ const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(tsItem.uri);
129
+ if (!sourceMap)
130
+ return [tsItem, tsRanges]; // not virtual file
131
+ let vueRange = (_a = sourceMap.getSourceRange(tsItem.range.start, tsItem.range.end)) === null || _a === void 0 ? void 0 : _a[0];
132
+ if (!vueRange) {
133
+ // TODO: <script> range
134
+ vueRange = {
135
+ start: sourceMap.sourceDocument.positionAt(0),
136
+ end: sourceMap.sourceDocument.positionAt(sourceMap.sourceDocument.getText().length),
137
+ };
138
+ }
139
+ const vueSelectionRange = (_b = sourceMap.getSourceRange(tsItem.selectionRange.start, tsItem.selectionRange.end)) === null || _b === void 0 ? void 0 : _b[0];
140
+ if (!vueSelectionRange)
141
+ return;
142
+ const vueRanges = tsRanges.map(tsRange => { var _a; return (_a = sourceMap.getSourceRange(tsRange.start, tsRange.end)) === null || _a === void 0 ? void 0 : _a[0]; }).filter(shared.notEmpty);
143
+ const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === upath.basename(shared.getPathOfUri(sourceMap.mappedDocument.uri)) ? upath.basename(shared.getPathOfUri(sourceMap.sourceDocument.uri)) : tsItem.name, uri: sourceMap.sourceDocument.uri, range: vueRange, selectionRange: vueSelectionRange });
144
+ return [vueItem, vueRanges];
145
+ }
146
+ }
147
+ exports.register = register;
148
+ //# sourceMappingURL=callHierarchy.js.map
@@ -0,0 +1,3 @@
1
+ import type { CodeAction } from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export declare function register(context: LanguageServiceRuntimeContext): (item: CodeAction) => Promise<CodeAction>;
@@ -0,0 +1,45 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.register = void 0;
12
+ const rename_1 = require("./rename");
13
+ function register(context) {
14
+ return (item) => __awaiter(this, void 0, void 0, function* () {
15
+ var _a, _b, _c;
16
+ const data = item.data;
17
+ if (data) {
18
+ const plugin = context.plugins[data.pluginId];
19
+ if (!plugin)
20
+ return item;
21
+ if (!((_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.resolve))
22
+ return item;
23
+ const originalItem = data.originalItem;
24
+ if (data.sourceMap) {
25
+ const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(data.sourceMap.embeddedDocumentUri);
26
+ if (sourceMap) {
27
+ const resolvedItem = yield ((_b = plugin.codeAction) === null || _b === void 0 ? void 0 : _b.resolve(originalItem));
28
+ if (resolvedItem.edit) {
29
+ const edit = (0, rename_1.embeddedEditToSourceEdit)(resolvedItem.edit, context.documents);
30
+ if (edit) {
31
+ resolvedItem.edit = edit;
32
+ return resolvedItem;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ else {
38
+ return yield ((_c = plugin.codeAction) === null || _c === void 0 ? void 0 : _c.resolve(originalItem));
39
+ }
40
+ }
41
+ return item;
42
+ });
43
+ }
44
+ exports.register = register;
45
+ //# sourceMappingURL=codeActionResolve.js.map
@@ -0,0 +1,11 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export interface PluginCodeActionData {
4
+ uri: string;
5
+ originalItem: vscode.CodeAction;
6
+ pluginId: number;
7
+ sourceMap: {
8
+ embeddedDocumentUri: string;
9
+ } | undefined;
10
+ }
11
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
@@ -0,0 +1,89 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.register = void 0;
12
+ const shared = require("@volar/shared");
13
+ const transforms_1 = require("@volar/transforms");
14
+ const vscode = require("vscode-languageserver-protocol");
15
+ const dedupe = require("../utils/dedupe");
16
+ const featureWorkers_1 = require("../utils/featureWorkers");
17
+ const rename_1 = require("./rename");
18
+ function register(context) {
19
+ return (uri, range, codeActionContext) => __awaiter(this, void 0, void 0, function* () {
20
+ const document = context.getTextDocument(uri);
21
+ if (!document)
22
+ return;
23
+ const offsetRange = {
24
+ start: document.offsetAt(range.start),
25
+ end: document.offsetAt(range.end),
26
+ };
27
+ let codeActions = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (arg, sourceMap) => {
28
+ var _a;
29
+ if (!sourceMap.embeddedFile.capabilities.codeActions)
30
+ return [];
31
+ const _codeActionContext = {
32
+ diagnostics: (0, transforms_1.transformLocations)(codeActionContext.diagnostics, range => { var _a; return (_a = sourceMap.getMappedRange(range.start, range.end)) === null || _a === void 0 ? void 0 : _a[0]; }),
33
+ only: codeActionContext.only,
34
+ };
35
+ let minStart;
36
+ let maxEnd;
37
+ for (const mapping of sourceMap.base.mappings) {
38
+ const overlapRange = shared.getOverlapRange2(offsetRange, mapping.sourceRange);
39
+ if (overlapRange) {
40
+ const embeddedRange = (_a = sourceMap.getMappedRange(overlapRange.start, overlapRange.end)) === null || _a === void 0 ? void 0 : _a[0];
41
+ if (embeddedRange) {
42
+ minStart = minStart === undefined ? embeddedRange.start : Math.min(embeddedRange.start, minStart);
43
+ maxEnd = maxEnd === undefined ? embeddedRange.end : Math.max(embeddedRange.end, maxEnd);
44
+ }
45
+ }
46
+ }
47
+ if (minStart !== undefined && maxEnd !== undefined) {
48
+ return [{
49
+ range: vscode.Range.create(sourceMap.mappedDocument.positionAt(minStart), sourceMap.mappedDocument.positionAt(maxEnd)),
50
+ codeActionContext: _codeActionContext,
51
+ }];
52
+ }
53
+ return [];
54
+ }, (plugin, document, arg, sourceMap) => __awaiter(this, void 0, void 0, function* () {
55
+ var _a, _b;
56
+ const codeActions = yield ((_b = (_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, arg.range, arg.codeActionContext));
57
+ return codeActions === null || codeActions === void 0 ? void 0 : codeActions.map(_codeAction => {
58
+ const data = {
59
+ uri,
60
+ originalItem: _codeAction,
61
+ pluginId: context.plugins.indexOf(plugin),
62
+ sourceMap: sourceMap ? {
63
+ embeddedDocumentUri: sourceMap.mappedDocument.uri,
64
+ } : undefined,
65
+ };
66
+ return Object.assign(Object.assign({}, _codeAction), { data: data });
67
+ });
68
+ }), (_codeActions, sourceMap) => _codeActions.map(_codeAction => {
69
+ if (!sourceMap)
70
+ return _codeAction;
71
+ if (_codeAction.edit) {
72
+ const edit = (0, rename_1.embeddedEditToSourceEdit)(_codeAction.edit, context.documents);
73
+ if (edit) {
74
+ _codeAction.edit = edit;
75
+ return _codeAction;
76
+ }
77
+ }
78
+ else {
79
+ return _codeAction;
80
+ }
81
+ }).filter(shared.notEmpty), arr => arr.flat());
82
+ if (codeActions) {
83
+ codeActions = codeActions.filter(codeAction => codeAction.title.indexOf('__VLS_') === -1);
84
+ return dedupe.withCodeAction(codeActions);
85
+ }
86
+ });
87
+ }
88
+ exports.register = register;
89
+ //# sourceMappingURL=codeActions.js.map
@@ -0,0 +1,8 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export interface PluginCodeLensData {
4
+ uri: string;
5
+ originalItem: vscode.CodeLens;
6
+ pluginId: number;
7
+ }
8
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<vscode.CodeLens[]>;
@@ -0,0 +1,45 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.register = void 0;
12
+ const shared = require("@volar/shared");
13
+ const featureWorkers_1 = require("../utils/featureWorkers");
14
+ const executeCommand_1 = require("./executeCommand");
15
+ function register(context) {
16
+ return (uri) => __awaiter(this, void 0, void 0, function* () {
17
+ var _a;
18
+ return (_a = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg, sourceMap) => [arg], (plugin, document, arg, sourceMap) => __awaiter(this, void 0, void 0, function* () {
19
+ var _b, _c;
20
+ const codeLens = yield ((_c = (_b = plugin.codeLens) === null || _b === void 0 ? void 0 : _b.on) === null || _c === void 0 ? void 0 : _c.call(_b, document));
21
+ if (codeLens) {
22
+ return codeLens.map(item => {
23
+ const data = {
24
+ uri,
25
+ originalItem: item,
26
+ pluginId: context.plugins.indexOf(plugin),
27
+ };
28
+ const commandArgs = item.command ? [uri, context.plugins.indexOf(plugin), item.command] : undefined;
29
+ const codeLens = Object.assign(Object.assign({}, item), { command: item.command && commandArgs ? Object.assign(Object.assign({}, item.command), { command: executeCommand_1.executePluginCommand, arguments: commandArgs }) : undefined, data: data });
30
+ return codeLens;
31
+ });
32
+ }
33
+ }), (data, sourceMap) => data.map(codeLens => {
34
+ var _a;
35
+ if (!sourceMap)
36
+ return codeLens;
37
+ const range = (_a = sourceMap.getSourceRange(codeLens.range.start, codeLens.range.end)) === null || _a === void 0 ? void 0 : _a[0];
38
+ if (range) {
39
+ return Object.assign(Object.assign({}, codeLens), { range });
40
+ }
41
+ }).filter(shared.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : [];
42
+ });
43
+ }
44
+ exports.register = register;
45
+ //# sourceMappingURL=codeLens.js.map
@@ -0,0 +1,3 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export declare function register(context: LanguageServiceRuntimeContext): (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
@@ -0,0 +1,30 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.register = void 0;
12
+ const executeCommand_1 = require("./executeCommand");
13
+ function register(context) {
14
+ return (item) => __awaiter(this, void 0, void 0, function* () {
15
+ var _a;
16
+ const data = item.data;
17
+ if (data) {
18
+ const plugin = context.plugins[data.pluginId];
19
+ if (!plugin)
20
+ return item;
21
+ if (!((_a = plugin.codeLens) === null || _a === void 0 ? void 0 : _a.resolve))
22
+ return item;
23
+ const resolvedOriginalItem = yield plugin.codeLens.resolve(data.originalItem);
24
+ item = Object.assign(Object.assign({}, resolvedOriginalItem), { command: resolvedOriginalItem.command ? Object.assign(Object.assign({}, resolvedOriginalItem.command), { command: executeCommand_1.executePluginCommand, arguments: [data.uri, context.plugins.indexOf(plugin), resolvedOriginalItem.command] }) : undefined, range: item.range });
25
+ }
26
+ return item;
27
+ });
28
+ }
29
+ exports.register = register;
30
+ //# sourceMappingURL=codeLensResolve.js.map
@@ -0,0 +1,14 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export interface PluginCompletionData {
4
+ uri: string;
5
+ originalItem: vscode.CompletionItem;
6
+ pluginId: number;
7
+ sourceMap: {
8
+ embeddedDocumentUri: string;
9
+ } | undefined;
10
+ }
11
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext) => Promise<{
12
+ isIncomplete: boolean;
13
+ items: vscode.CompletionItem[];
14
+ }>;
@@ -0,0 +1,181 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.register = void 0;
12
+ const transforms_1 = require("@volar/transforms");
13
+ const vscode = require("vscode-languageserver-protocol");
14
+ const definePlugin_1 = require("../utils/definePlugin");
15
+ function register(context) {
16
+ let cache;
17
+ return (uri, position, completionContext) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b, _c, _d;
19
+ 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) {
22
+ for (const cacheData of cache.data) {
23
+ if (!cacheData.list.isIncomplete)
24
+ continue;
25
+ if (cacheData.sourceMap) {
26
+ const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(cacheData.sourceMap.embeddedDocumentUri);
27
+ if (!sourceMap)
28
+ continue;
29
+ for (const [embeddedRange] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
30
+ if (!((_a = cacheData.plugin.complete) === null || _a === void 0 ? void 0 : _a.on))
31
+ continue;
32
+ const embeddedCompletionList = yield cacheData.plugin.complete.on(sourceMap.mappedDocument, embeddedRange.start, completionContext);
33
+ if (!embeddedCompletionList) {
34
+ cacheData.list.isIncomplete = false;
35
+ continue;
36
+ }
37
+ cacheData.list = Object.assign(Object.assign({}, embeddedCompletionList), { items: embeddedCompletionList.items.map(item => {
38
+ const data = {
39
+ uri,
40
+ originalItem: item,
41
+ pluginId: context.plugins.indexOf(cacheData.plugin),
42
+ sourceMap: {
43
+ embeddedDocumentUri: sourceMap.mappedDocument.uri,
44
+ },
45
+ };
46
+ return Object.assign(Object.assign({}, (0, transforms_1.transformCompletionItem)(item, embeddedRange => { var _a; return (_a = sourceMap.getSourceRange(embeddedRange.start, embeddedRange.end)) === null || _a === void 0 ? void 0 : _a[0]; })), { data: data });
47
+ }) });
48
+ }
49
+ }
50
+ else if (document = context.getTextDocument(uri)) {
51
+ if (!((_b = cacheData.plugin.complete) === null || _b === void 0 ? void 0 : _b.on))
52
+ continue;
53
+ const completionList = yield cacheData.plugin.complete.on(document, position, completionContext);
54
+ if (!completionList) {
55
+ cacheData.list.isIncomplete = false;
56
+ continue;
57
+ }
58
+ cacheData.list = Object.assign(Object.assign({}, completionList), { items: completionList.items.map(item => {
59
+ const data = {
60
+ uri,
61
+ originalItem: item,
62
+ pluginId: context.plugins.indexOf(cacheData.plugin),
63
+ sourceMap: undefined,
64
+ };
65
+ return Object.assign(Object.assign({}, item), { data: data });
66
+ }) });
67
+ }
68
+ }
69
+ }
70
+ else {
71
+ const vueDocument = context.documents.get(uri);
72
+ cache = {
73
+ uri,
74
+ data: [],
75
+ mainCompletion: undefined,
76
+ };
77
+ // monky fix https://github.com/johnsoncodehk/volar/issues/1358
78
+ let isFirstMapping = true;
79
+ if (vueDocument) {
80
+ yield (0, definePlugin_1.visitEmbedded)(vueDocument, (sourceMap) => __awaiter(this, void 0, void 0, function* () {
81
+ var _e, _f;
82
+ const plugins = context.plugins.sort(sortPlugins);
83
+ for (const [embeddedRange, data] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
84
+ for (const plugin of plugins) {
85
+ if (!((_e = plugin.complete) === null || _e === void 0 ? void 0 : _e.on))
86
+ continue;
87
+ if (plugin.complete.isAdditional && !isFirstMapping)
88
+ continue;
89
+ if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_f = plugin.complete.triggerCharacters) === null || _f === void 0 ? void 0 : _f.includes(completionContext.triggerCharacter)))
90
+ continue;
91
+ const isAdditionalMapping = typeof data.completion === 'object' && data.completion.additional;
92
+ if (cache.mainCompletion && ((!plugin.complete.isAdditional && !isAdditionalMapping) || (cache === null || cache === void 0 ? void 0 : cache.mainCompletion.documentUri) !== sourceMap.mappedDocument.uri))
93
+ continue;
94
+ // avoid duplicate items with .vue and .vue.html
95
+ if (plugin.complete.isAdditional && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin)))
96
+ continue;
97
+ const embeddedCompletionList = yield plugin.complete.on(sourceMap.mappedDocument, embeddedRange.start, completionContext);
98
+ if (!embeddedCompletionList || !embeddedCompletionList.items.length)
99
+ continue;
100
+ if (!plugin.complete.isAdditional) {
101
+ cache.mainCompletion = { documentUri: sourceMap.mappedDocument.uri };
102
+ }
103
+ const completionList = Object.assign(Object.assign({}, embeddedCompletionList), { items: embeddedCompletionList.items.map(item => {
104
+ const data = {
105
+ uri,
106
+ originalItem: item,
107
+ pluginId: context.plugins.indexOf(plugin),
108
+ sourceMap: {
109
+ embeddedDocumentUri: sourceMap.mappedDocument.uri,
110
+ }
111
+ };
112
+ return Object.assign(Object.assign({}, (0, transforms_1.transformCompletionItem)(item, embeddedRange => { var _a; return (_a = sourceMap.getSourceRange(embeddedRange.start, embeddedRange.end)) === null || _a === void 0 ? void 0 : _a[0]; })), { data: data });
113
+ }) });
114
+ cache.data.push({
115
+ sourceMap: {
116
+ embeddedDocumentUri: sourceMap.mappedDocument.uri,
117
+ },
118
+ plugin,
119
+ list: completionList,
120
+ });
121
+ }
122
+ isFirstMapping = false;
123
+ }
124
+ return true;
125
+ }));
126
+ }
127
+ if (document = context.getTextDocument(uri)) {
128
+ const plugins = context.plugins.sort(sortPlugins);
129
+ for (const plugin of plugins) {
130
+ if (!((_c = plugin.complete) === null || _c === void 0 ? void 0 : _c.on))
131
+ continue;
132
+ if (plugin.complete.isAdditional && !isFirstMapping)
133
+ continue;
134
+ if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_d = plugin.complete.triggerCharacters) === null || _d === void 0 ? void 0 : _d.includes(completionContext.triggerCharacter)))
135
+ continue;
136
+ if (cache.mainCompletion && (!plugin.complete.isAdditional || cache.mainCompletion.documentUri !== document.uri))
137
+ continue;
138
+ // avoid duplicate items with .vue and .vue.html
139
+ if (plugin.complete.isAdditional && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin)))
140
+ continue;
141
+ const completionList = yield plugin.complete.on(document, position, completionContext);
142
+ if (!completionList || !completionList.items.length)
143
+ continue;
144
+ if (!plugin.complete.isAdditional) {
145
+ cache.mainCompletion = { documentUri: document.uri };
146
+ }
147
+ cache.data.push({
148
+ sourceMap: undefined,
149
+ plugin,
150
+ list: Object.assign(Object.assign({}, completionList), { items: completionList.items.map(item => {
151
+ const data = {
152
+ uri,
153
+ originalItem: item,
154
+ pluginId: context.plugins.indexOf(plugin),
155
+ sourceMap: undefined,
156
+ };
157
+ return Object.assign(Object.assign({}, item), { data: data });
158
+ }) }),
159
+ });
160
+ }
161
+ }
162
+ }
163
+ return combineCompletionList(cache.data.map(cacheData => cacheData.list));
164
+ function sortPlugins(a, b) {
165
+ var _a, _b;
166
+ 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);
167
+ }
168
+ function combineCompletionList(lists) {
169
+ return {
170
+ isIncomplete: lists.some(list => list.isIncomplete),
171
+ items: lists.map(list => list.items).flat().filter((result) => {
172
+ var _a;
173
+ return result.label.indexOf('__VLS_') === -1
174
+ && (!((_a = result.labelDetails) === null || _a === void 0 ? void 0 : _a.description) || result.labelDetails.description.indexOf('__VLS_') === -1);
175
+ }),
176
+ };
177
+ }
178
+ });
179
+ }
180
+ exports.register = register;
181
+ //# sourceMappingURL=complete.js.map
@@ -0,0 +1,3 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export declare function register(context: LanguageServiceRuntimeContext): (item: vscode.CompletionItem, newPosition?: vscode.Position) => Promise<vscode.CompletionItem>;