@volar/typescript 1.6.8 → 1.7.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/out/dtsHost.d.ts +26 -0
- package/out/dtsHost.js +190 -0
- package/out/getProgram.d.ts +1 -1
- package/out/getProgram.js +12 -10
- package/out/index.d.ts +4 -8
- package/out/index.js +18 -285
- package/out/languageService.d.ts +9 -0
- package/out/languageService.js +291 -0
- package/out/languageServiceHost.d.ts +5 -0
- package/out/languageServiceHost.js +218 -0
- package/out/sys.d.ts +7 -0
- package/out/sys.js +322 -0
- package/out/typescript/core.d.ts +83 -0
- package/out/typescript/core.js +320 -0
- package/out/typescript/corePublic.d.ts +91 -0
- package/out/typescript/corePublic.js +51 -0
- package/out/typescript/path.d.ts +112 -0
- package/out/typescript/path.js +417 -0
- package/out/typescript/types.d.ts +129 -0
- package/out/typescript/types.js +3 -0
- package/out/typescript/utilities.d.ts +7 -0
- package/out/typescript/utilities.js +250 -0
- package/package.json +6 -3
package/out/sys.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSys = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const utilities_1 = require("./typescript/utilities");
|
|
7
|
+
const dtsHost_1 = require("./dtsHost");
|
|
8
|
+
let currentCwd = '';
|
|
9
|
+
function createSys(ctx, ts, env, dtsHost) {
|
|
10
|
+
let version = 0;
|
|
11
|
+
const rootPath = env.uriToFileName(env.rootUri.toString());
|
|
12
|
+
const sys = ts.sys;
|
|
13
|
+
const root = {
|
|
14
|
+
dirs: {},
|
|
15
|
+
files: {},
|
|
16
|
+
requested: false,
|
|
17
|
+
};
|
|
18
|
+
const promises = new Set();
|
|
19
|
+
const fileWatcher = env.onDidChangeWatchedFiles?.(({ changes }) => {
|
|
20
|
+
for (const change of changes) {
|
|
21
|
+
const fileName = env.uriToFileName(change.uri);
|
|
22
|
+
const dirName = path_1.posix.dirname(fileName);
|
|
23
|
+
const baseName = path_1.posix.basename(fileName);
|
|
24
|
+
const dir = getDir(dirName);
|
|
25
|
+
if (dir.files[baseName]) { // is requested file
|
|
26
|
+
version++;
|
|
27
|
+
if (change.type === 1) {
|
|
28
|
+
dir.files[baseName] = { exists: true };
|
|
29
|
+
}
|
|
30
|
+
else if (change.type === 2) {
|
|
31
|
+
dir.files[baseName] = { exists: true };
|
|
32
|
+
}
|
|
33
|
+
else if (change.type === 3) {
|
|
34
|
+
dir.files[baseName] = { exists: false };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
get version() {
|
|
41
|
+
return version;
|
|
42
|
+
},
|
|
43
|
+
dispose() {
|
|
44
|
+
fileWatcher?.dispose();
|
|
45
|
+
},
|
|
46
|
+
args: sys?.args ?? [],
|
|
47
|
+
newLine: sys?.newLine ?? '\n',
|
|
48
|
+
useCaseSensitiveFileNames: sys?.useCaseSensitiveFileNames ?? false,
|
|
49
|
+
realpath: sys?.realpath,
|
|
50
|
+
getExecutingFilePath: sys?.getExecutingFilePath ?? (() => rootPath + '/__fake__.js'),
|
|
51
|
+
getCurrentDirectory: () => rootPath,
|
|
52
|
+
getModifiedTime,
|
|
53
|
+
readFile,
|
|
54
|
+
readDirectory,
|
|
55
|
+
getDirectories,
|
|
56
|
+
resolvePath,
|
|
57
|
+
fileExists,
|
|
58
|
+
directoryExists,
|
|
59
|
+
async sync() {
|
|
60
|
+
while (promises.size) {
|
|
61
|
+
await Promise.all(promises);
|
|
62
|
+
}
|
|
63
|
+
return version;
|
|
64
|
+
},
|
|
65
|
+
// ignore
|
|
66
|
+
write: () => { },
|
|
67
|
+
writeFile: () => { },
|
|
68
|
+
createDirectory: () => { },
|
|
69
|
+
exit: () => { },
|
|
70
|
+
};
|
|
71
|
+
function resolvePath(fsPath) {
|
|
72
|
+
if (sys) {
|
|
73
|
+
if (currentCwd !== rootPath) {
|
|
74
|
+
currentCwd = rootPath;
|
|
75
|
+
// https://github.com/vuejs/language-tools/issues/2039
|
|
76
|
+
// https://github.com/vuejs/language-tools/issues/2234
|
|
77
|
+
if (sys.directoryExists(rootPath)) {
|
|
78
|
+
// https://github.com/vuejs/language-tools/issues/2480
|
|
79
|
+
try {
|
|
80
|
+
process.chdir(rootPath);
|
|
81
|
+
}
|
|
82
|
+
catch { }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return sys.resolvePath(fsPath);
|
|
86
|
+
}
|
|
87
|
+
return path_1.posix.resolve(fsPath);
|
|
88
|
+
}
|
|
89
|
+
function getModifiedTime(fileName) {
|
|
90
|
+
fileName = resolvePath(fileName);
|
|
91
|
+
const dirPath = path_1.posix.dirname(fileName);
|
|
92
|
+
const dir = getDir(dirPath);
|
|
93
|
+
const name = path_1.posix.basename(fileName);
|
|
94
|
+
const modifiedTime = dir.files[name]?.modifiedTime;
|
|
95
|
+
if (modifiedTime !== undefined) {
|
|
96
|
+
return new Date(modifiedTime);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function readFile(fileName, encoding) {
|
|
100
|
+
fileName = resolvePath(fileName);
|
|
101
|
+
const dirPath = path_1.posix.dirname(fileName);
|
|
102
|
+
const dir = getDir(dirPath);
|
|
103
|
+
const name = path_1.posix.basename(fileName);
|
|
104
|
+
readFileWorker(fileName, encoding, dir);
|
|
105
|
+
return dir.files[name]?.text;
|
|
106
|
+
}
|
|
107
|
+
function directoryExists(dirName) {
|
|
108
|
+
dirName = resolvePath(dirName);
|
|
109
|
+
const dir = getDir(dirName);
|
|
110
|
+
if (dirName === '/node_modules' && dtsHost) {
|
|
111
|
+
dir.exists = true;
|
|
112
|
+
}
|
|
113
|
+
else if (dirName.startsWith('/node_modules/') && dtsHost && !(0, dtsHost_1.getPackageNameOfDtsPath)(dirName)) {
|
|
114
|
+
dir.exists = true;
|
|
115
|
+
}
|
|
116
|
+
else if (dir.exists === undefined) {
|
|
117
|
+
dir.exists = false;
|
|
118
|
+
const result = dirName.startsWith('/node_modules/') && dtsHost
|
|
119
|
+
? dtsHost.stat(dirName)
|
|
120
|
+
: env.fs?.stat(env.fileNameToUri(dirName));
|
|
121
|
+
if (typeof result === 'object' && 'then' in result) {
|
|
122
|
+
const promise = result;
|
|
123
|
+
promises.add(promise);
|
|
124
|
+
result.then(result => {
|
|
125
|
+
promises.delete(promise);
|
|
126
|
+
dir.exists = result?.type === 2;
|
|
127
|
+
if (dir.exists) {
|
|
128
|
+
version++;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
dir.exists = result?.type === 2;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return dir.exists;
|
|
137
|
+
}
|
|
138
|
+
function fileExists(fileName) {
|
|
139
|
+
fileName = resolvePath(fileName);
|
|
140
|
+
const dirPath = path_1.posix.dirname(fileName);
|
|
141
|
+
const baseName = path_1.posix.basename(fileName);
|
|
142
|
+
const dir = getDir(dirPath);
|
|
143
|
+
const file = dir.files[baseName] ??= {};
|
|
144
|
+
if (file.exists === undefined) {
|
|
145
|
+
file.exists = false;
|
|
146
|
+
const result = fileName.startsWith('/node_modules/') && dtsHost
|
|
147
|
+
? dtsHost.stat(fileName)
|
|
148
|
+
: env.fs?.stat(env.fileNameToUri(fileName));
|
|
149
|
+
if (typeof result === 'object' && 'then' in result) {
|
|
150
|
+
const promise = result;
|
|
151
|
+
promises.add(promise);
|
|
152
|
+
result.then(result => {
|
|
153
|
+
promises.delete(promise);
|
|
154
|
+
file.exists = result?.type === 1 || result?.type === 64;
|
|
155
|
+
if (file.exists) {
|
|
156
|
+
const time = Date.now();
|
|
157
|
+
file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
|
|
158
|
+
version++;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
file.exists = result?.type === 1 || result?.type === 64;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return file.exists;
|
|
167
|
+
}
|
|
168
|
+
// for import path completion
|
|
169
|
+
function getDirectories(dirName) {
|
|
170
|
+
dirName = resolvePath(dirName);
|
|
171
|
+
readDirectoryWorker(dirName);
|
|
172
|
+
const dir = getDir(dirName);
|
|
173
|
+
return [...Object.entries(dir.dirs)].filter(([_, dir]) => dir.exists).map(([name]) => name);
|
|
174
|
+
}
|
|
175
|
+
function readDirectory(dirName, extensions, excludes, includes, depth) {
|
|
176
|
+
dirName = resolvePath(dirName);
|
|
177
|
+
let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, rootPath, depth, (dirPath) => {
|
|
178
|
+
dirPath = resolvePath(dirPath);
|
|
179
|
+
readDirectoryWorker(dirPath);
|
|
180
|
+
const dir = getDir(dirPath);
|
|
181
|
+
const virtualFiles = [];
|
|
182
|
+
if (ctx) {
|
|
183
|
+
for (const { root } of ctx.virtualFiles.allSources()) {
|
|
184
|
+
(0, language_core_1.forEachEmbeddedFile)(root, file => {
|
|
185
|
+
if (file.kind === language_core_1.FileKind.TypeScriptHostFile) {
|
|
186
|
+
const fileDirName = path_1.posix.dirname(file.fileName);
|
|
187
|
+
if (fileDirName.toLowerCase() === dirPath.toLowerCase()) {
|
|
188
|
+
virtualFiles.push(path_1.posix.basename(file.fileName));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
files: [
|
|
196
|
+
...[...Object.entries(dir.files)].filter(([_, file]) => file.exists).map(([name]) => name),
|
|
197
|
+
...virtualFiles,
|
|
198
|
+
],
|
|
199
|
+
directories: [...Object.entries(dir.dirs)].filter(([_, dir]) => dir.exists).map(([name]) => name),
|
|
200
|
+
};
|
|
201
|
+
}, sys?.realpath ? (path => sys.realpath(path)) : (path => path));
|
|
202
|
+
if (ctx) {
|
|
203
|
+
matches = matches.map(match => {
|
|
204
|
+
const [_, source] = ctx.virtualFiles.getVirtualFile(match);
|
|
205
|
+
if (source) {
|
|
206
|
+
return source.fileName;
|
|
207
|
+
}
|
|
208
|
+
return match;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return [...new Set(matches)];
|
|
212
|
+
}
|
|
213
|
+
function readFileWorker(fileName, encoding, dir) {
|
|
214
|
+
const name = path_1.posix.basename(fileName);
|
|
215
|
+
dir.files[name] ??= {};
|
|
216
|
+
const file = dir.files[name];
|
|
217
|
+
if (file.exists === false || file.requested) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
file.requested = true;
|
|
221
|
+
const uri = env.fileNameToUri(fileName);
|
|
222
|
+
const result = fileName.startsWith('/node_modules/') && dtsHost
|
|
223
|
+
? dtsHost.readFile(fileName)
|
|
224
|
+
: env.fs?.readFile(uri, encoding);
|
|
225
|
+
if (typeof result === 'object' && 'then' in result) {
|
|
226
|
+
const promise = result;
|
|
227
|
+
promises.add(promise);
|
|
228
|
+
result.then(result => {
|
|
229
|
+
promises.delete(promise);
|
|
230
|
+
if (result !== undefined) {
|
|
231
|
+
file.exists = true;
|
|
232
|
+
file.text = result;
|
|
233
|
+
const time = Date.now();
|
|
234
|
+
file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
|
|
235
|
+
version++;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
file.exists = false;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
else if (result !== undefined) {
|
|
243
|
+
file.exists = true;
|
|
244
|
+
file.text = result;
|
|
245
|
+
const time = Date.now();
|
|
246
|
+
file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
|
|
247
|
+
version++;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
file.exists = false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function readDirectoryWorker(dirName) {
|
|
254
|
+
const dir = getDir(dirName);
|
|
255
|
+
if (dir.requested) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
dir.requested = true;
|
|
259
|
+
const uri = env.fileNameToUri(dirName);
|
|
260
|
+
const result = dirName.startsWith('/node_modules/') && dtsHost
|
|
261
|
+
? dtsHost.readDirectory(dirName)
|
|
262
|
+
: env.fs?.readDirectory(uri);
|
|
263
|
+
if (typeof result === 'object' && 'then' in result) {
|
|
264
|
+
const promise = result;
|
|
265
|
+
promises.add(promise);
|
|
266
|
+
result.then((result) => {
|
|
267
|
+
promises.delete(promise);
|
|
268
|
+
onReadDirectoryResult(dir, result);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
onReadDirectoryResult(dir, result ?? []);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function onReadDirectoryResult(dir, result) {
|
|
276
|
+
for (const [name, fileType] of result) {
|
|
277
|
+
if (fileType === 1 || fileType === 64) {
|
|
278
|
+
dir.files[name] ??= {};
|
|
279
|
+
if (!dir.files[name].exists) {
|
|
280
|
+
dir.files[name].exists = true;
|
|
281
|
+
version++;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else if (fileType === 2) {
|
|
285
|
+
const childDir = getDirFromDir(dir, name);
|
|
286
|
+
if (!childDir.exists) {
|
|
287
|
+
childDir.exists = true;
|
|
288
|
+
version++;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function getDir(dirName) {
|
|
294
|
+
const dirNames = [];
|
|
295
|
+
let currentDirPath = dirName;
|
|
296
|
+
let currentDirName = path_1.posix.basename(currentDirPath);
|
|
297
|
+
while (currentDirName !== '') {
|
|
298
|
+
dirNames.push(currentDirName);
|
|
299
|
+
currentDirPath = path_1.posix.dirname(currentDirPath);
|
|
300
|
+
currentDirName = path_1.posix.basename(currentDirPath);
|
|
301
|
+
}
|
|
302
|
+
let currentDir = root;
|
|
303
|
+
for (let i = dirNames.length - 1; i >= 0; i--) {
|
|
304
|
+
const nextDirName = dirNames[i];
|
|
305
|
+
currentDir = getDirFromDir(currentDir, nextDirName);
|
|
306
|
+
}
|
|
307
|
+
return currentDir;
|
|
308
|
+
}
|
|
309
|
+
function getDirFromDir(dir, name) {
|
|
310
|
+
let target = dir.dirs[name];
|
|
311
|
+
if (!target) {
|
|
312
|
+
target = {
|
|
313
|
+
dirs: {},
|
|
314
|
+
files: {},
|
|
315
|
+
};
|
|
316
|
+
dir.dirs[name] = target;
|
|
317
|
+
}
|
|
318
|
+
return target;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
exports.createSys = createSys;
|
|
322
|
+
//# sourceMappingURL=sys.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Comparer, Comparison, SortedReadonlyArray } from "./corePublic";
|
|
2
|
+
/**
|
|
3
|
+
* Iterates through `array` by index and performs the callback on each element of array until the callback
|
|
4
|
+
* returns a falsey value, then returns false.
|
|
5
|
+
* If no such value is found, the callback is applied to each element of array and `true` is returned.
|
|
6
|
+
*/
|
|
7
|
+
export declare function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean;
|
|
8
|
+
/** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */
|
|
9
|
+
export declare function findIndex<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): number;
|
|
10
|
+
export declare function indexOfAnyCharCode(text: string, charCodes: readonly number[], start?: number): number;
|
|
11
|
+
export declare function map<T, U>(array: readonly T[], f: (x: T, i: number) => U): U[];
|
|
12
|
+
export declare function map<T, U>(array: readonly T[] | undefined, f: (x: T, i: number) => U): U[] | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Flattens an array containing a mix of array or non-array elements.
|
|
15
|
+
*
|
|
16
|
+
* @param array The array to flatten.
|
|
17
|
+
*/
|
|
18
|
+
export declare function flatten<T>(array: T[][] | readonly (T | readonly T[] | undefined)[]): T[];
|
|
19
|
+
/**
|
|
20
|
+
* Maps an array. If the mapped value is an array, it is spread into the result.
|
|
21
|
+
*
|
|
22
|
+
* @param array The array to map.
|
|
23
|
+
* @param mapfn The callback used to map the result into one or more values.
|
|
24
|
+
*/
|
|
25
|
+
export declare function flatMap<T, U>(array: readonly T[] | undefined, mapfn: (x: T, i: number) => U | readonly U[] | undefined): readonly U[];
|
|
26
|
+
export declare function some<T>(array: readonly T[] | undefined): array is readonly T[];
|
|
27
|
+
export declare function some<T>(array: readonly T[] | undefined, predicate: (value: T) => boolean): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a new sorted array.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sort<T>(array: readonly T[], comparer?: Comparer<T>): SortedReadonlyArray<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the last element of an array if non-empty, `undefined` otherwise.
|
|
34
|
+
*/
|
|
35
|
+
export declare function lastOrUndefined<T>(array: readonly T[] | undefined): T | undefined;
|
|
36
|
+
export declare function last<T>(array: readonly T[]): T;
|
|
37
|
+
/**
|
|
38
|
+
* Compare the equality of two strings using a case-sensitive ordinal comparison.
|
|
39
|
+
*
|
|
40
|
+
* Case-sensitive comparisons compare both strings one code-point at a time using the integer
|
|
41
|
+
* value of each code-point after applying `toUpperCase` to each string. We always map both
|
|
42
|
+
* strings to their upper-case form as some unicode characters do not properly round-trip to
|
|
43
|
+
* lowercase (such as `ẞ` (German sharp capital s)).
|
|
44
|
+
*/
|
|
45
|
+
export declare function equateStringsCaseInsensitive(a: string, b: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Compare the equality of two strings using a case-sensitive ordinal comparison.
|
|
48
|
+
*
|
|
49
|
+
* Case-sensitive comparisons compare both strings one code-point at a time using the
|
|
50
|
+
* integer value of each code-point.
|
|
51
|
+
*/
|
|
52
|
+
export declare function equateStringsCaseSensitive(a: string, b: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Compare two strings using a case-insensitive ordinal comparison.
|
|
55
|
+
*
|
|
56
|
+
* Ordinal comparisons are based on the difference between the unicode code points of both
|
|
57
|
+
* strings. Characters with multiple unicode representations are considered unequal. Ordinal
|
|
58
|
+
* comparisons provide predictable ordering, but place "a" after "B".
|
|
59
|
+
*
|
|
60
|
+
* Case-insensitive comparisons compare both strings one code-point at a time using the integer
|
|
61
|
+
* value of each code-point after applying `toUpperCase` to each string. We always map both
|
|
62
|
+
* strings to their upper-case form as some unicode characters do not properly round-trip to
|
|
63
|
+
* lowercase (such as `ẞ` (German sharp capital s)).
|
|
64
|
+
*/
|
|
65
|
+
declare function compareStringsCaseInsensitive(a: string, b: string): Comparison;
|
|
66
|
+
/**
|
|
67
|
+
* Compare two strings using a case-sensitive ordinal comparison.
|
|
68
|
+
*
|
|
69
|
+
* Ordinal comparisons are based on the difference between the unicode code points of both
|
|
70
|
+
* strings. Characters with multiple unicode representations are considered unequal. Ordinal
|
|
71
|
+
* comparisons provide predictable ordering, but place "a" after "B".
|
|
72
|
+
*
|
|
73
|
+
* Case-sensitive comparisons compare both strings one code-point at a time using the integer
|
|
74
|
+
* value of each code-point.
|
|
75
|
+
*/
|
|
76
|
+
export declare function compareStringsCaseSensitive(a: string | undefined, b: string | undefined): Comparison;
|
|
77
|
+
export declare function getStringComparer(ignoreCase?: boolean): typeof compareStringsCaseInsensitive;
|
|
78
|
+
export declare function endsWith(str: string, suffix: string): boolean;
|
|
79
|
+
export declare function stringContains(str: string, substring: string): boolean;
|
|
80
|
+
type GetCanonicalFileName = (fileName: string) => string;
|
|
81
|
+
export declare function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName;
|
|
82
|
+
export declare function startsWith(str: string, prefix: string): boolean;
|
|
83
|
+
export {};
|