@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,68 @@
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 dedupe = require("../utils/dedupe");
15
+ function register(context) {
16
+ return (uri, position) => {
17
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
18
+ for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.references)) {
19
+ yield mappedRange.start;
20
+ }
21
+ }, (plugin, document, position, sourceMap, vueDocument) => __awaiter(this, void 0, void 0, function* () {
22
+ const recursiveChecker = dedupe.createLocationSet();
23
+ const result = [];
24
+ yield withTeleports(document, position);
25
+ return result;
26
+ function withTeleports(document, position) {
27
+ var _a;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ if (!plugin.findReferences)
30
+ return;
31
+ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
32
+ return;
33
+ recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
34
+ const references = (_a = yield plugin.findReferences(document, position)) !== null && _a !== void 0 ? _a : [];
35
+ for (const reference of references) {
36
+ let foundTeleport = false;
37
+ recursiveChecker.add({ uri: reference.uri, range: { start: reference.range.start, end: reference.range.start } });
38
+ const teleport = context.documents.teleportfromEmbeddedDocumentUri(reference.uri);
39
+ if (teleport) {
40
+ for (const [teleRange] of teleport.findTeleports(reference.range.start, reference.range.end, sideData => !!sideData.references)) {
41
+ if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: teleRange.start, end: teleRange.start } }))
42
+ continue;
43
+ foundTeleport = true;
44
+ yield withTeleports(teleport.document, teleRange.start);
45
+ }
46
+ }
47
+ if (!foundTeleport) {
48
+ result.push(reference);
49
+ }
50
+ }
51
+ });
52
+ }
53
+ }), (data, sourceMap) => data.map(reference => {
54
+ var _a;
55
+ const referenceSourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(reference.uri);
56
+ if (referenceSourceMap) {
57
+ const range = (_a = referenceSourceMap.getSourceRange(reference.range.start, reference.range.end, data => !!data.references)) === null || _a === void 0 ? void 0 : _a[0];
58
+ if (!range)
59
+ return;
60
+ reference.uri = referenceSourceMap.sourceDocument.uri;
61
+ reference.range = range;
62
+ }
63
+ return reference;
64
+ }).filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat()));
65
+ };
66
+ }
67
+ exports.register = register;
68
+ //# sourceMappingURL=references.js.map
@@ -0,0 +1,19 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ import { SourceFileDocuments } from '../documents';
4
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
5
+ export declare function mergeWorkspaceEdits(original: vscode.WorkspaceEdit, ...others: vscode.WorkspaceEdit[]): void;
6
+ /**
7
+ * TODO: rewrite this
8
+ *
9
+ * Start from Script LS
10
+ * -> Access all results
11
+ *
12
+ * Start from template LS
13
+ * -> Start from template content?
14
+ * -> Access all results
15
+ * -> Start from script content?
16
+ * -> Yes: Only access template results
17
+ * -> No: Access all results
18
+ */
19
+ export declare function embeddedEditToSourceEdit(tsResult: vscode.WorkspaceEdit, vueDocuments: SourceFileDocuments): vscode.WorkspaceEdit | undefined;
@@ -0,0 +1,226 @@
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.embeddedEditToSourceEdit = exports.mergeWorkspaceEdits = exports.register = void 0;
12
+ const vscode = require("vscode-languageserver-protocol");
13
+ const featureWorkers_1 = require("../utils/featureWorkers");
14
+ const dedupe = require("../utils/dedupe");
15
+ function register(context) {
16
+ return (uri, position, newName) => {
17
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, newName }, function* (arg, sourceMap) {
18
+ for (const [mappedRange, mappedData] of sourceMap.getMappedRanges(arg.position, arg.position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename)) {
19
+ let newName = arg.newName;
20
+ if (typeof mappedData.rename === 'object' && mappedData.rename.normalize)
21
+ newName = mappedData.rename.normalize(arg.newName);
22
+ yield { position: mappedRange.start, newName };
23
+ }
24
+ }, (plugin, document, arg, sourceMap) => __awaiter(this, void 0, void 0, function* () {
25
+ const recursiveChecker = dedupe.createLocationSet();
26
+ let result;
27
+ yield withTeleports(document, arg.position, arg.newName);
28
+ return result;
29
+ function withTeleports(document, position, newName) {
30
+ var _a;
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ if (!((_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.on))
33
+ return;
34
+ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
35
+ return;
36
+ recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
37
+ const workspaceEdit = yield plugin.rename.on(document, position, newName);
38
+ if (!workspaceEdit)
39
+ return;
40
+ if (!result)
41
+ result = {};
42
+ if (workspaceEdit.changes) {
43
+ for (const editUri in workspaceEdit.changes) {
44
+ const textEdits = workspaceEdit.changes[editUri];
45
+ for (const textEdit of textEdits) {
46
+ let foundTeleport = false;
47
+ recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } });
48
+ const teleport = context.documents.teleportfromEmbeddedDocumentUri(editUri);
49
+ if (teleport) {
50
+ for (const [teleRange] of teleport.findTeleports(textEdit.range.start, textEdit.range.end, sideData => !!sideData.rename)) {
51
+ if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: teleRange.start, end: teleRange.start } }))
52
+ continue;
53
+ foundTeleport = true;
54
+ yield withTeleports(teleport.document, teleRange.start, newName);
55
+ }
56
+ }
57
+ if (!foundTeleport) {
58
+ if (!result.changes)
59
+ result.changes = {};
60
+ if (!result.changes[editUri])
61
+ result.changes[editUri] = [];
62
+ result.changes[editUri].push(textEdit);
63
+ }
64
+ }
65
+ }
66
+ }
67
+ if (workspaceEdit.changeAnnotations) {
68
+ for (const uri in workspaceEdit.changeAnnotations) {
69
+ if (!result.changeAnnotations)
70
+ result.changeAnnotations = {};
71
+ result.changeAnnotations[uri] = workspaceEdit.changeAnnotations[uri];
72
+ }
73
+ }
74
+ if (workspaceEdit.documentChanges) {
75
+ if (!result.documentChanges)
76
+ result.documentChanges = [];
77
+ result.documentChanges = result.documentChanges.concat(workspaceEdit.documentChanges);
78
+ }
79
+ });
80
+ }
81
+ }), (data, sourceMap) => {
82
+ return embeddedEditToSourceEdit(data, context.documents);
83
+ }, (workspaceEdits) => {
84
+ const mainEdit = workspaceEdits[0];
85
+ const otherEdits = workspaceEdits.slice(1);
86
+ mergeWorkspaceEdits(mainEdit, ...otherEdits);
87
+ if (mainEdit.changes) {
88
+ for (const uri in mainEdit.changes) {
89
+ mainEdit.changes[uri] = dedupe.withTextEdits(mainEdit.changes[uri]);
90
+ }
91
+ }
92
+ return workspaceEdits[0];
93
+ });
94
+ };
95
+ }
96
+ exports.register = register;
97
+ function mergeWorkspaceEdits(original, ...others) {
98
+ for (const other of others) {
99
+ for (const uri in other.changeAnnotations) {
100
+ if (!original.changeAnnotations) {
101
+ original.changeAnnotations = {};
102
+ }
103
+ original.changeAnnotations[uri] = other.changeAnnotations[uri];
104
+ }
105
+ for (const uri in other.changes) {
106
+ if (!original.changes) {
107
+ original.changes = {};
108
+ }
109
+ if (!original.changes[uri]) {
110
+ original.changes[uri] = [];
111
+ }
112
+ const edits = other.changes[uri];
113
+ original.changes[uri] = original.changes[uri].concat(edits);
114
+ }
115
+ if (other.documentChanges) {
116
+ if (!original.documentChanges) {
117
+ original.documentChanges = [];
118
+ }
119
+ for (const docChange of other.documentChanges) {
120
+ original.documentChanges.push(docChange);
121
+ }
122
+ }
123
+ }
124
+ }
125
+ exports.mergeWorkspaceEdits = mergeWorkspaceEdits;
126
+ /**
127
+ * TODO: rewrite this
128
+ *
129
+ * Start from Script LS
130
+ * -> Access all results
131
+ *
132
+ * Start from template LS
133
+ * -> Start from template content?
134
+ * -> Access all results
135
+ * -> Start from script content?
136
+ * -> Yes: Only access template results
137
+ * -> No: Access all results
138
+ */
139
+ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
140
+ var _a, _b, _c, _d, _e, _f;
141
+ const vueResult = {};
142
+ let hasResult = false;
143
+ for (const tsUri in tsResult.changeAnnotations) {
144
+ if (!vueResult.changeAnnotations)
145
+ vueResult.changeAnnotations = {};
146
+ const tsAnno = tsResult.changeAnnotations[tsUri];
147
+ const uri = (_b = (_a = vueDocuments.sourceMapFromEmbeddedDocumentUri(tsUri)) === null || _a === void 0 ? void 0 : _a.sourceDocument.uri) !== null && _b !== void 0 ? _b : tsUri;
148
+ vueResult.changeAnnotations[uri] = tsAnno;
149
+ }
150
+ for (const tsUri in tsResult.changes) {
151
+ const tsEdits = tsResult.changes[tsUri];
152
+ for (const tsEdit of tsEdits) {
153
+ for (const vueLoc of vueDocuments.fromEmbeddedLocation(tsUri, tsEdit.range.start, tsEdit.range.end, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename)) {
154
+ let newText_2 = tsEdit.newText;
155
+ if (vueLoc.sourceMap && typeof vueLoc.data.rename === 'object' && vueLoc.data.rename.apply) {
156
+ const vueDoc = vueLoc.sourceMap.sourceDocument;
157
+ newText_2 = vueLoc.data.rename.apply(vueDoc.getText(vueLoc.range), tsEdit.newText);
158
+ }
159
+ if (!vueResult.changes) {
160
+ vueResult.changes = {};
161
+ }
162
+ if (!vueResult.changes[vueLoc.uri]) {
163
+ vueResult.changes[vueLoc.uri] = [];
164
+ }
165
+ vueResult.changes[vueLoc.uri].push({
166
+ newText: newText_2,
167
+ range: vueLoc.range,
168
+ });
169
+ hasResult = true;
170
+ }
171
+ }
172
+ }
173
+ if (tsResult.documentChanges) {
174
+ for (const tsDocEdit of tsResult.documentChanges) {
175
+ if (!vueResult.documentChanges) {
176
+ vueResult.documentChanges = [];
177
+ }
178
+ let vueDocEdit;
179
+ if (vscode.TextDocumentEdit.is(tsDocEdit)) {
180
+ const sourceMap = vueDocuments.sourceMapFromEmbeddedDocumentUri(tsDocEdit.textDocument.uri);
181
+ if (sourceMap) {
182
+ vueDocEdit = vscode.TextDocumentEdit.create({
183
+ uri: sourceMap.sourceDocument.uri,
184
+ // version: sourceMap.sourceDocument.version,
185
+ version: null, // fix https://github.com/johnsoncodehk/volar/issues/1490
186
+ }, []);
187
+ for (const tsEdit of tsDocEdit.edits) {
188
+ for (const [vueRange] of sourceMap.getSourceRanges(tsEdit.range.start, tsEdit.range.end, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename)) {
189
+ vueDocEdit.edits.push({
190
+ annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
191
+ newText: tsEdit.newText,
192
+ range: vueRange,
193
+ });
194
+ }
195
+ }
196
+ if (!vueDocEdit.edits.length) {
197
+ vueDocEdit = undefined;
198
+ }
199
+ }
200
+ else {
201
+ vueDocEdit = tsDocEdit;
202
+ }
203
+ }
204
+ else if (vscode.CreateFile.is(tsDocEdit)) {
205
+ vueDocEdit = tsDocEdit; // TODO: remove .ts?
206
+ }
207
+ else if (vscode.RenameFile.is(tsDocEdit)) {
208
+ const oldUri = (_d = (_c = vueDocuments.sourceMapFromEmbeddedDocumentUri(tsDocEdit.oldUri)) === null || _c === void 0 ? void 0 : _c.sourceDocument.uri) !== null && _d !== void 0 ? _d : tsDocEdit.oldUri;
209
+ vueDocEdit = vscode.RenameFile.create(oldUri, tsDocEdit.newUri /* TODO: remove .ts? */, tsDocEdit.options, tsDocEdit.annotationId);
210
+ }
211
+ else if (vscode.DeleteFile.is(tsDocEdit)) {
212
+ const uri = (_f = (_e = vueDocuments.sourceMapFromEmbeddedDocumentUri(tsDocEdit.uri)) === null || _e === void 0 ? void 0 : _e.sourceDocument.uri) !== null && _f !== void 0 ? _f : tsDocEdit.uri;
213
+ vueDocEdit = vscode.DeleteFile.create(uri, tsDocEdit.options, tsDocEdit.annotationId);
214
+ }
215
+ if (vueDocEdit) {
216
+ vueResult.documentChanges.push(vueDocEdit);
217
+ hasResult = true;
218
+ }
219
+ }
220
+ }
221
+ if (hasResult) {
222
+ return vueResult;
223
+ }
224
+ }
225
+ exports.embeddedEditToSourceEdit = embeddedEditToSourceEdit;
226
+ //# sourceMappingURL=rename.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): (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
@@ -0,0 +1,41 @@
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_1 = require("@volar/shared");
13
+ const vscode = require("vscode-languageserver-protocol");
14
+ const featureWorkers_1 = require("../utils/featureWorkers");
15
+ // https://github.com/microsoft/vscode/blob/dcf27391b7dd7c1cece483806af75b4f87188e70/extensions/html/language-configuration.json#L35
16
+ const htmlWordPatterns = /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\\"\,\.\<\>\/\s]+)/g;
17
+ function register(context) {
18
+ return (uri, position) => __awaiter(this, void 0, void 0, function* () {
19
+ const document = context.getTextDocument(uri);
20
+ const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
21
+ for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename)) {
22
+ yield mappedRange.start;
23
+ }
24
+ }, (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (data, sourceMap) => {
25
+ var _a;
26
+ if (sourceMap && vscode.Range.is(data))
27
+ return (_a = sourceMap.getSourceRange(data.start, data.end)) === null || _a === void 0 ? void 0 : _a[0];
28
+ return data;
29
+ }, prepares => {
30
+ for (const prepare of prepares) {
31
+ if (vscode.Range.is(prepare)) {
32
+ return prepare; // if has any valid range, ignore other errors
33
+ }
34
+ }
35
+ return prepares[0];
36
+ });
37
+ return result !== null && result !== void 0 ? result : (document ? (0, shared_1.getWordRange)(htmlWordPatterns, position, document) : undefined);
38
+ });
39
+ }
40
+ exports.register = register;
41
+ //# sourceMappingURL=renamePrepare.js.map
@@ -0,0 +1,3 @@
1
+ import type * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext) => Promise<vscode.SignatureHelp | undefined>;
@@ -0,0 +1,14 @@
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, signatureHelpContext) => {
6
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
7
+ for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
8
+ yield mappedRange.start;
9
+ }
10
+ }, (plugin, document, position) => { var _a; return (_a = plugin.getSignatureHelp) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, signatureHelpContext); }, (data, sourceMap) => data);
11
+ };
12
+ }
13
+ exports.register = register;
14
+ //# sourceMappingURL=signatureHelp.js.map
@@ -0,0 +1,7 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export declare function updateRange(range: vscode.Range, change: {
4
+ range: vscode.Range;
5
+ newEnd: vscode.Position;
6
+ }): vscode.Range;
7
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined, cancellationToken?: vscode.CancellationToken) => Promise<vscode.Diagnostic[]>;
@@ -0,0 +1,237 @@
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 = exports.updateRange = void 0;
12
+ const shared = require("@volar/shared");
13
+ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
14
+ const dedupe = require("../utils/dedupe");
15
+ const featureWorkers_1 = require("../utils/featureWorkers");
16
+ function isTsDocument(document) {
17
+ return document.languageId === 'javascript' ||
18
+ document.languageId === 'typescript' ||
19
+ document.languageId === 'javascriptreact' ||
20
+ document.languageId === 'typescriptreact';
21
+ }
22
+ function updateRange(range, change) {
23
+ updatePosition(range.start, change, false);
24
+ updatePosition(range.end, change, true);
25
+ if (range.end.line === range.start.line && range.end.character <= range.start.character) {
26
+ range.end.character++;
27
+ }
28
+ return range;
29
+ }
30
+ exports.updateRange = updateRange;
31
+ function updatePosition(position, change, isEnd) {
32
+ if (change.range.end.line > position.line) {
33
+ if (change.newEnd.line > position.line) {
34
+ // No change
35
+ }
36
+ else if (change.newEnd.line === position.line) {
37
+ position.character = Math.min(position.character, change.newEnd.character);
38
+ }
39
+ else if (change.newEnd.line < position.line) {
40
+ position.line = change.newEnd.line;
41
+ position.character = change.newEnd.character;
42
+ }
43
+ }
44
+ else if (change.range.end.line === position.line) {
45
+ const characterDiff = change.newEnd.character - change.range.end.character;
46
+ if (position.character >= change.range.end.character) {
47
+ if (change.newEnd.line !== change.range.end.line) {
48
+ position.line = change.newEnd.line;
49
+ position.character = change.newEnd.character + position.character - change.range.end.character;
50
+ }
51
+ else {
52
+ if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
53
+ position.character += characterDiff;
54
+ }
55
+ else {
56
+ const offset = change.range.end.character - position.character;
57
+ if (-characterDiff > offset) {
58
+ position.character += characterDiff + offset;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ else {
64
+ if (change.newEnd.line !== change.range.end.line) {
65
+ if (change.newEnd.line < change.range.end.line) {
66
+ position.line = change.newEnd.line;
67
+ position.character = change.newEnd.character;
68
+ }
69
+ }
70
+ else {
71
+ const offset = change.range.end.character - position.character;
72
+ if (-characterDiff > offset) {
73
+ position.character += characterDiff + offset;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ else if (change.range.end.line < position.line) {
79
+ position.line += change.newEnd.line - change.range.end.line;
80
+ }
81
+ }
82
+ function register(context) {
83
+ const responseCache = new Map();
84
+ const nonTsCache = new Map();
85
+ const scriptTsCache_semantic = new Map();
86
+ const scriptTsCache_declaration = new Map();
87
+ const scriptTsCache_syntactic = new Map();
88
+ const scriptTsCache_suggestion = new Map();
89
+ return (uri, response, cancellationToken) => __awaiter(this, void 0, void 0, function* () {
90
+ var _a;
91
+ const cache = (_a = responseCache.get(uri)) !== null && _a !== void 0 ? _a : responseCache.set(uri, {
92
+ nonTs: { snapshot: undefined, errors: [] },
93
+ tsSemantic: { snapshot: undefined, errors: [] },
94
+ tsDeclaration: { snapshot: undefined, errors: [] },
95
+ tsSuggestion: { snapshot: undefined, errors: [] },
96
+ tsSyntactic: { snapshot: undefined, errors: [] },
97
+ }).get(uri);
98
+ const newSnapshot = context.host.getScriptSnapshot(shared.getPathOfUri(uri));
99
+ const newDocument = newSnapshot ? vscode_languageserver_textdocument_1.TextDocument.create('file://a.txt', 'txt', 0, newSnapshot.getText(0, newSnapshot.getLength())) : undefined;
100
+ for (const _cache of Object.values(cache)) {
101
+ const oldSnapshot = _cache.snapshot;
102
+ const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined;
103
+ _cache.snapshot = newSnapshot;
104
+ if (newDocument && oldSnapshot && newSnapshot && change) {
105
+ const oldDocument = vscode_languageserver_textdocument_1.TextDocument.create('file://a.txt', 'txt', 0, oldSnapshot.getText(0, oldSnapshot.getLength()));
106
+ const changeRange = {
107
+ range: {
108
+ start: oldDocument.positionAt(change.span.start),
109
+ end: oldDocument.positionAt(change.span.start + change.span.length),
110
+ },
111
+ newEnd: newDocument.positionAt(change.span.start + change.newLength),
112
+ };
113
+ for (const error of _cache.errors) {
114
+ updateRange(error.range, changeRange);
115
+ }
116
+ }
117
+ }
118
+ let shouldSend = false;
119
+ let lastCheckCancelAt = 0;
120
+ yield worker(false, 'onFull', nonTsCache, cache.nonTs);
121
+ doResponse();
122
+ yield worker(true, 'onSyntactic', scriptTsCache_syntactic, cache.tsSyntactic);
123
+ doResponse();
124
+ yield worker(true, 'onSuggestion', scriptTsCache_suggestion, cache.tsSuggestion);
125
+ doResponse();
126
+ yield worker(true, 'onSemantic', scriptTsCache_semantic, cache.tsSemantic);
127
+ doResponse();
128
+ yield worker(true, 'onDeclaration', scriptTsCache_declaration, cache.tsDeclaration);
129
+ return getErrors();
130
+ function doResponse() {
131
+ if (shouldSend) {
132
+ response === null || response === void 0 ? void 0 : response(getErrors());
133
+ shouldSend = false;
134
+ }
135
+ }
136
+ function getErrors() {
137
+ return Object.values(cache).flatMap(({ errors }) => errors);
138
+ }
139
+ function worker(isTs, mode, cacheMap, cache) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, sourceMap) {
142
+ if (sourceMap.embeddedFile.capabilities.diagnostics && sourceMap.embeddedFile.isTsHostFile === isTs) {
143
+ yield arg;
144
+ }
145
+ }, (plugin, document, arg, sourceMap) => __awaiter(this, void 0, void 0, function* () {
146
+ var _a, _b, _c, _d, _e;
147
+ if (cancellationToken) {
148
+ if (Date.now() - lastCheckCancelAt >= 5) {
149
+ yield shared.sleep(5); // wait for LSP event polling
150
+ lastCheckCancelAt = Date.now();
151
+ }
152
+ if (cancellationToken.isCancellationRequested)
153
+ return;
154
+ }
155
+ // avoid duplicate errors from vue plugin & typescript plugin
156
+ if (isTsDocument(document) !== isTs)
157
+ return;
158
+ const pluginId = context.plugins.indexOf(plugin);
159
+ const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
160
+ const cache = pluginCache.get(document.uri);
161
+ const tsProjectVersion = isTs ? (_c = (_b = context.core.typescriptLanguageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
162
+ if (!isTs) {
163
+ if (cache && cache.documentVersion === document.version) {
164
+ return cache.errors;
165
+ }
166
+ }
167
+ else {
168
+ if (mode === 'onFull' || mode === 'onDeclaration' || mode === 'onSemantic') {
169
+ if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
170
+ return cache.errors;
171
+ }
172
+ }
173
+ else {
174
+ if (cache && cache.documentVersion === document.version) {
175
+ return cache.errors;
176
+ }
177
+ }
178
+ }
179
+ const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[mode]) === null || _e === void 0 ? void 0 : _e.call(_d, document));
180
+ shouldSend = true;
181
+ pluginCache.set(document.uri, {
182
+ documentVersion: document.version,
183
+ errors,
184
+ tsProjectVersion,
185
+ });
186
+ return errors;
187
+ }), (errors, sourceMap) => transformErrorRange(sourceMap, errors), arr => dedupe.withDiagnostics(arr.flat()));
188
+ if (result) {
189
+ cache.errors = result;
190
+ cache.snapshot = newSnapshot;
191
+ }
192
+ });
193
+ }
194
+ });
195
+ function transformErrorRange(sourceMap, errors) {
196
+ var _a, _b, _c;
197
+ const result = [];
198
+ for (const error of errors) {
199
+ const _error = Object.assign({}, error);
200
+ if (sourceMap) {
201
+ let sourceRange = (_a = sourceMap.getSourceRange(error.range.start, error.range.end, data => !!data.diagnostic)) === null || _a === void 0 ? void 0 : _a[0];
202
+ // fix https://github.com/johnsoncodehk/volar/issues/1205
203
+ // fix https://github.com/johnsoncodehk/volar/issues/1264
204
+ if (!sourceRange) {
205
+ const start = (_b = sourceMap.getSourceRange(error.range.start, error.range.start, data => !!data.diagnostic)) === null || _b === void 0 ? void 0 : _b[0].start;
206
+ const end = (_c = sourceMap.getSourceRange(error.range.end, error.range.end, data => !!data.diagnostic)) === null || _c === void 0 ? void 0 : _c[0].end;
207
+ if (start && end) {
208
+ sourceRange = { start, end };
209
+ }
210
+ }
211
+ if (!sourceRange)
212
+ continue;
213
+ _error.range = sourceRange;
214
+ }
215
+ if (_error.relatedInformation) {
216
+ const relatedInfos = [];
217
+ for (const info of _error.relatedInformation) {
218
+ for (const sourceLoc of context.documents.fromEmbeddedLocation(info.location.uri, info.location.range.start, info.location.range.end, data => !!data.diagnostic)) {
219
+ relatedInfos.push({
220
+ location: {
221
+ uri: sourceLoc.uri,
222
+ range: sourceLoc.range,
223
+ },
224
+ message: info.message,
225
+ });
226
+ break;
227
+ }
228
+ }
229
+ _error.relatedInformation = relatedInfos;
230
+ }
231
+ result.push(_error);
232
+ }
233
+ return result;
234
+ }
235
+ }
236
+ exports.register = register;
237
+ //# sourceMappingURL=validation.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): (query: string) => Promise<vscode.SymbolInformation[]>;