@torpor/language-server 1.0.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.
- package/README.md +104 -0
- package/dist/bin/index.d.mts +1 -0
- package/dist/bin/index.js +9 -0
- package/dist/bin/index.js.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/src-DXbwpiIY.mjs +1333 -0
- package/dist/src-DXbwpiIY.mjs.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,1333 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
3
|
+
import { CompletionList, ProposedFeatures, SemanticTokensRangeRequest, SemanticTokensRequest, TextDocumentSyncKind, TextDocuments, createConnection } from "vscode-languageserver/node.js";
|
|
4
|
+
import { getCSSLanguageService } from "vscode-css-languageservice";
|
|
5
|
+
import { getLanguageService } from "vscode-html-languageservice";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import url from "node:url";
|
|
9
|
+
import * as tsvfs from "@typescript/vfs";
|
|
10
|
+
import { build, parse } from "@torpor/view/compile";
|
|
11
|
+
import { SymbolKind } from "vscode-languageserver";
|
|
12
|
+
//#region \0rolldown/runtime.js
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __exportAll = (all, no_symbols) => {
|
|
18
|
+
let target = {};
|
|
19
|
+
for (var name in all) __defProp(target, name, {
|
|
20
|
+
get: all[name],
|
|
21
|
+
enumerable: true
|
|
22
|
+
});
|
|
23
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
28
|
+
key = keys[i];
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
30
|
+
get: ((k) => from[k]).bind(null, key),
|
|
31
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/modes/cssMode.ts
|
|
39
|
+
function getCSSMode(cssLanguageService, documentRegions) {
|
|
40
|
+
return {
|
|
41
|
+
getId() {
|
|
42
|
+
return "css";
|
|
43
|
+
},
|
|
44
|
+
doValidation(document) {
|
|
45
|
+
const embedded = documentRegions.get(document).getEmbeddedDocument("css");
|
|
46
|
+
const stylesheet = cssLanguageService.parseStylesheet(embedded);
|
|
47
|
+
return cssLanguageService.doValidation(embedded, stylesheet);
|
|
48
|
+
},
|
|
49
|
+
doComplete(document, position) {
|
|
50
|
+
const embedded = documentRegions.get(document).getEmbeddedDocument("css");
|
|
51
|
+
const stylesheet = cssLanguageService.parseStylesheet(embedded);
|
|
52
|
+
return cssLanguageService.doComplete(embedded, position, stylesheet);
|
|
53
|
+
},
|
|
54
|
+
onDocumentRemoved(_document) {},
|
|
55
|
+
dispose() {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/embeddedSupport.ts
|
|
60
|
+
function getDocumentRegions(document) {
|
|
61
|
+
const regions = [];
|
|
62
|
+
let documentText = document.getText();
|
|
63
|
+
let start = 0;
|
|
64
|
+
for (let i = 0; i < documentText.length; i++) {
|
|
65
|
+
const char = documentText[i];
|
|
66
|
+
if (char === "/") {
|
|
67
|
+
if (documentText[i + 1] === "/") i = documentText.indexOf("\n", i);
|
|
68
|
+
else if (documentText[i + 1] === "*") i = documentText.indexOf("*/", i) + 1;
|
|
69
|
+
} else if (char === "\"" || char === "'") {
|
|
70
|
+
for (let j = i + 1; j < documentText.length; j++) if (documentText[j] === char && documentText[j - 1] !== "\\") {
|
|
71
|
+
i = j;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
} else if (char === "`") {
|
|
75
|
+
let level = 0;
|
|
76
|
+
for (let j = i + 1; j < documentText.length; j++) if (documentText[j] === char && documentText[j - 1] !== "\\" && level === 0) {
|
|
77
|
+
i = j;
|
|
78
|
+
break;
|
|
79
|
+
} else if (documentText[j] === "{" && (level > 0 || documentText[j - 1] === "$")) level += 1;
|
|
80
|
+
else if (documentText[j] === "}" && level > 0) level -= 1;
|
|
81
|
+
} else if (char === "@") {
|
|
82
|
+
if (documentText.substring(i + 1).startsWith("render") || documentText.substring(i + 1).startsWith("head")) {
|
|
83
|
+
let end = documentText.indexOf("{", i) + 1;
|
|
84
|
+
if (end === -1) end = documentText.length;
|
|
85
|
+
regions.push({
|
|
86
|
+
languageId: "script",
|
|
87
|
+
start,
|
|
88
|
+
end
|
|
89
|
+
});
|
|
90
|
+
start = end;
|
|
91
|
+
start = i = getRenderRegions(start, documentText, regions);
|
|
92
|
+
} else if (documentText.substring(i).startsWith("@style")) {
|
|
93
|
+
let end = documentText.indexOf("{", i) + 1;
|
|
94
|
+
if (end === -1) end = documentText.length;
|
|
95
|
+
regions.push({
|
|
96
|
+
languageId: "script",
|
|
97
|
+
start,
|
|
98
|
+
end
|
|
99
|
+
});
|
|
100
|
+
start = end;
|
|
101
|
+
start = i = getStyleRegions(start, documentText, regions);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const end = documentText.length;
|
|
106
|
+
regions.push({
|
|
107
|
+
languageId: "script",
|
|
108
|
+
start,
|
|
109
|
+
end
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
getLanguageRanges: (range) => getLanguageRanges(document, regions, range),
|
|
113
|
+
getEmbeddedDocument: (languageId, ignoreAttributeValues) => getEmbeddedDocument(document, regions, languageId, ignoreAttributeValues),
|
|
114
|
+
getLanguageAtPosition: (position) => getLanguageAtPosition(document, regions, position),
|
|
115
|
+
getLanguagesInDocument: () => getLanguagesInDocument(document, regions),
|
|
116
|
+
getImportedScripts: () => []
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function getRenderRegions(start, documentText, regions) {
|
|
120
|
+
let end = documentText.length;
|
|
121
|
+
for (let i = start; i < documentText.length; i++) {
|
|
122
|
+
const char = documentText[i];
|
|
123
|
+
if (char === "@") {
|
|
124
|
+
let tail = documentText.substring(i + 1);
|
|
125
|
+
if (tail.startsWith("//")) i = documentText.indexOf("\n", i);
|
|
126
|
+
else if (tail.startsWith("/*")) i = documentText.indexOf("*/", i) + 1;
|
|
127
|
+
} else if (char === "<" && documentText.substring(i + 1).startsWith("!--")) i = documentText.indexOf("-->", i) + 2;
|
|
128
|
+
else if (char === "<" && /[A-Za-z]/.test(documentText[i + 1] ?? "")) {
|
|
129
|
+
let nameEnd = i + 1;
|
|
130
|
+
while (nameEnd < documentText.length && /[A-Za-z0-9.$]/.test(documentText[nameEnd])) nameEnd++;
|
|
131
|
+
if (/[A-Z]/.test(documentText[i + 1])) {
|
|
132
|
+
i = nameEnd;
|
|
133
|
+
regions.push({
|
|
134
|
+
languageId: "html",
|
|
135
|
+
start,
|
|
136
|
+
end: i
|
|
137
|
+
});
|
|
138
|
+
start = i;
|
|
139
|
+
end = documentText.length;
|
|
140
|
+
for (let j = i; j < documentText.length; j++) if (/[\s>]/.test(documentText[j])) {
|
|
141
|
+
end = j;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
regions.push({
|
|
145
|
+
languageId: "script",
|
|
146
|
+
start,
|
|
147
|
+
end
|
|
148
|
+
});
|
|
149
|
+
start = i = end;
|
|
150
|
+
}
|
|
151
|
+
} else if (char === "\"" || char === "'") {
|
|
152
|
+
for (let j = i + 1; j < documentText.length; j++) if (documentText[j] === char && documentText[j - 1] !== "\\") {
|
|
153
|
+
i = j;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
} else if (char === "{") {
|
|
157
|
+
regions.push({
|
|
158
|
+
languageId: "html",
|
|
159
|
+
start,
|
|
160
|
+
end: i
|
|
161
|
+
});
|
|
162
|
+
start = i = getScriptRegion(i, documentText, regions);
|
|
163
|
+
} else if (char === "}") {
|
|
164
|
+
end = i;
|
|
165
|
+
regions.push({
|
|
166
|
+
languageId: "html",
|
|
167
|
+
start,
|
|
168
|
+
end
|
|
169
|
+
});
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return end;
|
|
174
|
+
}
|
|
175
|
+
function getStyleRegions(start, documentText, regions) {
|
|
176
|
+
let level = 1;
|
|
177
|
+
let end = documentText.length;
|
|
178
|
+
for (let i = start; i < documentText.length; i++) {
|
|
179
|
+
const char = documentText[i];
|
|
180
|
+
if (char === "/") {
|
|
181
|
+
let commentEnd = -1;
|
|
182
|
+
if (documentText[i + 1] === "/") commentEnd = documentText.indexOf("\n", i);
|
|
183
|
+
else if (documentText[i + 1] === "*") commentEnd = documentText.indexOf("*/", i) + 1;
|
|
184
|
+
if (commentEnd !== -1) {
|
|
185
|
+
regions.push({
|
|
186
|
+
languageId: "css",
|
|
187
|
+
start,
|
|
188
|
+
end: i
|
|
189
|
+
});
|
|
190
|
+
i = commentEnd;
|
|
191
|
+
start = i + 1;
|
|
192
|
+
}
|
|
193
|
+
} else if (char === "{") level += 1;
|
|
194
|
+
else if (char === "}") {
|
|
195
|
+
level -= 1;
|
|
196
|
+
if (level === 0) {
|
|
197
|
+
end = i;
|
|
198
|
+
regions.push({
|
|
199
|
+
languageId: "css",
|
|
200
|
+
start,
|
|
201
|
+
end
|
|
202
|
+
});
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return end;
|
|
208
|
+
}
|
|
209
|
+
function getScriptRegion(start, documentText, regions) {
|
|
210
|
+
let end = documentText.length;
|
|
211
|
+
let level = 0;
|
|
212
|
+
for (let i = start; i < documentText.length; i++) {
|
|
213
|
+
const char = documentText[i];
|
|
214
|
+
if (char === "/") {
|
|
215
|
+
if (documentText[i + 1] === "/") i = documentText.indexOf("\n", i);
|
|
216
|
+
else if (documentText[i + 1] === "*") i = documentText.indexOf("*/", i) + 1;
|
|
217
|
+
} else if (char === "\"" || char === "'") {
|
|
218
|
+
for (let j = i + 1; j < documentText.length; j++) if (documentText[j] === char && documentText[j - 1] !== "\\") {
|
|
219
|
+
i = j;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
} else if (char === "`") {
|
|
223
|
+
let level2 = 0;
|
|
224
|
+
for (let j = i + 1; j < documentText.length; j++) if (documentText[j] === char && documentText[j - 1] !== "\\" && level2 === 0) {
|
|
225
|
+
i = j;
|
|
226
|
+
break;
|
|
227
|
+
} else if (documentText[j] === "{" && (level2 > 0 || documentText[j - 1] === "$")) level2 += 1;
|
|
228
|
+
else if (documentText[j] === "}" && level2 > 0) level2 -= 1;
|
|
229
|
+
} else if (char === "{") level += 1;
|
|
230
|
+
else if (char === "}") {
|
|
231
|
+
level -= 1;
|
|
232
|
+
if (level === 0) {
|
|
233
|
+
end = i + 1;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
regions.push({
|
|
239
|
+
languageId: "script",
|
|
240
|
+
start,
|
|
241
|
+
end
|
|
242
|
+
});
|
|
243
|
+
return end;
|
|
244
|
+
}
|
|
245
|
+
function getLanguageRanges(document, regions, range) {
|
|
246
|
+
const result = [];
|
|
247
|
+
let currentPos = range ? range.start : languageModes_exports.Position.create(0, 0);
|
|
248
|
+
let currentOffset = range ? document.offsetAt(range.start) : 0;
|
|
249
|
+
const endOffset = range ? document.offsetAt(range.end) : document.getText().length;
|
|
250
|
+
for (const region of regions) if (region.end > currentOffset && region.start < endOffset) {
|
|
251
|
+
const start = Math.max(region.start, currentOffset);
|
|
252
|
+
const startPos = document.positionAt(start);
|
|
253
|
+
if (currentOffset < region.start) result.push({
|
|
254
|
+
start: currentPos,
|
|
255
|
+
end: startPos,
|
|
256
|
+
languageId: "script"
|
|
257
|
+
});
|
|
258
|
+
const end = Math.min(region.end, endOffset);
|
|
259
|
+
const endPos = document.positionAt(end);
|
|
260
|
+
if (end > region.start) result.push({
|
|
261
|
+
start: startPos,
|
|
262
|
+
end: endPos,
|
|
263
|
+
languageId: region.languageId
|
|
264
|
+
});
|
|
265
|
+
currentOffset = end;
|
|
266
|
+
currentPos = endPos;
|
|
267
|
+
}
|
|
268
|
+
if (currentOffset < endOffset) {
|
|
269
|
+
const endPos = range ? range.end : document.positionAt(endOffset);
|
|
270
|
+
result.push({
|
|
271
|
+
start: currentPos,
|
|
272
|
+
end: endPos,
|
|
273
|
+
languageId: "script"
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
function getLanguagesInDocument(_document, regions) {
|
|
279
|
+
const result = [];
|
|
280
|
+
for (const region of regions) if (region.languageId && !result.includes(region.languageId)) {
|
|
281
|
+
result.push(region.languageId);
|
|
282
|
+
if (result.length === 3) return result;
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
function getLanguageAtPosition(document, regions, position) {
|
|
287
|
+
const offset = document.offsetAt(position);
|
|
288
|
+
for (const region of regions) if (region.start <= offset) {
|
|
289
|
+
if (offset <= region.end) return region.languageId;
|
|
290
|
+
} else break;
|
|
291
|
+
return "script";
|
|
292
|
+
}
|
|
293
|
+
function getEmbeddedDocument(document, contents, languageId, ignoreAttributeValues) {
|
|
294
|
+
let currentPos = 0;
|
|
295
|
+
const oldContent = document.getText();
|
|
296
|
+
let result = "";
|
|
297
|
+
let lastSuffix = "";
|
|
298
|
+
for (const c of contents) if (c.languageId === languageId && (!ignoreAttributeValues || !c.attributeValue)) {
|
|
299
|
+
result = substituteWithWhitespace(result, currentPos, c.start, oldContent, lastSuffix, getPrefix(c));
|
|
300
|
+
result += oldContent.substring(c.start, c.end);
|
|
301
|
+
currentPos = c.end;
|
|
302
|
+
lastSuffix = getSuffix(c);
|
|
303
|
+
}
|
|
304
|
+
result = substituteWithWhitespace(result, currentPos, oldContent.length, oldContent, lastSuffix, "");
|
|
305
|
+
return languageModes_exports.TextDocument.create(document.uri, languageId, document.version, result);
|
|
306
|
+
}
|
|
307
|
+
function getPrefix(c) {
|
|
308
|
+
if (c.attributeValue) switch (c.languageId) {
|
|
309
|
+
case "css": return "__{";
|
|
310
|
+
}
|
|
311
|
+
return "";
|
|
312
|
+
}
|
|
313
|
+
function getSuffix(c) {
|
|
314
|
+
if (c.attributeValue) switch (c.languageId) {
|
|
315
|
+
case "css": return "}";
|
|
316
|
+
case "script": return ";";
|
|
317
|
+
}
|
|
318
|
+
return "";
|
|
319
|
+
}
|
|
320
|
+
function substituteWithWhitespace(result, start, end, oldContent, before, after) {
|
|
321
|
+
let accumulatedWS = 0;
|
|
322
|
+
result += before;
|
|
323
|
+
for (let i = start + before.length; i < end; i++) {
|
|
324
|
+
const ch = oldContent[i];
|
|
325
|
+
if (ch === "\n" || ch === "\r") {
|
|
326
|
+
accumulatedWS = 0;
|
|
327
|
+
result += ch;
|
|
328
|
+
} else accumulatedWS++;
|
|
329
|
+
}
|
|
330
|
+
result = append(result, " ", accumulatedWS - after.length);
|
|
331
|
+
result += after;
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
function append(result, str, n) {
|
|
335
|
+
while (n > 0) {
|
|
336
|
+
if (n & 1) result += str;
|
|
337
|
+
n >>= 1;
|
|
338
|
+
str += str;
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/modes/htmlMode.ts
|
|
344
|
+
function getHTMLMode(htmlLanguageService) {
|
|
345
|
+
return {
|
|
346
|
+
getId() {
|
|
347
|
+
return "html";
|
|
348
|
+
},
|
|
349
|
+
doComplete(document, position) {
|
|
350
|
+
return htmlLanguageService.doComplete(document, position, htmlLanguageService.parseHTMLDocument(document));
|
|
351
|
+
},
|
|
352
|
+
onDocumentRemoved(_document) {},
|
|
353
|
+
dispose() {}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/languageModelCache.ts
|
|
358
|
+
function getLanguageModelCache(maxEntries, cleanupIntervalTimeInSec, parse) {
|
|
359
|
+
let languageModels = {};
|
|
360
|
+
let nModels = 0;
|
|
361
|
+
let cleanupInterval = void 0;
|
|
362
|
+
if (cleanupIntervalTimeInSec > 0) cleanupInterval = setInterval(() => {
|
|
363
|
+
const cutoffTime = Date.now() - cleanupIntervalTimeInSec * 1e3;
|
|
364
|
+
const uris = Object.keys(languageModels);
|
|
365
|
+
for (const uri of uris) if (languageModels[uri].cTime < cutoffTime) {
|
|
366
|
+
delete languageModels[uri];
|
|
367
|
+
nModels--;
|
|
368
|
+
}
|
|
369
|
+
}, cleanupIntervalTimeInSec * 1e3);
|
|
370
|
+
return {
|
|
371
|
+
get(document) {
|
|
372
|
+
const version = document.version;
|
|
373
|
+
const languageId = document.languageId;
|
|
374
|
+
const languageModelInfo = languageModels[document.uri];
|
|
375
|
+
if (languageModelInfo && languageModelInfo.version === version && languageModelInfo.languageId === languageId) {
|
|
376
|
+
languageModelInfo.cTime = Date.now();
|
|
377
|
+
return languageModelInfo.languageModel;
|
|
378
|
+
}
|
|
379
|
+
const languageModel = parse(document);
|
|
380
|
+
languageModels[document.uri] = {
|
|
381
|
+
languageModel,
|
|
382
|
+
version,
|
|
383
|
+
languageId,
|
|
384
|
+
cTime: Date.now()
|
|
385
|
+
};
|
|
386
|
+
if (!languageModelInfo) nModels++;
|
|
387
|
+
if (nModels === maxEntries) {
|
|
388
|
+
let oldestTime = Number.MAX_VALUE;
|
|
389
|
+
let oldestUri = null;
|
|
390
|
+
for (const uri in languageModels) {
|
|
391
|
+
const languageModelInfo = languageModels[uri];
|
|
392
|
+
if (languageModelInfo.cTime < oldestTime) {
|
|
393
|
+
oldestUri = uri;
|
|
394
|
+
oldestTime = languageModelInfo.cTime;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (oldestUri) {
|
|
398
|
+
delete languageModels[oldestUri];
|
|
399
|
+
nModels--;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return languageModel;
|
|
403
|
+
},
|
|
404
|
+
onDocumentRemoved(document) {
|
|
405
|
+
const uri = document.uri;
|
|
406
|
+
if (languageModels[uri]) {
|
|
407
|
+
delete languageModels[uri];
|
|
408
|
+
nModels--;
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
dispose() {
|
|
412
|
+
if (typeof cleanupInterval !== "undefined") {
|
|
413
|
+
clearInterval(cleanupInterval);
|
|
414
|
+
cleanupInterval = void 0;
|
|
415
|
+
languageModels = {};
|
|
416
|
+
nModels = 0;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/utils/pathReplace.ts
|
|
423
|
+
function pathReplace(pattern, replacement, value) {
|
|
424
|
+
pattern = "^" + pattern.replaceAll("*", "(.+?)");
|
|
425
|
+
replacement = replacement.replaceAll("*", "$1");
|
|
426
|
+
const regex1 = new RegExp(pattern);
|
|
427
|
+
return value.replace(regex1, replacement);
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/script/transformDocument.ts
|
|
431
|
+
function transformDocument(vts, filename, source, debug = false) {
|
|
432
|
+
try {
|
|
433
|
+
const parsed = parse(source);
|
|
434
|
+
if (!parsed.ok || !parsed.template) return {
|
|
435
|
+
ok: false,
|
|
436
|
+
errors: parsed.errors,
|
|
437
|
+
content: "",
|
|
438
|
+
map: []
|
|
439
|
+
};
|
|
440
|
+
let { code, map } = build(parsed.template, { mapped: true });
|
|
441
|
+
code = importComponentFiles(vts, filename, code, map, debug);
|
|
442
|
+
return {
|
|
443
|
+
ok: true,
|
|
444
|
+
errors: [],
|
|
445
|
+
content: code,
|
|
446
|
+
map
|
|
447
|
+
};
|
|
448
|
+
} catch (ex) {
|
|
449
|
+
console.log("Failed to compile", source);
|
|
450
|
+
console.log(ex);
|
|
451
|
+
return {
|
|
452
|
+
ok: false,
|
|
453
|
+
errors: [],
|
|
454
|
+
content: "",
|
|
455
|
+
map: []
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function importComponentFiles(vts, filename, content, map, _debug = false) {
|
|
460
|
+
if (!/^\s*import\s+(.+?)\s+from\s+(.+?);*\s*$/ms.test(content)) return content;
|
|
461
|
+
const first = map.shift();
|
|
462
|
+
const filepath = path.dirname(filename);
|
|
463
|
+
let moved = 0;
|
|
464
|
+
let newMaps = [];
|
|
465
|
+
for (let i = 0; i < first.script.length; i++) if (first.script[i] === "/") {
|
|
466
|
+
if (first.script[i + 1] === "/") i = first.script.indexOf("\n", i);
|
|
467
|
+
else if (first.script[i + 1] === "*") i = first.script.indexOf("*/", i);
|
|
468
|
+
if (i === -1) return content;
|
|
469
|
+
} else if (first.script[i] === "i") {
|
|
470
|
+
const match = first.script.substring(i).match(/import\s+(.+?)\s+from\s+(.+?);*\s*$/ms);
|
|
471
|
+
if (match === null) continue;
|
|
472
|
+
const oldImport = match[0];
|
|
473
|
+
let importFile = match[2];
|
|
474
|
+
if (importFile.startsWith("'") && importFile.endsWith("'") || importFile.startsWith("\"") && importFile.endsWith("\"")) importFile = importFile.substring(1, importFile.length - 1);
|
|
475
|
+
if (!importFile.endsWith(".torp")) {
|
|
476
|
+
newMaps.push({
|
|
477
|
+
script: oldImport,
|
|
478
|
+
source: {
|
|
479
|
+
start: i,
|
|
480
|
+
end: i + oldImport.length
|
|
481
|
+
},
|
|
482
|
+
compiled: {
|
|
483
|
+
start: first.compiled.start + i + moved,
|
|
484
|
+
end: first.compiled.start + i + moved + oldImport.length
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
let typeFile = importFile.startsWith(".") ? path.join(filepath, importFile) : importFile;
|
|
490
|
+
if (vts.configPath && vts.config.paths) {
|
|
491
|
+
const oldTypeFile = typeFile;
|
|
492
|
+
for (let [srcGlob, paths] of Object.entries(vts.config.paths)) for (let destGlob of paths) typeFile = pathReplace(srcGlob, destGlob, typeFile);
|
|
493
|
+
if (typeFile !== oldTypeFile && typeFile.startsWith(".")) typeFile = path.join(vts.configPath, typeFile);
|
|
494
|
+
}
|
|
495
|
+
if (!vts.virtualFiles.has(typeFile) && fs.existsSync(typeFile)) {
|
|
496
|
+
const typeSource = fs.readFileSync(typeFile, "utf8");
|
|
497
|
+
const { content } = transformDocument(vts, typeFile, typeSource);
|
|
498
|
+
const key = typeFile.replace(/\.torp$/, ".ts");
|
|
499
|
+
vts.virtualFiles.set(key, content);
|
|
500
|
+
vts.env.createFile(key, content);
|
|
501
|
+
}
|
|
502
|
+
let oldLength = content.length;
|
|
503
|
+
let newValue = typeFile.replace(".torp", ".ts");
|
|
504
|
+
let newImport = oldImport.replace(importFile, newValue);
|
|
505
|
+
content = content.replace(oldImport, newImport);
|
|
506
|
+
let diff = content.length - oldLength;
|
|
507
|
+
for (let mapped of map) {
|
|
508
|
+
mapped.compiled.start += diff;
|
|
509
|
+
mapped.compiled.end += diff;
|
|
510
|
+
}
|
|
511
|
+
newMaps.push({
|
|
512
|
+
script: oldImport,
|
|
513
|
+
source: {
|
|
514
|
+
start: i,
|
|
515
|
+
end: i + oldImport.length
|
|
516
|
+
},
|
|
517
|
+
compiled: {
|
|
518
|
+
start: first.compiled.start + i + moved,
|
|
519
|
+
end: first.compiled.start + i + moved + newImport.length
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
moved += diff;
|
|
523
|
+
i += oldImport.length;
|
|
524
|
+
}
|
|
525
|
+
map.unshift(...newMaps);
|
|
526
|
+
return content;
|
|
527
|
+
}
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/script/typescriptLoader.ts
|
|
530
|
+
/**
|
|
531
|
+
* Checks that a TypeScript module provides the API surface that the language
|
|
532
|
+
* server uses. Newer versions of TypeScript may drop or change the compiler
|
|
533
|
+
* internals (e.g. the TypeScript 7 native preview does not expose the
|
|
534
|
+
* compiler enums), in which case the bundled version is used instead
|
|
535
|
+
*/
|
|
536
|
+
function isCompatible(ts) {
|
|
537
|
+
const api = ts;
|
|
538
|
+
return !!api && typeof api.version === "string" && typeof api.createLanguageService === "function" && !!api.sys && typeof api.sys.getExecutingFilePath === "function" && !!api.ScriptTarget && !!api.ModuleKind && !!api.ModuleResolutionKind && !!api.SemanticClassificationFormat;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Loads the TypeScript module to use for the project containing the given
|
|
542
|
+
* file.
|
|
543
|
+
*
|
|
544
|
+
* Prefers the project's own installed version (resolved from the file's
|
|
545
|
+
* location, like Node would), so that language features match the user's
|
|
546
|
+
* build. Falls back to the version bundled with this package.
|
|
547
|
+
*/
|
|
548
|
+
function loadTypeScriptModule(filename) {
|
|
549
|
+
try {
|
|
550
|
+
const ts = createRequire(filename)("typescript");
|
|
551
|
+
if (isCompatible(ts)) {
|
|
552
|
+
console.log(`Using TypeScript ${ts.version} from the project`);
|
|
553
|
+
return ts;
|
|
554
|
+
}
|
|
555
|
+
console.log(`Project TypeScript ${ts.version} is not compatible with the language server, falling back to the bundled version`);
|
|
556
|
+
} catch {}
|
|
557
|
+
const ts = createRequire(typeof __filename === "string" ? __filename : import.meta.url)("typescript");
|
|
558
|
+
console.log(`Using bundled TypeScript ${ts.version}`);
|
|
559
|
+
return ts;
|
|
560
|
+
}
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/script/loadDocument.ts
|
|
563
|
+
let vts = {
|
|
564
|
+
ts: void 0,
|
|
565
|
+
env: void 0,
|
|
566
|
+
lang: void 0,
|
|
567
|
+
projectRoot: "",
|
|
568
|
+
configPath: void 0,
|
|
569
|
+
config: void 0,
|
|
570
|
+
virtualFiles: /* @__PURE__ */ new Map(),
|
|
571
|
+
virtualFileMaps: /* @__PURE__ */ new Map()
|
|
572
|
+
};
|
|
573
|
+
function loadDocument(document) {
|
|
574
|
+
const filename = url.fileURLToPath(document.uri);
|
|
575
|
+
const key = filename.replace(/\.torp$/, ".ts");
|
|
576
|
+
const text = document.getText();
|
|
577
|
+
loadTypeScriptEnv(filename, key);
|
|
578
|
+
const transformed = transformDocument(vts, filename, text);
|
|
579
|
+
if (!transformed.ok) return {
|
|
580
|
+
ok: false,
|
|
581
|
+
errors: transformed.errors
|
|
582
|
+
};
|
|
583
|
+
const { content, map } = transformed;
|
|
584
|
+
updateVirtualFile(key, content, filename, map);
|
|
585
|
+
return {
|
|
586
|
+
ok: true,
|
|
587
|
+
filename,
|
|
588
|
+
key,
|
|
589
|
+
text,
|
|
590
|
+
content,
|
|
591
|
+
map,
|
|
592
|
+
vts
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function loadTypeScriptEnv(filename, key) {
|
|
596
|
+
if (vts.env === void 0) {
|
|
597
|
+
vts.projectRoot = path.join(filename, ".");
|
|
598
|
+
while (vts.projectRoot && !fs.existsSync(path.join(vts.projectRoot, "node_modules"))) vts.projectRoot = path.join(vts.projectRoot, "..");
|
|
599
|
+
if (!vts.projectRoot) {
|
|
600
|
+
console.log("No project root found");
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
vts.ts = loadTypeScriptModule(filename);
|
|
604
|
+
vts.config = {
|
|
605
|
+
target: vts.ts.ScriptTarget.ES2022,
|
|
606
|
+
module: vts.ts.ModuleKind.ESNext,
|
|
607
|
+
moduleResolution: vts.ts.ModuleResolutionKind.Bundler,
|
|
608
|
+
esModuleInterop: true
|
|
609
|
+
};
|
|
610
|
+
try {
|
|
611
|
+
let fileConfig = loadTypeScriptConfig();
|
|
612
|
+
if (fileConfig?.options) vts.config = fileConfig.options;
|
|
613
|
+
} catch {
|
|
614
|
+
console.log("No tsconfig.json file found, using default");
|
|
615
|
+
}
|
|
616
|
+
vts.virtualFiles.set(key, "const x = 5;");
|
|
617
|
+
const tsLibDirectory = path.dirname(vts.ts.sys.getExecutingFilePath());
|
|
618
|
+
const system = tsvfs.createFSBackedSystem(vts.virtualFiles, vts.projectRoot, vts.ts, tsLibDirectory);
|
|
619
|
+
vts.env = tsvfs.createVirtualTypeScriptEnvironment(system, [key], vts.ts, vts.config);
|
|
620
|
+
vts.lang = vts.env.languageService;
|
|
621
|
+
console.log("Torpor type checking loaded");
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function updateVirtualFile(key, content, sourceFile, map) {
|
|
625
|
+
if (!vts.virtualFiles.has(key)) vts.env.createFile(key, content);
|
|
626
|
+
else vts.env.updateFile(key, content);
|
|
627
|
+
vts.virtualFiles.set(key, content);
|
|
628
|
+
vts.virtualFileMaps.set(key, {
|
|
629
|
+
sourceFile,
|
|
630
|
+
map
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
function loadTypeScriptConfig() {
|
|
634
|
+
const ts = vts.ts;
|
|
635
|
+
const configFileName = ts.findConfigFile(vts.projectRoot, (path) => ts.sys.fileExists(path));
|
|
636
|
+
if (configFileName) {
|
|
637
|
+
vts.configPath = path.dirname(configFileName);
|
|
638
|
+
const configFile = ts.readConfigFile(configFileName, (path) => ts.sys.readFile(path));
|
|
639
|
+
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.projectRoot);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/script/sourceSpanFromSourceRange.ts
|
|
644
|
+
function sourceSpanFromSourceRange(text, range) {
|
|
645
|
+
let start = 0;
|
|
646
|
+
let end = 0;
|
|
647
|
+
let line = 0;
|
|
648
|
+
for (let i = 0; i < text.length; i++) if (text[i] === "\n") {
|
|
649
|
+
line++;
|
|
650
|
+
if (line === range.start.line) start = i + range.start.character;
|
|
651
|
+
if (line === range.end.line) {
|
|
652
|
+
end = i + range.end.character;
|
|
653
|
+
break;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return {
|
|
657
|
+
start,
|
|
658
|
+
length: end - start
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
//#endregion
|
|
662
|
+
//#region src/script/doCodeAction.ts
|
|
663
|
+
function doCodeAction(document, range, context) {
|
|
664
|
+
try {
|
|
665
|
+
const transformed = loadDocument(document);
|
|
666
|
+
if (!transformed.ok) return [];
|
|
667
|
+
const { key, text, vts } = transformed;
|
|
668
|
+
const span = sourceSpanFromSourceRange(text, range);
|
|
669
|
+
const errorCodes = context.diagnostics.map((d) => Number(d.code));
|
|
670
|
+
return vts.lang.getCodeFixesAtPosition(key, span.start, span.start + span.length, errorCodes, {}, {}).map((f) => ({
|
|
671
|
+
title: f.description,
|
|
672
|
+
description: f.description,
|
|
673
|
+
changes: f.changes
|
|
674
|
+
}));
|
|
675
|
+
} catch (ex) {
|
|
676
|
+
console.log("CODE ACTIONS ERROR:", ex);
|
|
677
|
+
return [];
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region src/script/compiledIndexFromSourcePosition.ts
|
|
682
|
+
function compiledIndexFromSourcePosition(text, position, map) {
|
|
683
|
+
let index = 0;
|
|
684
|
+
let line = 0;
|
|
685
|
+
for (; index < text.length; index++) if (text[index] === "\n") {
|
|
686
|
+
line++;
|
|
687
|
+
if (line === position.line) {
|
|
688
|
+
index += position.character + 1;
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const mapped = map.find((m) => index >= m.source.start && index <= m.source.end);
|
|
693
|
+
if (!mapped) return -1;
|
|
694
|
+
return mapped.compiled.start + (index - mapped.source.start);
|
|
695
|
+
}
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region src/script/doComplete.ts
|
|
698
|
+
function doComplete(document, position, context) {
|
|
699
|
+
try {
|
|
700
|
+
const transformed = loadDocument(document);
|
|
701
|
+
if (!transformed.ok) return null;
|
|
702
|
+
const { key, text, map, vts: vfs } = transformed;
|
|
703
|
+
let compiledIndex = compiledIndexFromSourcePosition(text, position, map);
|
|
704
|
+
if (compiledIndex === -1) return [];
|
|
705
|
+
const completions = vfs.lang.getCompletionsAtPosition(key, compiledIndex, { triggerKind: context?.triggerKind });
|
|
706
|
+
if (!completions) return [];
|
|
707
|
+
return completions.entries.map((e) => {
|
|
708
|
+
if (context?.triggerCharacter === "$" && !e.name.startsWith("$")) return null;
|
|
709
|
+
let completion = {
|
|
710
|
+
label: e.name,
|
|
711
|
+
kind: e.kind,
|
|
712
|
+
insertText: e.insertText,
|
|
713
|
+
sortText: e.sortText,
|
|
714
|
+
commitCharacters: [
|
|
715
|
+
".",
|
|
716
|
+
",",
|
|
717
|
+
";",
|
|
718
|
+
"("
|
|
719
|
+
],
|
|
720
|
+
detail: e.detail,
|
|
721
|
+
documentation: e.documentation
|
|
722
|
+
};
|
|
723
|
+
if (e.name.startsWith("$")) completion.textEdit = {
|
|
724
|
+
range: {
|
|
725
|
+
start: {
|
|
726
|
+
line: position.line,
|
|
727
|
+
character: position.character - 1
|
|
728
|
+
},
|
|
729
|
+
end: {
|
|
730
|
+
line: position.line,
|
|
731
|
+
character: position.character - 1
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
newText: e.name
|
|
735
|
+
};
|
|
736
|
+
return completion;
|
|
737
|
+
}).filter((item) => Boolean(item));
|
|
738
|
+
} catch (ex) {
|
|
739
|
+
console.log("COMPLETE ERROR:", ex);
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region src/script/rangeFromSpan.ts
|
|
745
|
+
function rangeFromSpan(text, start, end) {
|
|
746
|
+
let line = 0;
|
|
747
|
+
let lastLineStart = 0;
|
|
748
|
+
let range = {
|
|
749
|
+
start: {
|
|
750
|
+
line: 0,
|
|
751
|
+
character: 0
|
|
752
|
+
},
|
|
753
|
+
end: {
|
|
754
|
+
line: 0,
|
|
755
|
+
character: 0
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
for (let i = 0; i < text.length; i++) {
|
|
759
|
+
if (text[i] === "\n") {
|
|
760
|
+
line++;
|
|
761
|
+
lastLineStart = i;
|
|
762
|
+
}
|
|
763
|
+
if (i === start) {
|
|
764
|
+
range.start.line = line;
|
|
765
|
+
range.start.character = start - lastLineStart - 1;
|
|
766
|
+
} else if (i === end) {
|
|
767
|
+
range.end.line = line;
|
|
768
|
+
range.end.character = end - lastLineStart - 1;
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
return range;
|
|
773
|
+
}
|
|
774
|
+
//#endregion
|
|
775
|
+
//#region src/script/sourceIndexFromCompiledIndex.ts
|
|
776
|
+
function sourceIndexFromCompiledIndex(index, map) {
|
|
777
|
+
const mapped = map.find((m) => index >= m.compiled.start && index <= m.compiled.end);
|
|
778
|
+
if (!mapped) return -1;
|
|
779
|
+
return mapped.source.start + (index - mapped.compiled.start);
|
|
780
|
+
}
|
|
781
|
+
//#endregion
|
|
782
|
+
//#region src/script/doDefinition.ts
|
|
783
|
+
function doDefinition(document, position) {
|
|
784
|
+
try {
|
|
785
|
+
const transformed = loadDocument(document);
|
|
786
|
+
if (!transformed.ok) return null;
|
|
787
|
+
const { filename, key, text, map, vts } = transformed;
|
|
788
|
+
let compiledIndex = compiledIndexFromSourcePosition(text, position, map);
|
|
789
|
+
if (compiledIndex === -1) return null;
|
|
790
|
+
const defs = vts.lang.getDefinitionAtPosition(key, compiledIndex);
|
|
791
|
+
if (!defs || !defs.length) return null;
|
|
792
|
+
let { fileName, textSpan } = defs[0];
|
|
793
|
+
let fileMap = vts.virtualFileMaps.get(fileName);
|
|
794
|
+
if (fileMap) fileName = fileMap.sourceFile;
|
|
795
|
+
const fileContent = fs.readFileSync(filename, "utf8");
|
|
796
|
+
const start = fileMap ? sourceIndexFromCompiledIndex(textSpan.start, fileMap.map) : textSpan.start;
|
|
797
|
+
const range = rangeFromSpan(fileContent, start, start + textSpan.length);
|
|
798
|
+
return {
|
|
799
|
+
uri: fileName,
|
|
800
|
+
range
|
|
801
|
+
};
|
|
802
|
+
} catch (ex) {
|
|
803
|
+
console.log("DEFINITION ERROR:", ex);
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region src/utils/previewer.ts
|
|
809
|
+
/**
|
|
810
|
+
* Joins a set of display parts into a string. This is our own version of
|
|
811
|
+
* TypeScript's displayPartsToString, so that the previewer does not need the
|
|
812
|
+
* TypeScript module at run time (the parts may come from the project's own
|
|
813
|
+
* TypeScript version)
|
|
814
|
+
*/
|
|
815
|
+
function displayPartsToString(parts) {
|
|
816
|
+
return typeof parts === "string" ? parts : (parts ?? []).map((part) => part.text).join("");
|
|
817
|
+
}
|
|
818
|
+
function replaceLinks(text) {
|
|
819
|
+
return text.replace(/\{@(link|linkplain|linkcode) (https?:\/\/[^ |}]+?)(?:[| ]([^{}\n]+?))?\}/gi, (_, tag, link, text) => {
|
|
820
|
+
switch (tag) {
|
|
821
|
+
case "linkcode": return `[\`${text ? text.trim() : link}\`](${link})`;
|
|
822
|
+
default: return `[${text ? text.trim() : link}](${link})`;
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
function processInlineTags(text) {
|
|
827
|
+
return replaceLinks(text);
|
|
828
|
+
}
|
|
829
|
+
function getTagBodyText(tag) {
|
|
830
|
+
if (!tag.text) return;
|
|
831
|
+
function makeCodeblock(text) {
|
|
832
|
+
if (text.match(/^\s*[~`]{3}/g)) return text;
|
|
833
|
+
return "```\n" + text + "\n```";
|
|
834
|
+
}
|
|
835
|
+
function makeExampleTag(text) {
|
|
836
|
+
const captionTagMatches = text.match(/<caption>(.*?)<\/caption>\s*(\r\n|\n)/);
|
|
837
|
+
if (captionTagMatches && captionTagMatches.index === 0) return captionTagMatches[1] + "\n\n" + makeCodeblock(text.substr(captionTagMatches[0].length));
|
|
838
|
+
else return makeCodeblock(text);
|
|
839
|
+
}
|
|
840
|
+
function makeEmailTag(text) {
|
|
841
|
+
const emailMatch = text.match(/(.+)\s<([-.\w]+@[-.\w]+)>/);
|
|
842
|
+
if (emailMatch === null) return text;
|
|
843
|
+
else return `${emailMatch[1]} ${emailMatch[2]}`;
|
|
844
|
+
}
|
|
845
|
+
switch (tag.name) {
|
|
846
|
+
case "example": return makeExampleTag(displayPartsToString(tag.text));
|
|
847
|
+
case "author": return makeEmailTag(displayPartsToString(tag.text));
|
|
848
|
+
case "default": return makeCodeblock(displayPartsToString(tag.text));
|
|
849
|
+
}
|
|
850
|
+
return processInlineTags(displayPartsToString(tag.text));
|
|
851
|
+
}
|
|
852
|
+
function getTagDocumentation(tag) {
|
|
853
|
+
function getWithType() {
|
|
854
|
+
const body = (displayPartsToString(tag.text) || "").split(/^(\S+)\s*-?\s*/);
|
|
855
|
+
if (body?.length === 3) {
|
|
856
|
+
const param = body[1];
|
|
857
|
+
const doc = body[2];
|
|
858
|
+
const label = `*@${tag.name}* \`${param}\``;
|
|
859
|
+
if (!doc) return label;
|
|
860
|
+
return label + (doc.match(/\r\n|\n/g) ? " \n" + processInlineTags(doc) : ` — ${processInlineTags(doc)}`);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
switch (tag.name) {
|
|
864
|
+
case "augments":
|
|
865
|
+
case "extends":
|
|
866
|
+
case "param":
|
|
867
|
+
case "template": return getWithType();
|
|
868
|
+
}
|
|
869
|
+
const label = `*@${tag.name}*`;
|
|
870
|
+
const text = getTagBodyText(tag);
|
|
871
|
+
if (!text) return label;
|
|
872
|
+
return label + (text.match(/\r\n|\n/g) ? " \n" + text : ` — ${text}`);
|
|
873
|
+
}
|
|
874
|
+
function plain(parts) {
|
|
875
|
+
return processInlineTags(displayPartsToString(parts));
|
|
876
|
+
}
|
|
877
|
+
function getMarkdownDocumentation(documentation, tags) {
|
|
878
|
+
let result = [];
|
|
879
|
+
if (documentation) result.push(plain(documentation));
|
|
880
|
+
if (tags) result = result.concat(tags.map(getTagDocumentation));
|
|
881
|
+
return result.filter(Boolean).join("\n\n");
|
|
882
|
+
}
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region src/script/doHover.ts
|
|
885
|
+
function doHover(document, position) {
|
|
886
|
+
try {
|
|
887
|
+
const transformed = loadDocument(document);
|
|
888
|
+
if (!transformed.ok) return null;
|
|
889
|
+
const { key, text, map, vts } = transformed;
|
|
890
|
+
let compiledIndex = compiledIndexFromSourcePosition(text, position, map);
|
|
891
|
+
if (compiledIndex === -1) return null;
|
|
892
|
+
const info = vts.lang.getQuickInfoAtPosition(key, compiledIndex);
|
|
893
|
+
if (!info) return null;
|
|
894
|
+
let declaration = vts.ts.displayPartsToString(info.displayParts);
|
|
895
|
+
const documentation = getMarkdownDocumentation(info.documentation, info.tags);
|
|
896
|
+
return { contents: [
|
|
897
|
+
"```typescript",
|
|
898
|
+
declaration,
|
|
899
|
+
"```"
|
|
900
|
+
].concat(documentation ? ["---", documentation] : []).join("\n") };
|
|
901
|
+
} catch (ex) {
|
|
902
|
+
console.log("HOVER ERROR:", ex);
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/script/doValidation.ts
|
|
908
|
+
function doValidation(document) {
|
|
909
|
+
try {
|
|
910
|
+
const transformed = loadDocument(document);
|
|
911
|
+
if (!transformed.ok) {
|
|
912
|
+
if (!transformed.ok) return transformed.errors.map((e) => {
|
|
913
|
+
return {
|
|
914
|
+
message: e.message,
|
|
915
|
+
range: {
|
|
916
|
+
start: {
|
|
917
|
+
line: e.startLine,
|
|
918
|
+
character: e.startChar
|
|
919
|
+
},
|
|
920
|
+
end: {
|
|
921
|
+
line: e.endLine,
|
|
922
|
+
character: e.endChar
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
const { key, text, content, map, vts } = transformed;
|
|
929
|
+
vts.lang.cleanupSemanticCache();
|
|
930
|
+
return [...vts.lang.getSemanticDiagnostics(key), ...vts.lang.getSyntacticDiagnostics(key)].map((d) => {
|
|
931
|
+
let start = d.start ?? 0;
|
|
932
|
+
let end = (d.start ?? 0) + (d.length ?? 0);
|
|
933
|
+
let mapped = map.find((m) => start >= m.compiled.start && end <= m.compiled.end);
|
|
934
|
+
let message = getMessageText(d);
|
|
935
|
+
if (message.startsWith("This import uses a '.ts' extension to resolve") || /Cannot find module '(.+?)\?raw'/.test(message)) {
|
|
936
|
+
mapped = void 0;
|
|
937
|
+
message = "!";
|
|
938
|
+
}
|
|
939
|
+
if (!mapped && message !== "!") {
|
|
940
|
+
console.log(`Error${!mapped ? " (unmapped)" : ""}:`, message);
|
|
941
|
+
const lineMap = d.file?.lineMap;
|
|
942
|
+
if (lineMap) {
|
|
943
|
+
const line = (lineMap.findIndex((l) => l > start) ?? 1) - 1;
|
|
944
|
+
const char = start - lineMap[line];
|
|
945
|
+
console.log(`(${line + 1}, ${char + 1}):`, content.split("\n")[line]);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (!mapped) return {
|
|
949
|
+
message,
|
|
950
|
+
range: {
|
|
951
|
+
start: {
|
|
952
|
+
line: 0,
|
|
953
|
+
character: 0
|
|
954
|
+
},
|
|
955
|
+
end: {
|
|
956
|
+
line: 0,
|
|
957
|
+
character: 0
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
let sourceStart = mapped.source.start + start - mapped.compiled.start;
|
|
962
|
+
let sourceEnd = mapped.source.start + end - mapped.compiled.start;
|
|
963
|
+
if (sourceStart > mapped.source.end) {
|
|
964
|
+
sourceStart = mapped.source.start;
|
|
965
|
+
sourceEnd = mapped.source.end;
|
|
966
|
+
}
|
|
967
|
+
if (sourceEnd > mapped.source.end) sourceEnd = mapped.source.end;
|
|
968
|
+
let lastLineStart = 0;
|
|
969
|
+
let startLine = 0;
|
|
970
|
+
for (let i = 0; i < sourceStart; i++) if (text[i] === "\n") {
|
|
971
|
+
lastLineStart = i;
|
|
972
|
+
startLine++;
|
|
973
|
+
}
|
|
974
|
+
let startChar = sourceStart - lastLineStart - 1;
|
|
975
|
+
let endLine = startLine;
|
|
976
|
+
for (let i = sourceStart; i < sourceEnd; i++) if (text[i] === "\n") {
|
|
977
|
+
lastLineStart = i;
|
|
978
|
+
endLine++;
|
|
979
|
+
}
|
|
980
|
+
let endChar = sourceEnd - lastLineStart - 1;
|
|
981
|
+
return {
|
|
982
|
+
range: {
|
|
983
|
+
start: {
|
|
984
|
+
line: startLine,
|
|
985
|
+
character: startChar
|
|
986
|
+
},
|
|
987
|
+
end: {
|
|
988
|
+
line: endLine,
|
|
989
|
+
character: endChar
|
|
990
|
+
}
|
|
991
|
+
},
|
|
992
|
+
code: d.code,
|
|
993
|
+
message
|
|
994
|
+
};
|
|
995
|
+
}).filter((d) => d.message !== "!");
|
|
996
|
+
} catch (ex) {
|
|
997
|
+
console.log("HOVER ERROR:", ex);
|
|
998
|
+
return [];
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
function getMessageText(d) {
|
|
1002
|
+
if (typeof d.messageText === "string") return d.messageText;
|
|
1003
|
+
else {
|
|
1004
|
+
let messages = [];
|
|
1005
|
+
getMessages(d.messageText, messages);
|
|
1006
|
+
return messages.map((m, i) => " ".repeat(i * 2) + m).join("\n");
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function getMessages(chain, messages) {
|
|
1010
|
+
messages.push(chain.messageText);
|
|
1011
|
+
if (chain.next !== void 0) for (let next of chain.next) getMessages(next, messages);
|
|
1012
|
+
}
|
|
1013
|
+
//#endregion
|
|
1014
|
+
//#region src/modes/scriptMode.ts
|
|
1015
|
+
function getScriptMode(_regions) {
|
|
1016
|
+
return {
|
|
1017
|
+
getId() {
|
|
1018
|
+
return "script";
|
|
1019
|
+
},
|
|
1020
|
+
doComplete,
|
|
1021
|
+
doCodeAction,
|
|
1022
|
+
doValidation,
|
|
1023
|
+
doHover,
|
|
1024
|
+
doDefinition,
|
|
1025
|
+
onDocumentRemoved(_document) {},
|
|
1026
|
+
dispose() {}
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/languageModes.ts
|
|
1031
|
+
var languageModes_exports = /* @__PURE__ */ __exportAll({ getLanguageModes: () => getLanguageModes });
|
|
1032
|
+
import * as import_vscode_html_languageservice from "vscode-html-languageservice";
|
|
1033
|
+
__reExport(languageModes_exports, import_vscode_html_languageservice);
|
|
1034
|
+
function getLanguageModes() {
|
|
1035
|
+
const htmlLanguageService = getLanguageService();
|
|
1036
|
+
const cssLanguageService = getCSSLanguageService();
|
|
1037
|
+
const documentRegions = getLanguageModelCache(10, 60, (document) => getDocumentRegions(document));
|
|
1038
|
+
let modelCaches = [];
|
|
1039
|
+
modelCaches.push(documentRegions);
|
|
1040
|
+
let modes = Object.create(null);
|
|
1041
|
+
modes["script"] = getScriptMode(documentRegions);
|
|
1042
|
+
modes["html"] = getHTMLMode(htmlLanguageService);
|
|
1043
|
+
modes["css"] = getCSSMode(cssLanguageService, documentRegions);
|
|
1044
|
+
return {
|
|
1045
|
+
getModeAtPosition(document, position) {
|
|
1046
|
+
const languageId = documentRegions.get(document).getLanguageAtPosition(position);
|
|
1047
|
+
if (languageId) return modes[languageId];
|
|
1048
|
+
},
|
|
1049
|
+
getModesInRange(document, range) {
|
|
1050
|
+
return documentRegions.get(document).getLanguageRanges(range).map((r) => {
|
|
1051
|
+
return {
|
|
1052
|
+
start: r.start,
|
|
1053
|
+
end: r.end,
|
|
1054
|
+
mode: r.languageId && modes[r.languageId],
|
|
1055
|
+
attributeValue: r.attributeValue
|
|
1056
|
+
};
|
|
1057
|
+
});
|
|
1058
|
+
},
|
|
1059
|
+
getAllModesInDocument(document) {
|
|
1060
|
+
const result = [];
|
|
1061
|
+
for (const languageId of documentRegions.get(document).getLanguagesInDocument()) {
|
|
1062
|
+
const mode = modes[languageId];
|
|
1063
|
+
if (mode) result.push(mode);
|
|
1064
|
+
}
|
|
1065
|
+
return result;
|
|
1066
|
+
},
|
|
1067
|
+
getAllModes() {
|
|
1068
|
+
const result = [];
|
|
1069
|
+
for (const languageId in modes) {
|
|
1070
|
+
const mode = modes[languageId];
|
|
1071
|
+
if (mode) result.push(mode);
|
|
1072
|
+
}
|
|
1073
|
+
return result;
|
|
1074
|
+
},
|
|
1075
|
+
getMode(languageId) {
|
|
1076
|
+
return modes[languageId];
|
|
1077
|
+
},
|
|
1078
|
+
onDocumentRemoved(document) {
|
|
1079
|
+
modelCaches.forEach((mc) => mc.onDocumentRemoved(document));
|
|
1080
|
+
for (const mode in modes) modes[mode].onDocumentRemoved(document);
|
|
1081
|
+
},
|
|
1082
|
+
dispose() {
|
|
1083
|
+
modelCaches.forEach((mc) => mc.dispose());
|
|
1084
|
+
modelCaches = [];
|
|
1085
|
+
for (const mode in modes) modes[mode].dispose();
|
|
1086
|
+
modes = {};
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
//#endregion
|
|
1091
|
+
//#region src/script/getDocumentSymbols.ts
|
|
1092
|
+
function getDocumentSymbols(document, _cancellationToken) {
|
|
1093
|
+
try {
|
|
1094
|
+
const transformed = loadDocument(document);
|
|
1095
|
+
if (!transformed.ok) return null;
|
|
1096
|
+
const { key, text, map, vts } = transformed;
|
|
1097
|
+
const tree = vts.lang.getNavigationTree(key);
|
|
1098
|
+
let symbols = [];
|
|
1099
|
+
collectSymbols(tree, symbols, text, map);
|
|
1100
|
+
return symbols;
|
|
1101
|
+
} catch (ex) {
|
|
1102
|
+
console.log("DOCUMENT SYMBOLS ERROR:", ex);
|
|
1103
|
+
return null;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
function collectSymbols(tree, symbols, text, map) {
|
|
1107
|
+
const span = tree.nameSpan ?? tree.spans[0];
|
|
1108
|
+
const sourceIndex = span ? sourceIndexFromCompiledIndex(span.start, map) : -1;
|
|
1109
|
+
if (sourceIndex !== -1) {
|
|
1110
|
+
const range = rangeFromSpan(text, sourceIndex, sourceIndex + span.length);
|
|
1111
|
+
const symbol = {
|
|
1112
|
+
name: tree.text,
|
|
1113
|
+
kind: symbolKindFromString(tree.kind),
|
|
1114
|
+
range,
|
|
1115
|
+
selectionRange: range
|
|
1116
|
+
};
|
|
1117
|
+
symbols.push(symbol);
|
|
1118
|
+
}
|
|
1119
|
+
if (tree.childItems) for (let child of tree.childItems) collectSymbols(child, symbols, text, map);
|
|
1120
|
+
}
|
|
1121
|
+
function symbolKindFromString(kind) {
|
|
1122
|
+
switch (kind) {
|
|
1123
|
+
case "module": return SymbolKind.Module;
|
|
1124
|
+
case "class": return SymbolKind.Class;
|
|
1125
|
+
case "local class": return SymbolKind.Class;
|
|
1126
|
+
case "interface": return SymbolKind.Interface;
|
|
1127
|
+
case "enum": return SymbolKind.Enum;
|
|
1128
|
+
case "enum member": return SymbolKind.Constant;
|
|
1129
|
+
case "var": return SymbolKind.Variable;
|
|
1130
|
+
case "local var": return SymbolKind.Variable;
|
|
1131
|
+
case "function": return SymbolKind.Function;
|
|
1132
|
+
case "local function": return SymbolKind.Function;
|
|
1133
|
+
case "method": return SymbolKind.Method;
|
|
1134
|
+
case "getter": return SymbolKind.Method;
|
|
1135
|
+
case "setter": return SymbolKind.Method;
|
|
1136
|
+
case "property": return SymbolKind.Property;
|
|
1137
|
+
case "constructor": return SymbolKind.Constructor;
|
|
1138
|
+
case "parameter": return SymbolKind.Variable;
|
|
1139
|
+
case "type parameter": return SymbolKind.Variable;
|
|
1140
|
+
case "alias": return SymbolKind.Variable;
|
|
1141
|
+
case "let": return SymbolKind.Variable;
|
|
1142
|
+
case "const": return SymbolKind.Constant;
|
|
1143
|
+
case "JSX attribute": return SymbolKind.Property;
|
|
1144
|
+
default: return SymbolKind.Variable;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/script/getImplementation.ts
|
|
1149
|
+
function getImplementation(document, position, _cancellationToken) {
|
|
1150
|
+
try {
|
|
1151
|
+
const transformed = loadDocument(document);
|
|
1152
|
+
if (!transformed.ok) return null;
|
|
1153
|
+
const { filename, key, text, map, vts } = transformed;
|
|
1154
|
+
const compiledIndex = compiledIndexFromSourcePosition(text, position, map);
|
|
1155
|
+
if (compiledIndex === -1) return null;
|
|
1156
|
+
const imps = vts.lang.getImplementationAtPosition(key, compiledIndex);
|
|
1157
|
+
if (!imps || !imps.length) return null;
|
|
1158
|
+
let { fileName, textSpan } = imps[0];
|
|
1159
|
+
let fileMap = vts.virtualFileMaps.get(fileName);
|
|
1160
|
+
if (fileMap) fileName = fileMap.sourceFile;
|
|
1161
|
+
const fileContent = fs.readFileSync(filename, "utf8");
|
|
1162
|
+
const start = fileMap ? sourceIndexFromCompiledIndex(textSpan.start, fileMap.map) : textSpan.start;
|
|
1163
|
+
const range = rangeFromSpan(fileContent, start, start + textSpan.length);
|
|
1164
|
+
return {
|
|
1165
|
+
uri: fileName,
|
|
1166
|
+
range
|
|
1167
|
+
};
|
|
1168
|
+
} catch (ex) {
|
|
1169
|
+
console.log("IMPLEMENTATION ERROR:", ex);
|
|
1170
|
+
return null;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
//#endregion
|
|
1174
|
+
//#region src/script/getSelectionRanges.ts
|
|
1175
|
+
function getSelectionRanges(document, _positions, _cancellationToken) {
|
|
1176
|
+
try {
|
|
1177
|
+
if (!loadDocument(document).ok) return null;
|
|
1178
|
+
return [];
|
|
1179
|
+
} catch (ex) {
|
|
1180
|
+
console.log("SELECTION RANGE ERROR:", ex);
|
|
1181
|
+
return null;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
//#endregion
|
|
1185
|
+
//#region src/script/getSemanticTokens.ts
|
|
1186
|
+
function getSemanticTokens(document, range, _cancellationToken) {
|
|
1187
|
+
try {
|
|
1188
|
+
const transformed = loadDocument(document);
|
|
1189
|
+
if (!transformed.ok) return null;
|
|
1190
|
+
const { key, text, content, map, vts } = transformed;
|
|
1191
|
+
const span = range ? sourceSpanFromSourceRange(text, range) : {
|
|
1192
|
+
start: 0,
|
|
1193
|
+
length: content.length
|
|
1194
|
+
};
|
|
1195
|
+
const { spans } = vts.lang.getEncodedSemanticClassifications(key, span, vts.ts.SemanticClassificationFormat.TwentyTwenty);
|
|
1196
|
+
let sourceSpans = [];
|
|
1197
|
+
for (let i = 0; i < spans.length;) {
|
|
1198
|
+
const start = spans[i++];
|
|
1199
|
+
const length = spans[i++];
|
|
1200
|
+
const tokenType = spans[i++];
|
|
1201
|
+
const sourceIndex = sourceIndexFromCompiledIndex(start, map);
|
|
1202
|
+
if (sourceIndex !== -1) sourceSpans.push(sourceIndex, length, tokenType);
|
|
1203
|
+
}
|
|
1204
|
+
return sourceSpans;
|
|
1205
|
+
} catch (ex) {
|
|
1206
|
+
console.log("SEMANTIC TOKENS ERROR:", ex);
|
|
1207
|
+
return null;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
//#endregion
|
|
1211
|
+
//#region src/server.ts
|
|
1212
|
+
/**
|
|
1213
|
+
* Starts the Torpor language server on the current process, wiring up all
|
|
1214
|
+
* handlers to a new connection.
|
|
1215
|
+
*
|
|
1216
|
+
* The transport (stdio, node-ipc or socket) is detected from the command
|
|
1217
|
+
* line arguments, with the `torpor-lsp` bin defaulting to stdio.
|
|
1218
|
+
*/
|
|
1219
|
+
function start() {
|
|
1220
|
+
const connection = createConnection(ProposedFeatures.all);
|
|
1221
|
+
const documents = new TextDocuments(TextDocument);
|
|
1222
|
+
let languageModes;
|
|
1223
|
+
connection.onInitialize((_params) => {
|
|
1224
|
+
languageModes = getLanguageModes();
|
|
1225
|
+
documents.onDidClose((e) => {
|
|
1226
|
+
languageModes.onDocumentRemoved(e.document);
|
|
1227
|
+
});
|
|
1228
|
+
connection.onShutdown(() => {
|
|
1229
|
+
languageModes.dispose();
|
|
1230
|
+
});
|
|
1231
|
+
return { capabilities: {
|
|
1232
|
+
textDocumentSync: TextDocumentSyncKind.Full,
|
|
1233
|
+
completionProvider: {
|
|
1234
|
+
resolveProvider: false,
|
|
1235
|
+
triggerCharacters: [".", "$"],
|
|
1236
|
+
completionItem: { labelDetailsSupport: true }
|
|
1237
|
+
},
|
|
1238
|
+
codeActionProvider: true,
|
|
1239
|
+
hoverProvider: true,
|
|
1240
|
+
definitionProvider: true,
|
|
1241
|
+
implementationProvider: true
|
|
1242
|
+
} };
|
|
1243
|
+
});
|
|
1244
|
+
connection.onDidChangeConfiguration((_change) => {
|
|
1245
|
+
documents.all().forEach((document) => void validateTextDocument(document));
|
|
1246
|
+
});
|
|
1247
|
+
documents.onDidChangeContent((change) => {
|
|
1248
|
+
validateTextDocument(change.document);
|
|
1249
|
+
});
|
|
1250
|
+
async function validateTextDocument(textDocument) {
|
|
1251
|
+
try {
|
|
1252
|
+
const version = textDocument.version;
|
|
1253
|
+
const diagnostics = [];
|
|
1254
|
+
if (textDocument.languageId === "torpor") {
|
|
1255
|
+
const modes = languageModes.getAllModesInDocument(textDocument);
|
|
1256
|
+
const latestTextDocument = documents.get(textDocument.uri);
|
|
1257
|
+
if (latestTextDocument && latestTextDocument.version === version) {
|
|
1258
|
+
modes.forEach((mode) => {
|
|
1259
|
+
if (mode.doValidation) mode.doValidation(latestTextDocument).forEach((d) => {
|
|
1260
|
+
diagnostics.push(d);
|
|
1261
|
+
});
|
|
1262
|
+
});
|
|
1263
|
+
connection.sendDiagnostics({
|
|
1264
|
+
uri: latestTextDocument.uri,
|
|
1265
|
+
diagnostics
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
} catch (e) {
|
|
1270
|
+
connection.console.error(`Error while validating ${textDocument.uri}`);
|
|
1271
|
+
connection.console.error(String(e));
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
connection.onCompletion(async (evt, _cancellationToken) => {
|
|
1275
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1276
|
+
if (!document) return null;
|
|
1277
|
+
const mode = languageModes.getModeAtPosition(document, evt.position);
|
|
1278
|
+
if (!mode || !mode.doComplete) return CompletionList.create();
|
|
1279
|
+
return mode.doComplete(document, evt.position, evt.context);
|
|
1280
|
+
});
|
|
1281
|
+
connection.onCodeAction(async (evt, _cancellationToken) => {
|
|
1282
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1283
|
+
if (!document) return null;
|
|
1284
|
+
const mode = languageModes.getModeAtPosition(document, evt.range.start);
|
|
1285
|
+
if (!mode || !mode.doCodeAction) return null;
|
|
1286
|
+
return mode.doCodeAction(document, evt.range, evt.context);
|
|
1287
|
+
});
|
|
1288
|
+
connection.onHover(async (evt, _cancellationToken) => {
|
|
1289
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1290
|
+
if (!document) return null;
|
|
1291
|
+
const mode = languageModes.getModeAtPosition(document, evt.position);
|
|
1292
|
+
if (!mode || !mode.doHover) return null;
|
|
1293
|
+
return mode.doHover(document, evt.position);
|
|
1294
|
+
});
|
|
1295
|
+
connection.onDefinition(async (evt, _cancellationToken) => {
|
|
1296
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1297
|
+
if (!document) return null;
|
|
1298
|
+
const mode = languageModes.getModeAtPosition(document, evt.position);
|
|
1299
|
+
if (!mode || !mode.doDefinition) return null;
|
|
1300
|
+
return mode.doDefinition(document, evt.position);
|
|
1301
|
+
});
|
|
1302
|
+
connection.onDocumentSymbol((evt, cancellationToken) => {
|
|
1303
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1304
|
+
if (!document) return null;
|
|
1305
|
+
return getDocumentSymbols(document, cancellationToken);
|
|
1306
|
+
});
|
|
1307
|
+
connection.onImplementation((evt, cancellationToken) => {
|
|
1308
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1309
|
+
if (!document) return null;
|
|
1310
|
+
return getImplementation(document, evt.position, cancellationToken);
|
|
1311
|
+
});
|
|
1312
|
+
connection.onSelectionRanges((evt, cancellationToken) => {
|
|
1313
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1314
|
+
if (!document) return null;
|
|
1315
|
+
return getSelectionRanges(document, evt.positions, cancellationToken);
|
|
1316
|
+
});
|
|
1317
|
+
connection.onRequest(SemanticTokensRequest.method, (evt, cancellationToken) => {
|
|
1318
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1319
|
+
if (!document) return null;
|
|
1320
|
+
return getSemanticTokens(document, void 0, cancellationToken);
|
|
1321
|
+
});
|
|
1322
|
+
connection.onRequest(SemanticTokensRangeRequest.method, (evt, cancellationToken) => {
|
|
1323
|
+
const document = documents.get(evt.textDocument.uri);
|
|
1324
|
+
if (!document) return null;
|
|
1325
|
+
return getSemanticTokens(document, evt.range, cancellationToken);
|
|
1326
|
+
});
|
|
1327
|
+
documents.listen(connection);
|
|
1328
|
+
connection.listen();
|
|
1329
|
+
}
|
|
1330
|
+
//#endregion
|
|
1331
|
+
export { start as t };
|
|
1332
|
+
|
|
1333
|
+
//# sourceMappingURL=src-DXbwpiIY.mjs.map
|