@volar/typescript 2.0.0-alpha.9 → 2.0.1
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/lib/documentRegistry.d.ts +2 -2
- package/lib/node/decorateLanguageService.d.ts +3 -3
- package/lib/node/decorateLanguageService.js +47 -42
- package/lib/node/decorateLanguageServiceHost.d.ts +4 -4
- package/lib/node/decorateLanguageServiceHost.js +18 -15
- package/lib/node/decorateProgram.d.ts +3 -3
- package/lib/node/decorateProgram.js +1 -1
- package/lib/node/dedupe.d.ts +1 -1
- package/lib/node/proxyCreateProgram.d.ts +2 -2
- package/lib/node/proxyCreateProgram.js +15 -13
- package/lib/node/transform.d.ts +7 -7
- package/lib/node/transform.js +12 -10
- package/lib/node/utils.d.ts +2 -2
- package/lib/node/utils.js +7 -10
- package/lib/protocol/createProject.d.ts +6 -3
- package/lib/protocol/createProject.js +129 -122
- package/lib/protocol/createSys.d.ts +3 -3
- package/lib/protocol/createSys.js +11 -11
- package/lib/quickstart/createAsyncLanguageServicePlugin.d.ts +3 -0
- package/lib/quickstart/createAsyncLanguageServicePlugin.js +89 -0
- package/lib/quickstart/createLanguageServicePlugin.d.ts +4 -0
- package/lib/quickstart/createLanguageServicePlugin.js +70 -0
- package/lib/{starters → quickstart}/runTsc.d.ts +2 -2
- package/lib/{starters → quickstart}/runTsc.js +1 -1
- package/lib/typescript/core.js +16 -8
- package/lib/typescript/path.js +42 -21
- package/lib/typescript/utilities.js +6 -3
- package/package.json +4 -4
- package/lib/protocol/getProgram.d.ts +0 -3
- package/lib/protocol/getProgram.js +0 -146
- package/lib/starters/createAsyncTSServerPlugin.d.ts +0 -3
- package/lib/starters/createAsyncTSServerPlugin.js +0 -82
- package/lib/starters/createTSServerPlugin.d.ts +0 -7
- package/lib/starters/createTSServerPlugin.js +0 -60
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as ts from 'typescript
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
2
|
import type { LanguagePlugin } from '@volar/language-core';
|
|
3
|
-
export declare let getLanguagePlugins: (ts: typeof import('typescript
|
|
3
|
+
export declare let getLanguagePlugins: (ts: typeof import('typescript'), options: ts.CreateProgramOptions) => LanguagePlugin[];
|
|
4
4
|
export declare function runTsc(tscPath: string, extensions: string[], _getLanguagePlugins: typeof getLanguagePlugins): void;
|
|
@@ -18,7 +18,7 @@ function runTsc(tscPath, extensions, _getLanguagePlugins) {
|
|
|
18
18
|
tsc = replace(tsc, /allSupportedExtensions = .*(?=;)/, s => s + `.concat([[${extsText}]])`);
|
|
19
19
|
// proxy createProgram
|
|
20
20
|
tsc = replace(tsc, /function createProgram\(.+\) {/, s => `var createProgram = require(${JSON.stringify(proxyApiPath)}).proxyCreateProgram(`
|
|
21
|
-
+ `new Proxy({}, { get(_target, p, _receiver) {return eval(p); } } ), `
|
|
21
|
+
+ `new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } ), `
|
|
22
22
|
+ `_createProgram, `
|
|
23
23
|
+ `[${extsText}], `
|
|
24
24
|
+ `require(${JSON.stringify(__filename)}).getLanguagePlugins`
|
package/lib/typescript/core.js
CHANGED
|
@@ -21,8 +21,9 @@ function every(array, callback) {
|
|
|
21
21
|
exports.every = every;
|
|
22
22
|
/** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */
|
|
23
23
|
function findIndex(array, predicate, startIndex) {
|
|
24
|
-
if (array === undefined)
|
|
24
|
+
if (array === undefined) {
|
|
25
25
|
return -1;
|
|
26
|
+
}
|
|
26
27
|
for (let i = startIndex ?? 0; i < array.length; i++) {
|
|
27
28
|
if (predicate(array[i], i)) {
|
|
28
29
|
return i;
|
|
@@ -125,10 +126,12 @@ exports.some = some;
|
|
|
125
126
|
// function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined;
|
|
126
127
|
// function append<T>(to: Push<T>, value: T | undefined): void;
|
|
127
128
|
function append(to, value) {
|
|
128
|
-
if (value === undefined)
|
|
129
|
+
if (value === undefined) {
|
|
129
130
|
return to;
|
|
130
|
-
|
|
131
|
+
}
|
|
132
|
+
if (to === undefined) {
|
|
131
133
|
return [value];
|
|
134
|
+
}
|
|
132
135
|
to.push(value);
|
|
133
136
|
return to;
|
|
134
137
|
}
|
|
@@ -140,10 +143,12 @@ function toOffset(array, offset) {
|
|
|
140
143
|
return offset < 0 ? array.length + offset : offset;
|
|
141
144
|
}
|
|
142
145
|
function addRange(to, from, start, end) {
|
|
143
|
-
if (from === undefined || from.length === 0)
|
|
146
|
+
if (from === undefined || from.length === 0) {
|
|
144
147
|
return to;
|
|
145
|
-
|
|
148
|
+
}
|
|
149
|
+
if (to === undefined) {
|
|
146
150
|
return from.slice(start, end);
|
|
151
|
+
}
|
|
147
152
|
start = start === undefined ? 0 : toOffset(from, start);
|
|
148
153
|
end = end === undefined ? from.length : toOffset(from, end);
|
|
149
154
|
for (let i = start; i < end && i < from.length; i++) {
|
|
@@ -273,12 +278,15 @@ function compareComparableValues(a, b) {
|
|
|
273
278
|
* lowercase (such as `ẞ` (German sharp capital s)).
|
|
274
279
|
*/
|
|
275
280
|
function compareStringsCaseInsensitive(a, b) {
|
|
276
|
-
if (a === b)
|
|
281
|
+
if (a === b) {
|
|
277
282
|
return 0 /* Comparison.EqualTo */;
|
|
278
|
-
|
|
283
|
+
}
|
|
284
|
+
if (a === undefined) {
|
|
279
285
|
return -1 /* Comparison.LessThan */;
|
|
280
|
-
|
|
286
|
+
}
|
|
287
|
+
if (b === undefined) {
|
|
281
288
|
return 1 /* Comparison.GreaterThan */;
|
|
289
|
+
}
|
|
282
290
|
a = a.toUpperCase();
|
|
283
291
|
b = b.toUpperCase();
|
|
284
292
|
return a < b ? -1 /* Comparison.LessThan */ : a > b ? 1 /* Comparison.GreaterThan */ : 0 /* Comparison.EqualTo */;
|
package/lib/typescript/path.js
CHANGED
|
@@ -56,12 +56,14 @@ function isVolumeCharacter(charCode) {
|
|
|
56
56
|
}
|
|
57
57
|
function getFileUrlVolumeSeparatorEnd(url, start) {
|
|
58
58
|
const ch0 = url.charCodeAt(start);
|
|
59
|
-
if (ch0 === 58 /* CharacterCodes.colon */)
|
|
59
|
+
if (ch0 === 58 /* CharacterCodes.colon */) {
|
|
60
60
|
return start + 1;
|
|
61
|
+
}
|
|
61
62
|
if (ch0 === 37 /* CharacterCodes.percent */ && url.charCodeAt(start + 1) === 51 /* CharacterCodes._3 */) {
|
|
62
63
|
const ch2 = url.charCodeAt(start + 2);
|
|
63
|
-
if (ch2 === 97 /* CharacterCodes.a */ || ch2 === 65 /* CharacterCodes.A */)
|
|
64
|
+
if (ch2 === 97 /* CharacterCodes.a */ || ch2 === 65 /* CharacterCodes.A */) {
|
|
64
65
|
return start + 3;
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
return -1;
|
|
67
69
|
}
|
|
@@ -70,25 +72,30 @@ function getFileUrlVolumeSeparatorEnd(url, start) {
|
|
|
70
72
|
* If the root is part of a URL, the twos-complement of the root length is returned.
|
|
71
73
|
*/
|
|
72
74
|
function getEncodedRootLength(path) {
|
|
73
|
-
if (!path)
|
|
75
|
+
if (!path) {
|
|
74
76
|
return 0;
|
|
77
|
+
}
|
|
75
78
|
const ch0 = path.charCodeAt(0);
|
|
76
79
|
// POSIX or UNC
|
|
77
80
|
if (ch0 === 47 /* CharacterCodes.slash */ || ch0 === 92 /* CharacterCodes.backslash */) {
|
|
78
|
-
if (path.charCodeAt(1) !== ch0)
|
|
81
|
+
if (path.charCodeAt(1) !== ch0) {
|
|
79
82
|
return 1; // POSIX: "/" (or non-normalized "\")
|
|
83
|
+
}
|
|
80
84
|
const p1 = path.indexOf(ch0 === 47 /* CharacterCodes.slash */ ? exports.directorySeparator : altDirectorySeparator, 2);
|
|
81
|
-
if (p1 < 0)
|
|
85
|
+
if (p1 < 0) {
|
|
82
86
|
return path.length; // UNC: "//server" or "\\server"
|
|
87
|
+
}
|
|
83
88
|
return p1 + 1; // UNC: "//server/" or "\\server\"
|
|
84
89
|
}
|
|
85
90
|
// DOS
|
|
86
91
|
if (isVolumeCharacter(ch0) && path.charCodeAt(1) === 58 /* CharacterCodes.colon */) {
|
|
87
92
|
const ch2 = path.charCodeAt(2);
|
|
88
|
-
if (ch2 === 47 /* CharacterCodes.slash */ || ch2 === 92 /* CharacterCodes.backslash */)
|
|
93
|
+
if (ch2 === 47 /* CharacterCodes.slash */ || ch2 === 92 /* CharacterCodes.backslash */) {
|
|
89
94
|
return 3; // DOS: "c:/" or "c:\"
|
|
90
|
-
|
|
95
|
+
}
|
|
96
|
+
if (path.length === 2) {
|
|
91
97
|
return 2; // DOS: "c:" (but not "c:d")
|
|
98
|
+
}
|
|
92
99
|
}
|
|
93
100
|
// URL
|
|
94
101
|
const schemeEnd = path.indexOf(urlSchemeSeparator);
|
|
@@ -156,8 +163,9 @@ function getDirectoryPath(path) {
|
|
|
156
163
|
path = normalizeSlashes(path);
|
|
157
164
|
// If the path provided is itself the root, then return it.
|
|
158
165
|
const rootLength = getRootLength(path);
|
|
159
|
-
if (rootLength === path.length)
|
|
166
|
+
if (rootLength === path.length) {
|
|
160
167
|
return path;
|
|
168
|
+
}
|
|
161
169
|
// return the leading portion of the path up to the last (non-terminal) directory separator
|
|
162
170
|
// but not including any trailing directory separator.
|
|
163
171
|
path = removeTrailingDirectorySeparator(path);
|
|
@@ -168,8 +176,9 @@ function getBaseFileName(path, extensions, ignoreCase) {
|
|
|
168
176
|
path = normalizeSlashes(path);
|
|
169
177
|
// if the path provided is itself the root, then it has not file name.
|
|
170
178
|
const rootLength = getRootLength(path);
|
|
171
|
-
if (rootLength === path.length)
|
|
179
|
+
if (rootLength === path.length) {
|
|
172
180
|
return "";
|
|
181
|
+
}
|
|
173
182
|
// return the trailing portion of the path starting after the last (non-terminal) directory
|
|
174
183
|
// separator but not including any trailing directory separator.
|
|
175
184
|
path = removeTrailingDirectorySeparator(path);
|
|
@@ -178,8 +187,9 @@ function getBaseFileName(path, extensions, ignoreCase) {
|
|
|
178
187
|
return extension ? name.slice(0, name.length - extension.length) : name;
|
|
179
188
|
}
|
|
180
189
|
function tryGetExtensionFromPath(path, extension, stringEqualityComparer) {
|
|
181
|
-
if (!(0, core_1.startsWith)(extension, "."))
|
|
190
|
+
if (!(0, core_1.startsWith)(extension, ".")) {
|
|
182
191
|
extension = "." + extension;
|
|
192
|
+
}
|
|
183
193
|
if (path.length >= extension.length && path.charCodeAt(path.length - extension.length) === 46 /* CharacterCodes.dot */) {
|
|
184
194
|
const pathExtension = path.slice(path.length - extension.length);
|
|
185
195
|
if (stringEqualityComparer(pathExtension, extension)) {
|
|
@@ -193,8 +203,9 @@ function getAnyExtensionFromPathWorker(path, extensions, stringEqualityComparer)
|
|
|
193
203
|
}
|
|
194
204
|
for (const extension of extensions) {
|
|
195
205
|
const result = tryGetExtensionFromPath(path, extension, stringEqualityComparer);
|
|
196
|
-
if (result)
|
|
206
|
+
if (result) {
|
|
197
207
|
return result;
|
|
208
|
+
}
|
|
198
209
|
}
|
|
199
210
|
return "";
|
|
200
211
|
}
|
|
@@ -214,8 +225,9 @@ function getAnyExtensionFromPath(path, extensions, ignoreCase) {
|
|
|
214
225
|
function pathComponents(path, rootLength) {
|
|
215
226
|
const root = path.substring(0, rootLength);
|
|
216
227
|
const rest = path.substring(rootLength).split(exports.directorySeparator);
|
|
217
|
-
if (rest.length && !(0, core_1.lastOrUndefined)(rest))
|
|
228
|
+
if (rest.length && !(0, core_1.lastOrUndefined)(rest)) {
|
|
218
229
|
rest.pop();
|
|
230
|
+
}
|
|
219
231
|
return [root, ...rest];
|
|
220
232
|
}
|
|
221
233
|
/**
|
|
@@ -262,8 +274,9 @@ function getPathComponents(path, currentDirectory = "") {
|
|
|
262
274
|
* ```
|
|
263
275
|
*/
|
|
264
276
|
function getPathFromPathComponents(pathComponents) {
|
|
265
|
-
if (pathComponents.length === 0)
|
|
277
|
+
if (pathComponents.length === 0) {
|
|
266
278
|
return "";
|
|
279
|
+
}
|
|
267
280
|
const root = pathComponents[0] && ensureTrailingDirectorySeparator(pathComponents[0]);
|
|
268
281
|
return root + pathComponents.slice(1).join(exports.directorySeparator);
|
|
269
282
|
}
|
|
@@ -281,15 +294,18 @@ function normalizeSlashes(path) {
|
|
|
281
294
|
* `"."` or `".."` entries in the path.
|
|
282
295
|
*/
|
|
283
296
|
function reducePathComponents(components) {
|
|
284
|
-
if (!(0, core_1.some)(components))
|
|
297
|
+
if (!(0, core_1.some)(components)) {
|
|
285
298
|
return [];
|
|
299
|
+
}
|
|
286
300
|
const reduced = [components[0]];
|
|
287
301
|
for (let i = 1; i < components.length; i++) {
|
|
288
302
|
const component = components[i];
|
|
289
|
-
if (!component)
|
|
303
|
+
if (!component) {
|
|
290
304
|
continue;
|
|
291
|
-
|
|
305
|
+
}
|
|
306
|
+
if (component === ".") {
|
|
292
307
|
continue;
|
|
308
|
+
}
|
|
293
309
|
if (component === "..") {
|
|
294
310
|
if (reduced.length > 1) {
|
|
295
311
|
if (reduced[reduced.length - 1] !== "..") {
|
|
@@ -297,8 +313,9 @@ function reducePathComponents(components) {
|
|
|
297
313
|
continue;
|
|
298
314
|
}
|
|
299
315
|
}
|
|
300
|
-
else if (reduced[0])
|
|
316
|
+
else if (reduced[0]) {
|
|
301
317
|
continue;
|
|
318
|
+
}
|
|
302
319
|
}
|
|
303
320
|
reduced.push(component);
|
|
304
321
|
}
|
|
@@ -323,11 +340,13 @@ function reducePathComponents(components) {
|
|
|
323
340
|
* ```
|
|
324
341
|
*/
|
|
325
342
|
function combinePaths(path, ...paths) {
|
|
326
|
-
if (path)
|
|
343
|
+
if (path) {
|
|
327
344
|
path = normalizeSlashes(path);
|
|
345
|
+
}
|
|
328
346
|
for (let relativePath of paths) {
|
|
329
|
-
if (!relativePath)
|
|
347
|
+
if (!relativePath) {
|
|
330
348
|
continue;
|
|
349
|
+
}
|
|
331
350
|
relativePath = normalizeSlashes(relativePath);
|
|
332
351
|
if (!path || getRootLength(relativePath) !== 0) {
|
|
333
352
|
path = relativePath;
|
|
@@ -396,10 +415,12 @@ function containsPath(parent, child, currentDirectory, ignoreCase) {
|
|
|
396
415
|
else if (typeof currentDirectory === "boolean") {
|
|
397
416
|
ignoreCase = currentDirectory;
|
|
398
417
|
}
|
|
399
|
-
if (parent === undefined || child === undefined)
|
|
418
|
+
if (parent === undefined || child === undefined) {
|
|
400
419
|
return false;
|
|
401
|
-
|
|
420
|
+
}
|
|
421
|
+
if (parent === child) {
|
|
402
422
|
return true;
|
|
423
|
+
}
|
|
403
424
|
const parentComponents = reducePathComponents(getPathComponents(parent));
|
|
404
425
|
const childComponents = reducePathComponents(getPathComponents(child));
|
|
405
426
|
if (childComponents.length < parentComponents.length) {
|
|
@@ -172,17 +172,20 @@ function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNa
|
|
|
172
172
|
return (0, core_1.flatten)(results);
|
|
173
173
|
function visitDirectory(path, absolutePath, depth) {
|
|
174
174
|
const canonicalPath = toCanonical(realpath(absolutePath));
|
|
175
|
-
if (visited.has(canonicalPath))
|
|
175
|
+
if (visited.has(canonicalPath)) {
|
|
176
176
|
return;
|
|
177
|
+
}
|
|
177
178
|
visited.set(canonicalPath, true);
|
|
178
179
|
const { files, directories } = getFileSystemEntries(path);
|
|
179
180
|
for (const current of (0, core_1.sort)(files, core_1.compareStringsCaseSensitive)) {
|
|
180
181
|
const name = (0, path_1.combinePaths)(path, current);
|
|
181
182
|
const absoluteName = (0, path_1.combinePaths)(absolutePath, current);
|
|
182
|
-
if (extensions && !(0, path_1.fileExtensionIsOneOf)(name, extensions))
|
|
183
|
+
if (extensions && !(0, path_1.fileExtensionIsOneOf)(name, extensions)) {
|
|
183
184
|
continue;
|
|
184
|
-
|
|
185
|
+
}
|
|
186
|
+
if (excludeRegex && excludeRegex.test(absoluteName)) {
|
|
185
187
|
continue;
|
|
188
|
+
}
|
|
186
189
|
if (!includeFileRegexes) {
|
|
187
190
|
results[0].push(name);
|
|
188
191
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"directory": "packages/typescript"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.0.
|
|
15
|
+
"@volar/language-core": "2.0.1",
|
|
16
16
|
"path-browserify": "^1.0.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "latest",
|
|
20
20
|
"@types/path-browserify": "latest",
|
|
21
|
-
"@volar/language-service": "2.0.
|
|
21
|
+
"@volar/language-service": "2.0.1"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "b1fbf6eed522624ccccfb17a8999edfbc1d8d9bb"
|
|
24
24
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type FileProvider } from '@volar/language-core';
|
|
2
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), files: FileProvider, ls: ts.LanguageService, sys: ts.System): ts.Program;
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProgram = void 0;
|
|
4
|
-
const language_core_1 = require("@volar/language-core");
|
|
5
|
-
function getProgram(ts, files, ls, sys) {
|
|
6
|
-
const proxy = {
|
|
7
|
-
getRootFileNames,
|
|
8
|
-
emit,
|
|
9
|
-
getSyntacticDiagnostics,
|
|
10
|
-
getSemanticDiagnostics,
|
|
11
|
-
getGlobalDiagnostics,
|
|
12
|
-
// @ts-expect-error
|
|
13
|
-
getBindAndCheckDiagnostics,
|
|
14
|
-
};
|
|
15
|
-
return new Proxy({}, {
|
|
16
|
-
get: (target, property) => {
|
|
17
|
-
if (property in proxy) {
|
|
18
|
-
return proxy[property];
|
|
19
|
-
}
|
|
20
|
-
const program = getProgram();
|
|
21
|
-
if (property in program) {
|
|
22
|
-
return program[property];
|
|
23
|
-
}
|
|
24
|
-
return target[property];
|
|
25
|
-
},
|
|
26
|
-
// #17
|
|
27
|
-
// notice: https://github.com/vuejs/language-tools/issues/2403
|
|
28
|
-
set: (target, property, newValue) => {
|
|
29
|
-
const program = getProgram();
|
|
30
|
-
target[property] = program[property] = newValue;
|
|
31
|
-
return true;
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
function getProgram() {
|
|
35
|
-
return ls.getProgram();
|
|
36
|
-
}
|
|
37
|
-
function getRootFileNames() {
|
|
38
|
-
return getProgram().getRootFileNames().filter(fileName => sys.fileExists?.(fileName));
|
|
39
|
-
}
|
|
40
|
-
// for vue-tsc --noEmit --watch
|
|
41
|
-
function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
|
|
42
|
-
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getBindAndCheckDiagnostics');
|
|
43
|
-
}
|
|
44
|
-
// for vue-tsc --noEmit
|
|
45
|
-
function getSyntacticDiagnostics(sourceFile, cancellationToken) {
|
|
46
|
-
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSyntacticDiagnostics');
|
|
47
|
-
}
|
|
48
|
-
function getSemanticDiagnostics(sourceFile, cancellationToken) {
|
|
49
|
-
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSemanticDiagnostics');
|
|
50
|
-
}
|
|
51
|
-
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
52
|
-
if (sourceFile) {
|
|
53
|
-
const [virtualFile, source] = files.getVirtualFile(sourceFile.fileName);
|
|
54
|
-
if (virtualFile && source) {
|
|
55
|
-
if (!virtualFile.mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)))
|
|
56
|
-
return [];
|
|
57
|
-
const errors = transformDiagnostics(ls.getProgram()?.[api](sourceFile, cancellationToken) ?? []);
|
|
58
|
-
return errors;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return transformDiagnostics(getProgram()[api](sourceFile, cancellationToken) ?? []);
|
|
62
|
-
}
|
|
63
|
-
function getGlobalDiagnostics(cancellationToken) {
|
|
64
|
-
return transformDiagnostics(getProgram().getGlobalDiagnostics(cancellationToken) ?? []);
|
|
65
|
-
}
|
|
66
|
-
function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
|
|
67
|
-
const scriptResult = getProgram().emit(targetSourceFile, (sys.writeFile ?? ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
68
|
-
return {
|
|
69
|
-
emitSkipped: scriptResult.emitSkipped,
|
|
70
|
-
emittedFiles: scriptResult.emittedFiles,
|
|
71
|
-
diagnostics: transformDiagnostics(scriptResult.diagnostics),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
// transform
|
|
75
|
-
function transformDiagnostics(diagnostics) {
|
|
76
|
-
const result = [];
|
|
77
|
-
for (const diagnostic of diagnostics) {
|
|
78
|
-
if (diagnostic.file !== undefined
|
|
79
|
-
&& diagnostic.start !== undefined
|
|
80
|
-
&& diagnostic.length !== undefined) {
|
|
81
|
-
const [virtualFile, source] = files.getVirtualFile(diagnostic.file.fileName);
|
|
82
|
-
if (virtualFile && source) {
|
|
83
|
-
if (sys.fileExists?.(source.fileName) === false)
|
|
84
|
-
continue;
|
|
85
|
-
for (const [_, [sourceSnapshot, map]] of files.getMaps(virtualFile)) {
|
|
86
|
-
if (sourceSnapshot !== source.snapshot)
|
|
87
|
-
continue;
|
|
88
|
-
for (const start of map.getSourceOffsets(diagnostic.start)) {
|
|
89
|
-
if (!(0, language_core_1.shouldReportDiagnostics)(start[1].data))
|
|
90
|
-
continue;
|
|
91
|
-
for (const end of map.getSourceOffsets(diagnostic.start + diagnostic.length)) {
|
|
92
|
-
if (!(0, language_core_1.shouldReportDiagnostics)(end[1].data))
|
|
93
|
-
continue;
|
|
94
|
-
onMapping(diagnostic, source.fileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
if (sys.fileExists?.(diagnostic.file.fileName) === false)
|
|
103
|
-
continue;
|
|
104
|
-
onMapping(diagnostic, diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, diagnostic.file.text);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (diagnostic.file === undefined) {
|
|
108
|
-
result.push(diagnostic);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
function onMapping(diagnostic, fileName, start, end, docText) {
|
|
113
|
-
let file = fileName === diagnostic.file?.fileName
|
|
114
|
-
? diagnostic.file
|
|
115
|
-
: undefined;
|
|
116
|
-
if (!file) {
|
|
117
|
-
if (docText === undefined) {
|
|
118
|
-
const snapshot = files.getSourceFile(fileName)?.snapshot;
|
|
119
|
-
if (snapshot) {
|
|
120
|
-
docText = snapshot.getText(0, snapshot.getLength());
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
file = ts.createSourceFile(fileName, docText, ts.ScriptTarget.Latest, undefined, ts.ScriptKind.Deferred);
|
|
125
|
-
// fix https://github.com/vuejs/language-tools/issues/2622 for TS 5.0
|
|
126
|
-
file.originalFileName = fileName;
|
|
127
|
-
file.path = fileName.toLowerCase();
|
|
128
|
-
file.resolvedPath = fileName.toLowerCase();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
const newDiagnostic = {
|
|
132
|
-
...diagnostic,
|
|
133
|
-
file,
|
|
134
|
-
start: start,
|
|
135
|
-
length: end - start,
|
|
136
|
-
};
|
|
137
|
-
const relatedInformation = diagnostic.relatedInformation;
|
|
138
|
-
if (relatedInformation) {
|
|
139
|
-
newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
|
|
140
|
-
}
|
|
141
|
-
result.push(newDiagnostic);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.getProgram = getProgram;
|
|
146
|
-
//# sourceMappingURL=getProgram.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import { LanguagePlugin } from '@volar/language-core';
|
|
3
|
-
export declare function createAsyncTSServerPlugin(extensions: string[], scriptKind: ts.ScriptKind, loadLanguagePlugins: (ts: typeof import('typescript/lib/tsserverlibrary'), info: ts.server.PluginCreateInfo) => Promise<LanguagePlugin[]>): ts.server.PluginModuleFactory;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAsyncTSServerPlugin = void 0;
|
|
4
|
-
const decorateLanguageService_1 = require("../node/decorateLanguageService");
|
|
5
|
-
const decorateLanguageServiceHost_1 = require("../node/decorateLanguageServiceHost");
|
|
6
|
-
const language_core_1 = require("@volar/language-core");
|
|
7
|
-
const createTSServerPlugin_1 = require("./createTSServerPlugin");
|
|
8
|
-
const externalFiles = new WeakMap();
|
|
9
|
-
function createAsyncTSServerPlugin(extensions, scriptKind, loadLanguagePlugins) {
|
|
10
|
-
return (modules) => {
|
|
11
|
-
const { typescript: ts } = modules;
|
|
12
|
-
const pluginModule = {
|
|
13
|
-
create(info) {
|
|
14
|
-
const emptySnapshot = ts.ScriptSnapshot.fromString('');
|
|
15
|
-
const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
|
|
16
|
-
const getScriptVersion = info.languageServiceHost.getScriptVersion.bind(info.languageServiceHost);
|
|
17
|
-
const getScriptKind = info.languageServiceHost.getScriptKind?.bind(info.languageServiceHost);
|
|
18
|
-
const getProjectVersion = info.languageServiceHost.getProjectVersion?.bind(info.languageServiceHost);
|
|
19
|
-
let initialized = false;
|
|
20
|
-
info.languageServiceHost.getScriptSnapshot = (fileName) => {
|
|
21
|
-
if (!initialized && extensions.some(ext => fileName.endsWith(ext))) {
|
|
22
|
-
return emptySnapshot;
|
|
23
|
-
}
|
|
24
|
-
return getScriptSnapshot(fileName);
|
|
25
|
-
};
|
|
26
|
-
info.languageServiceHost.getScriptVersion = (fileName) => {
|
|
27
|
-
if (!initialized && extensions.some(ext => fileName.endsWith(ext))) {
|
|
28
|
-
return 'initializing...';
|
|
29
|
-
}
|
|
30
|
-
return getScriptVersion(fileName);
|
|
31
|
-
};
|
|
32
|
-
if (getScriptKind) {
|
|
33
|
-
info.languageServiceHost.getScriptKind = (fileName) => {
|
|
34
|
-
if (!initialized && extensions.some(ext => fileName.endsWith(ext))) {
|
|
35
|
-
return scriptKind; // TODO: bypass upstream bug
|
|
36
|
-
}
|
|
37
|
-
return getScriptKind(fileName);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (getProjectVersion) {
|
|
41
|
-
info.languageServiceHost.getProjectVersion = () => {
|
|
42
|
-
if (!initialized) {
|
|
43
|
-
return getProjectVersion() + ',initializing...';
|
|
44
|
-
}
|
|
45
|
-
return getProjectVersion();
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
loadLanguagePlugins(ts, info).then(languagePlugins => {
|
|
49
|
-
const files = (0, language_core_1.createFileProvider)(languagePlugins, ts.sys.useCaseSensitiveFileNames, (fileName) => {
|
|
50
|
-
const snapshot = getScriptSnapshot(fileName);
|
|
51
|
-
if (snapshot) {
|
|
52
|
-
files.updateSourceFile(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
files.deleteSourceFile(fileName);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
(0, decorateLanguageService_1.decorateLanguageService)(files, info.languageService);
|
|
59
|
-
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(files, info.languageServiceHost, ts, extensions);
|
|
60
|
-
info.project.markAsDirty();
|
|
61
|
-
initialized = true;
|
|
62
|
-
});
|
|
63
|
-
return info.languageService;
|
|
64
|
-
},
|
|
65
|
-
getExternalFiles(project, updateLevel = 0) {
|
|
66
|
-
if (updateLevel >= (1)
|
|
67
|
-
|| !externalFiles.has(project)) {
|
|
68
|
-
const oldFiles = externalFiles.get(project);
|
|
69
|
-
const newFiles = (0, decorateLanguageServiceHost_1.searchExternalFiles)(ts, project, extensions);
|
|
70
|
-
externalFiles.set(project, newFiles);
|
|
71
|
-
if (oldFiles && !(0, createTSServerPlugin_1.arrayItemsEqual)(oldFiles, newFiles)) {
|
|
72
|
-
project.refreshDiagnostics();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return externalFiles.get(project);
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
return pluginModule;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
exports.createAsyncTSServerPlugin = createAsyncTSServerPlugin;
|
|
82
|
-
//# sourceMappingURL=createAsyncTSServerPlugin.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import { LanguagePlugin } from '@volar/language-core';
|
|
3
|
-
export declare function createTSServerPlugin(init: (ts: typeof import('typescript/lib/tsserverlibrary'), info: ts.server.PluginCreateInfo) => {
|
|
4
|
-
languagePlugins: LanguagePlugin[];
|
|
5
|
-
extensions: string[];
|
|
6
|
-
}): ts.server.PluginModuleFactory;
|
|
7
|
-
export declare function arrayItemsEqual(a: string[], b: string[]): boolean;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arrayItemsEqual = exports.createTSServerPlugin = void 0;
|
|
4
|
-
const decorateLanguageService_1 = require("../node/decorateLanguageService");
|
|
5
|
-
const decorateLanguageServiceHost_1 = require("../node/decorateLanguageServiceHost");
|
|
6
|
-
const language_core_1 = require("@volar/language-core");
|
|
7
|
-
const externalFiles = new WeakMap();
|
|
8
|
-
const projectExternalFileExtensions = new WeakMap();
|
|
9
|
-
function createTSServerPlugin(init) {
|
|
10
|
-
return (modules) => {
|
|
11
|
-
const { typescript: ts } = modules;
|
|
12
|
-
const pluginModule = {
|
|
13
|
-
create(info) {
|
|
14
|
-
const { languagePlugins, extensions } = init(ts, info);
|
|
15
|
-
projectExternalFileExtensions.set(info.project, extensions);
|
|
16
|
-
const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
|
|
17
|
-
const files = (0, language_core_1.createFileProvider)(languagePlugins, ts.sys.useCaseSensitiveFileNames, fileName => {
|
|
18
|
-
const snapshot = getScriptSnapshot(fileName);
|
|
19
|
-
if (snapshot) {
|
|
20
|
-
files.updateSourceFile(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
files.deleteSourceFile(fileName);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
(0, decorateLanguageService_1.decorateLanguageService)(files, info.languageService);
|
|
27
|
-
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(files, info.languageServiceHost, ts, extensions);
|
|
28
|
-
return info.languageService;
|
|
29
|
-
},
|
|
30
|
-
getExternalFiles(project, updateLevel = 0) {
|
|
31
|
-
if (updateLevel >= (1)
|
|
32
|
-
|| !externalFiles.has(project)) {
|
|
33
|
-
const oldFiles = externalFiles.get(project);
|
|
34
|
-
const newFiles = (0, decorateLanguageServiceHost_1.searchExternalFiles)(ts, project, projectExternalFileExtensions.get(project));
|
|
35
|
-
externalFiles.set(project, newFiles);
|
|
36
|
-
if (oldFiles && !arrayItemsEqual(oldFiles, newFiles)) {
|
|
37
|
-
project.refreshDiagnostics();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return externalFiles.get(project);
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
return pluginModule;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
exports.createTSServerPlugin = createTSServerPlugin;
|
|
47
|
-
function arrayItemsEqual(a, b) {
|
|
48
|
-
if (a.length !== b.length) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
const set = new Set(a);
|
|
52
|
-
for (const file of b) {
|
|
53
|
-
if (!set.has(file)) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
exports.arrayItemsEqual = arrayItemsEqual;
|
|
60
|
-
//# sourceMappingURL=createTSServerPlugin.js.map
|