@volar/typescript 1.11.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +5 -6
- package/index.js +5 -5
- package/lib/documentRegistry.d.ts +0 -1
- package/lib/node/decorateLanguageService.d.ts +3 -0
- package/lib/node/decorateLanguageService.js +660 -0
- package/lib/{serverPlugin.d.ts → node/decorateLanguageServiceHost.d.ts} +2 -7
- package/lib/{serverPlugin.js → node/decorateLanguageServiceHost.js} +21 -31
- package/lib/node/dedupe.d.ts +3 -0
- package/lib/node/dedupe.js +27 -0
- package/lib/protocol/createProject.d.ts +4 -0
- package/lib/protocol/createProject.js +321 -0
- package/lib/{sys.d.ts → protocol/createSys.d.ts} +1 -2
- package/lib/{sys.js → protocol/createSys.js} +8 -8
- package/lib/protocol/getProgram.d.ts +6 -0
- package/lib/{getProgram.js → protocol/getProgram.js} +17 -14
- package/lib/typescript/core.d.ts +0 -1
- package/lib/typescript/core.js +1 -0
- package/lib/typescript/corePublic.d.ts +0 -1
- package/lib/typescript/corePublic.js +1 -1
- package/lib/typescript/path.d.ts +0 -1
- package/lib/typescript/path.js +1 -0
- package/lib/typescript/types.d.ts +37 -38
- package/lib/typescript/utilities.d.ts +0 -1
- package/lib/typescript/utilities.js +1 -0
- package/package.json +4 -4
- package/lib/getProgram.d.ts +0 -4
- package/lib/languageService.d.ts +0 -4
- package/lib/languageService.js +0 -303
- package/lib/languageServiceHost.d.ts +0 -6
- package/lib/languageServiceHost.js +0 -296
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.searchExternalFiles = exports.decorateLanguageServiceHost = void 0;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const language_service_1 = require("@volar/language-service");
|
|
5
6
|
function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts) {
|
|
6
7
|
let extraProjectVersion = 0;
|
|
7
8
|
const scripts = new Map();
|
|
@@ -70,18 +71,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
|
|
|
70
71
|
updateScript(fileName);
|
|
71
72
|
const script = scripts.get(fileName);
|
|
72
73
|
if (script) {
|
|
73
|
-
|
|
74
|
-
return ts.ScriptKind.JS;
|
|
75
|
-
}
|
|
76
|
-
if (script.extension.endsWith('.jsx')) {
|
|
77
|
-
return ts.ScriptKind.JSX;
|
|
78
|
-
}
|
|
79
|
-
if (script.extension.endsWith('.ts')) {
|
|
80
|
-
return ts.ScriptKind.TS;
|
|
81
|
-
}
|
|
82
|
-
if (script.extension.endsWith('.tsx')) {
|
|
83
|
-
return ts.ScriptKind.TSX;
|
|
84
|
-
}
|
|
74
|
+
return script.kind;
|
|
85
75
|
}
|
|
86
76
|
return ts.ScriptKind.Deferred;
|
|
87
77
|
}
|
|
@@ -120,32 +110,36 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
|
|
|
120
110
|
function updateScript(fileName) {
|
|
121
111
|
const version = languageServiceHost.getScriptVersion(fileName);
|
|
122
112
|
if (version !== scripts.get(fileName)?.version) {
|
|
123
|
-
const text = languageServiceHost.readFile(fileName);
|
|
124
|
-
let snapshot;
|
|
125
113
|
let extension = '.ts';
|
|
126
|
-
|
|
114
|
+
let snapshotSnapshot;
|
|
115
|
+
let scriptKind = ts.ScriptKind.TS;
|
|
116
|
+
const snapshot = getScriptSnapshot(fileName);
|
|
117
|
+
if (snapshot) {
|
|
127
118
|
extraProjectVersion++;
|
|
128
|
-
const
|
|
129
|
-
if (virtualFile) {
|
|
119
|
+
const sourceFile = virtualFiles.updateSourceFile(fileName, snapshot, (0, language_service_1.resolveCommonLanguageId)(fileName));
|
|
120
|
+
if (sourceFile.virtualFile) {
|
|
121
|
+
const text = snapshot.getText(0, snapshot.getLength());
|
|
130
122
|
let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
|
|
131
|
-
(0, language_core_1.forEachEmbeddedFile)(virtualFile
|
|
132
|
-
const ext = file.
|
|
133
|
-
if (file.
|
|
123
|
+
for (const file of (0, language_core_1.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
|
|
124
|
+
const ext = file.id.substring(fileName.length);
|
|
125
|
+
if (file.typescript && (ext === '.d.ts' || ext.match(/^\.(js|ts)x?$/))) {
|
|
134
126
|
extension = ext;
|
|
127
|
+
scriptKind = file.typescript.scriptKind;
|
|
135
128
|
patchedText += file.snapshot.getText(0, file.snapshot.getLength());
|
|
136
129
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
130
|
+
}
|
|
131
|
+
snapshotSnapshot = ts.ScriptSnapshot.fromString(patchedText);
|
|
139
132
|
}
|
|
140
133
|
}
|
|
141
|
-
else if (virtualFiles.
|
|
134
|
+
else if (virtualFiles.getSourceFile(fileName)) {
|
|
142
135
|
extraProjectVersion++;
|
|
143
|
-
virtualFiles.
|
|
136
|
+
virtualFiles.deleteSourceFile(fileName);
|
|
144
137
|
}
|
|
145
138
|
scripts.set(fileName, {
|
|
146
139
|
version,
|
|
147
|
-
snapshot,
|
|
148
140
|
extension,
|
|
141
|
+
snapshot: snapshotSnapshot,
|
|
142
|
+
kind: scriptKind,
|
|
149
143
|
});
|
|
150
144
|
}
|
|
151
145
|
return scripts.get(fileName);
|
|
@@ -171,8 +165,4 @@ function searchExternalFiles(ts, project, exts) {
|
|
|
171
165
|
return parsed.fileNames;
|
|
172
166
|
}
|
|
173
167
|
exports.searchExternalFiles = searchExternalFiles;
|
|
174
|
-
|
|
175
|
-
* @deprecated use `searchExternalFiles` instead
|
|
176
|
-
*/
|
|
177
|
-
exports.getExternalFiles = searchExternalFiles;
|
|
178
|
-
//# sourceMappingURL=serverPlugin.js.map
|
|
168
|
+
//# sourceMappingURL=decorateLanguageServiceHost.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dedupeDocumentSpans = exports.dedupeReferencedSymbols = void 0;
|
|
4
|
+
function dedupeReferencedSymbols(items) {
|
|
5
|
+
return dedupe(items, item => [
|
|
6
|
+
item.definition.fileName,
|
|
7
|
+
item.definition.textSpan.start,
|
|
8
|
+
item.definition.textSpan.length,
|
|
9
|
+
].join(':'));
|
|
10
|
+
}
|
|
11
|
+
exports.dedupeReferencedSymbols = dedupeReferencedSymbols;
|
|
12
|
+
function dedupeDocumentSpans(items) {
|
|
13
|
+
return dedupe(items, item => [
|
|
14
|
+
item.fileName,
|
|
15
|
+
item.textSpan.start,
|
|
16
|
+
item.textSpan.length,
|
|
17
|
+
].join(':'));
|
|
18
|
+
}
|
|
19
|
+
exports.dedupeDocumentSpans = dedupeDocumentSpans;
|
|
20
|
+
function dedupe(items, getKey) {
|
|
21
|
+
const map = new Map();
|
|
22
|
+
for (const item of items.reverse()) {
|
|
23
|
+
map.set(getKey(item), item);
|
|
24
|
+
}
|
|
25
|
+
return [...map.values()];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=dedupe.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LanguagePlugin, Language, TypeScriptProjectHost } from '@volar/language-core';
|
|
2
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import type { createSys } from './createSys';
|
|
4
|
+
export declare function createLanguage(ts: typeof import('typescript/lib/tsserverlibrary'), sys: ReturnType<typeof createSys> | ts.System, languages: LanguagePlugin<any>[], configFileName: string | undefined, projectHost: TypeScriptProjectHost): Language;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLanguage = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const language_core_2 = require("@volar/language-core");
|
|
6
|
+
const path = require("path-browserify");
|
|
7
|
+
const utilities_1 = require("../typescript/utilities");
|
|
8
|
+
const scriptVersions = new Map();
|
|
9
|
+
const fsFileSnapshots = new Map();
|
|
10
|
+
function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
11
|
+
const files = (0, language_core_1.createFileProvider)(languages, sys.useCaseSensitiveFileNames, (id) => {
|
|
12
|
+
const fileName = projectHost.getFileName(id);
|
|
13
|
+
// opened files
|
|
14
|
+
let snapshot = projectHost.getScriptSnapshot(fileName);
|
|
15
|
+
if (!snapshot) {
|
|
16
|
+
// fs files
|
|
17
|
+
const cache = fsFileSnapshots.get(fileName);
|
|
18
|
+
const modifiedTime = sys.getModifiedTime?.(fileName)?.valueOf();
|
|
19
|
+
if (!cache || cache[0] !== modifiedTime) {
|
|
20
|
+
if (sys.fileExists(fileName)) {
|
|
21
|
+
const text = sys.readFile(fileName);
|
|
22
|
+
const snapshot = text !== undefined ? ts.ScriptSnapshot.fromString(text) : undefined;
|
|
23
|
+
fsFileSnapshots.set(fileName, [modifiedTime, snapshot]);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
fsFileSnapshots.set(fileName, [modifiedTime, undefined]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
snapshot = fsFileSnapshots.get(fileName)?.[1];
|
|
30
|
+
}
|
|
31
|
+
if (snapshot) {
|
|
32
|
+
files.updateSourceFile(id, snapshot, projectHost.getLanguageId(id));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
files.deleteSourceFile(id);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
let languageServiceHost = createLanguageServiceHost();
|
|
39
|
+
for (const language of languages) {
|
|
40
|
+
if (language.typescript?.resolveLanguageServiceHost) {
|
|
41
|
+
languageServiceHost = language.typescript.resolveLanguageServiceHost(languageServiceHost);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (languages.some(language => language.typescript?.resolveModuleName)) {
|
|
45
|
+
// TODO: can this share between monorepo packages?
|
|
46
|
+
const moduleCache = ts.createModuleResolutionCache(languageServiceHost.getCurrentDirectory(), languageServiceHost.useCaseSensitiveFileNames ? s => s : s => s.toLowerCase(), languageServiceHost.getCompilationSettings());
|
|
47
|
+
let lastSysVersion = 'version' in sys ? sys.version : undefined;
|
|
48
|
+
languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, sourceFile) => {
|
|
49
|
+
if ('version' in sys && lastSysVersion !== sys.version) {
|
|
50
|
+
lastSysVersion = sys.version;
|
|
51
|
+
moduleCache.clear();
|
|
52
|
+
}
|
|
53
|
+
return moduleLiterals.map((moduleLiteral) => {
|
|
54
|
+
let moduleName = moduleLiteral.text;
|
|
55
|
+
for (const language of languages) {
|
|
56
|
+
if (language.typescript?.resolveModuleName) {
|
|
57
|
+
moduleName = language.typescript.resolveModuleName(moduleName, sourceFile.impliedNodeFormat) ?? moduleName;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return ts.resolveModuleName(moduleName, containingFile, options, languageServiceHost, moduleCache, redirectedReference, sourceFile.impliedNodeFormat);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
languageServiceHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options, sourceFile) => {
|
|
64
|
+
if ('version' in sys && lastSysVersion !== sys.version) {
|
|
65
|
+
lastSysVersion = sys.version;
|
|
66
|
+
moduleCache.clear();
|
|
67
|
+
}
|
|
68
|
+
return moduleNames.map((moduleName) => {
|
|
69
|
+
for (const language of languages) {
|
|
70
|
+
if (language.typescript?.resolveModuleName) {
|
|
71
|
+
moduleName = language.typescript.resolveModuleName(moduleName, sourceFile?.impliedNodeFormat) ?? moduleName;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return ts.resolveModuleName(moduleName, containingFile, options, languageServiceHost, moduleCache, redirectedReference, sourceFile?.impliedNodeFormat).resolvedModule;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
files,
|
|
80
|
+
typescript: {
|
|
81
|
+
configFileName,
|
|
82
|
+
sys,
|
|
83
|
+
projectHost,
|
|
84
|
+
languageServiceHost,
|
|
85
|
+
synchronizeFileSystem: 'sync' in sys ? () => sys.sync() : undefined,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
function createLanguageServiceHost() {
|
|
89
|
+
let lastProjectVersion;
|
|
90
|
+
let tsProjectVersion = 0;
|
|
91
|
+
let tsFileRegistry = new language_core_1.FileMap(sys.useCaseSensitiveFileNames);
|
|
92
|
+
let lastTsVirtualFileSnapshots = new Set();
|
|
93
|
+
let lastOtherVirtualFileSnapshots = new Set();
|
|
94
|
+
const languageServiceHost = {
|
|
95
|
+
...sys,
|
|
96
|
+
getCurrentDirectory: projectHost.getCurrentDirectory,
|
|
97
|
+
getCompilationSettings: projectHost.getCompilationSettings,
|
|
98
|
+
getCancellationToken: projectHost.getCancellationToken,
|
|
99
|
+
getLocalizedDiagnosticMessages: projectHost.getLocalizedDiagnosticMessages,
|
|
100
|
+
getProjectReferences: projectHost.getProjectReferences,
|
|
101
|
+
getDefaultLibFileName: (options) => {
|
|
102
|
+
try {
|
|
103
|
+
return ts.getDefaultLibFilePath(options);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// web
|
|
107
|
+
return `/node_modules/typescript/lib/${ts.getDefaultLibFileName(options)}`;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
useCaseSensitiveFileNames() {
|
|
111
|
+
return sys.useCaseSensitiveFileNames;
|
|
112
|
+
},
|
|
113
|
+
getNewLine() {
|
|
114
|
+
return sys.newLine;
|
|
115
|
+
},
|
|
116
|
+
getTypeRootsVersion: () => {
|
|
117
|
+
return 'version' in sys ? sys.version : -1; // TODO: only update for /node_modules changes?
|
|
118
|
+
},
|
|
119
|
+
// need sync
|
|
120
|
+
getDirectories(dirName) {
|
|
121
|
+
syncProject();
|
|
122
|
+
return [...new Set([
|
|
123
|
+
...getVirtualFileDirectories(dirName),
|
|
124
|
+
...sys.getDirectories(dirName),
|
|
125
|
+
])];
|
|
126
|
+
},
|
|
127
|
+
readFile(fileName) {
|
|
128
|
+
syncSourceFile(fileName);
|
|
129
|
+
const snapshot = getScriptSnapshot(fileName);
|
|
130
|
+
if (snapshot) {
|
|
131
|
+
return snapshot.getText(0, snapshot.getLength());
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
fileExists(fileName) {
|
|
135
|
+
syncSourceFile(fileName);
|
|
136
|
+
return getScriptVersion(fileName) !== '';
|
|
137
|
+
},
|
|
138
|
+
readDirectory(dirName, extensions, excludes, includes, depth) {
|
|
139
|
+
syncProject();
|
|
140
|
+
let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, projectHost.getCurrentDirectory(), depth, (dirPath) => {
|
|
141
|
+
const files = [];
|
|
142
|
+
for (const fileName of tsFileRegistry.keys()) {
|
|
143
|
+
if (fileName.toLowerCase().startsWith(dirPath.toLowerCase())) {
|
|
144
|
+
const baseName = fileName.substring(dirPath.length);
|
|
145
|
+
if (baseName.indexOf('/') === -1) {
|
|
146
|
+
files.push(baseName);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
files,
|
|
152
|
+
directories: getVirtualFileDirectories(dirPath),
|
|
153
|
+
};
|
|
154
|
+
}, sys?.realpath ? (path => sys.realpath(path)) : (path => path));
|
|
155
|
+
matches = matches.map(match => {
|
|
156
|
+
const [_, source] = files.getVirtualFile(projectHost.getFileId(match));
|
|
157
|
+
if (source) {
|
|
158
|
+
return projectHost.getFileName(source.id);
|
|
159
|
+
}
|
|
160
|
+
return match;
|
|
161
|
+
});
|
|
162
|
+
return [...new Set([
|
|
163
|
+
...matches,
|
|
164
|
+
...sys.readDirectory(dirName, extensions, excludes, includes, depth),
|
|
165
|
+
])];
|
|
166
|
+
},
|
|
167
|
+
getProjectVersion() {
|
|
168
|
+
syncProject();
|
|
169
|
+
return tsProjectVersion + ('version' in sys ? `:${sys.version}` : '');
|
|
170
|
+
},
|
|
171
|
+
getScriptFileNames() {
|
|
172
|
+
syncProject();
|
|
173
|
+
return [...tsFileRegistry.keys()];
|
|
174
|
+
},
|
|
175
|
+
getScriptKind(fileName) {
|
|
176
|
+
syncSourceFile(fileName);
|
|
177
|
+
const virtualFile = files.getVirtualFile(projectHost.getFileId(fileName))[0];
|
|
178
|
+
if (virtualFile?.typescript) {
|
|
179
|
+
return virtualFile.typescript.scriptKind;
|
|
180
|
+
}
|
|
181
|
+
const sourceFile = files.getSourceFile(projectHost.getFileId(fileName));
|
|
182
|
+
if (sourceFile?.virtualFile) {
|
|
183
|
+
return ts.ScriptKind.Deferred;
|
|
184
|
+
}
|
|
185
|
+
switch (path.extname(fileName)) {
|
|
186
|
+
case '.js':
|
|
187
|
+
case '.cjs':
|
|
188
|
+
case '.mjs':
|
|
189
|
+
return ts.ScriptKind.JS;
|
|
190
|
+
case '.jsx':
|
|
191
|
+
return ts.ScriptKind.JSX;
|
|
192
|
+
case '.ts':
|
|
193
|
+
case '.cts':
|
|
194
|
+
case '.mts':
|
|
195
|
+
return ts.ScriptKind.TS;
|
|
196
|
+
case '.tsx':
|
|
197
|
+
return ts.ScriptKind.TSX;
|
|
198
|
+
case '.json':
|
|
199
|
+
return ts.ScriptKind.JSON;
|
|
200
|
+
default:
|
|
201
|
+
return ts.ScriptKind.Unknown;
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
getScriptVersion,
|
|
205
|
+
getScriptSnapshot,
|
|
206
|
+
};
|
|
207
|
+
return languageServiceHost;
|
|
208
|
+
function syncSourceFile(tsFileName) {
|
|
209
|
+
for (const language of languages) {
|
|
210
|
+
const sourceFileName = language.typescript?.resolveSourceFileName(tsFileName);
|
|
211
|
+
if (sourceFileName) {
|
|
212
|
+
files.getSourceFile(projectHost.getFileId(sourceFileName)); // trigger sync
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function syncProject() {
|
|
217
|
+
const newProjectVersion = projectHost.getProjectVersion?.();
|
|
218
|
+
const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion;
|
|
219
|
+
if (!shouldUpdate)
|
|
220
|
+
return;
|
|
221
|
+
lastProjectVersion = newProjectVersion;
|
|
222
|
+
const newTsVirtualFileSnapshots = new Set();
|
|
223
|
+
const newOtherVirtualFileSnapshots = new Set();
|
|
224
|
+
const tsFileNamesSet = new Set();
|
|
225
|
+
for (const fileName of projectHost.getScriptFileNames()) {
|
|
226
|
+
const uri = projectHost.getFileId(fileName);
|
|
227
|
+
const sourceFile = files.getSourceFile(uri);
|
|
228
|
+
if (sourceFile?.virtualFile) {
|
|
229
|
+
for (const file of (0, language_core_2.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
|
|
230
|
+
if (file.typescript) {
|
|
231
|
+
newTsVirtualFileSnapshots.add(file.snapshot);
|
|
232
|
+
tsFileNamesSet.add(projectHost.getFileName(file.id)); // virtual .ts
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
newOtherVirtualFileSnapshots.add(file.snapshot);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
tsFileNamesSet.add(fileName);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (!setEquals(lastTsVirtualFileSnapshots, newTsVirtualFileSnapshots)) {
|
|
244
|
+
tsProjectVersion++;
|
|
245
|
+
}
|
|
246
|
+
else if (setEquals(lastOtherVirtualFileSnapshots, newOtherVirtualFileSnapshots)) {
|
|
247
|
+
// no any meta language files update, it mean project version was update by source files this time
|
|
248
|
+
tsProjectVersion++;
|
|
249
|
+
}
|
|
250
|
+
lastTsVirtualFileSnapshots = newTsVirtualFileSnapshots;
|
|
251
|
+
lastOtherVirtualFileSnapshots = newOtherVirtualFileSnapshots;
|
|
252
|
+
tsFileRegistry.clear();
|
|
253
|
+
for (const fileName of tsFileNamesSet) {
|
|
254
|
+
tsFileRegistry.set(fileName, true);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function getScriptSnapshot(fileName) {
|
|
258
|
+
syncSourceFile(fileName);
|
|
259
|
+
const uri = projectHost.getFileId(fileName);
|
|
260
|
+
const virtualFile = files.getVirtualFile(uri)[0];
|
|
261
|
+
if (virtualFile) {
|
|
262
|
+
return virtualFile.snapshot;
|
|
263
|
+
}
|
|
264
|
+
const sourceFile = files.getSourceFile(uri);
|
|
265
|
+
if (sourceFile && !sourceFile.virtualFile) {
|
|
266
|
+
return sourceFile.snapshot;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function getScriptVersion(fileName) {
|
|
270
|
+
syncSourceFile(fileName);
|
|
271
|
+
if (!scriptVersions.has(fileName)) {
|
|
272
|
+
scriptVersions.set(fileName, { lastVersion: 0, map: new WeakMap() });
|
|
273
|
+
}
|
|
274
|
+
const version = scriptVersions.get(fileName);
|
|
275
|
+
const virtualFile = files.getVirtualFile(projectHost.getFileId(fileName))[0];
|
|
276
|
+
if (virtualFile) {
|
|
277
|
+
if (!version.map.has(virtualFile.snapshot)) {
|
|
278
|
+
version.map.set(virtualFile.snapshot, version.lastVersion++);
|
|
279
|
+
}
|
|
280
|
+
return version.map.get(virtualFile.snapshot).toString();
|
|
281
|
+
}
|
|
282
|
+
const isOpenedFile = !!projectHost.getScriptSnapshot(fileName);
|
|
283
|
+
if (isOpenedFile) {
|
|
284
|
+
const sourceFile = files.getSourceFile(projectHost.getFileId(fileName));
|
|
285
|
+
if (sourceFile && !sourceFile.virtualFile) {
|
|
286
|
+
if (!version.map.has(sourceFile.snapshot)) {
|
|
287
|
+
version.map.set(sourceFile.snapshot, version.lastVersion++);
|
|
288
|
+
}
|
|
289
|
+
return version.map.get(sourceFile.snapshot).toString();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (sys.fileExists(fileName)) {
|
|
293
|
+
return sys.getModifiedTime?.(fileName)?.valueOf().toString() ?? '0';
|
|
294
|
+
}
|
|
295
|
+
return '';
|
|
296
|
+
}
|
|
297
|
+
function getVirtualFileDirectories(dirName) {
|
|
298
|
+
const names = new Set();
|
|
299
|
+
for (const fileName of tsFileRegistry.keys()) {
|
|
300
|
+
if (fileName.toLowerCase().startsWith(dirName.toLowerCase())) {
|
|
301
|
+
const path = fileName.substring(dirName.length);
|
|
302
|
+
if (path.indexOf('/') >= 0) {
|
|
303
|
+
names.add(path.split('/')[0]);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return [...names];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
exports.createLanguage = createLanguage;
|
|
312
|
+
function setEquals(a, b) {
|
|
313
|
+
if (a.size !== b.size)
|
|
314
|
+
return false;
|
|
315
|
+
for (const item of a) {
|
|
316
|
+
if (!b.has(item))
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=createProject.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ServiceEnvironment, Disposable } from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
export declare function createSys(ts: typeof import('typescript/lib/tsserverlibrary'), env: ServiceEnvironment): ts.System & {
|
|
3
|
+
export declare function createSys(ts: typeof import('typescript/lib/tsserverlibrary'), env: ServiceEnvironment, currentDirectory: string): ts.System & {
|
|
4
4
|
version: number;
|
|
5
5
|
sync(): Promise<number>;
|
|
6
6
|
} & Disposable;
|
|
7
|
-
//# sourceMappingURL=sys.d.ts.map
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSys = void 0;
|
|
4
4
|
const path = require("path-browserify");
|
|
5
|
-
const utilities_1 = require("
|
|
5
|
+
const utilities_1 = require("../typescript/utilities");
|
|
6
6
|
let currentCwd = '';
|
|
7
|
-
function createSys(ts, env) {
|
|
7
|
+
function createSys(ts, env, currentDirectory) {
|
|
8
8
|
let version = 0;
|
|
9
|
-
const rootPath =
|
|
9
|
+
const rootPath = currentDirectory;
|
|
10
10
|
const sys = ts.sys;
|
|
11
11
|
const root = {
|
|
12
12
|
dirs: new Map(),
|
|
@@ -45,9 +45,6 @@ function createSys(ts, env) {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
return {
|
|
48
|
-
get version() {
|
|
49
|
-
return version;
|
|
50
|
-
},
|
|
51
48
|
dispose() {
|
|
52
49
|
fileWatcher?.dispose();
|
|
53
50
|
},
|
|
@@ -68,6 +65,9 @@ function createSys(ts, env) {
|
|
|
68
65
|
resolvePath,
|
|
69
66
|
fileExists,
|
|
70
67
|
directoryExists,
|
|
68
|
+
get version() {
|
|
69
|
+
return version;
|
|
70
|
+
},
|
|
71
71
|
async sync() {
|
|
72
72
|
while (promises.size) {
|
|
73
73
|
await Promise.all(promises);
|
|
@@ -84,7 +84,7 @@ function createSys(ts, env) {
|
|
|
84
84
|
if (sys.directoryExists(rootPath)) {
|
|
85
85
|
// https://github.com/vuejs/language-tools/issues/2480
|
|
86
86
|
try {
|
|
87
|
-
// @ts-
|
|
87
|
+
// @ts-ignore
|
|
88
88
|
process.chdir(rootPath);
|
|
89
89
|
}
|
|
90
90
|
catch { }
|
|
@@ -338,4 +338,4 @@ function createSys(ts, env) {
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
exports.createSys = createSys;
|
|
341
|
-
//# sourceMappingURL=
|
|
341
|
+
//# sourceMappingURL=createSys.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
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, { getFileId, getFileName }: {
|
|
4
|
+
getFileId(fileName: string): string;
|
|
5
|
+
getFileName(id: string): string;
|
|
6
|
+
}, ls: ts.LanguageService, sys: ts.System): ts.Program;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getProgram = void 0;
|
|
4
|
-
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
|
|
5
6
|
const proxy = {
|
|
6
7
|
getRootFileNames,
|
|
7
8
|
emit,
|
|
@@ -49,9 +50,10 @@ function getProgram(ts, core, ls, sys) {
|
|
|
49
50
|
}
|
|
50
51
|
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
51
52
|
if (sourceFile) {
|
|
52
|
-
const
|
|
53
|
+
const uri = getFileId(sourceFile.fileName);
|
|
54
|
+
const [virtualFile, source] = files.getVirtualFile(uri);
|
|
53
55
|
if (virtualFile && source) {
|
|
54
|
-
if (!virtualFile.
|
|
56
|
+
if (!virtualFile.mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)))
|
|
55
57
|
return [];
|
|
56
58
|
const errors = transformDiagnostics(ls.getProgram()?.[api](sourceFile, cancellationToken) ?? []);
|
|
57
59
|
return errors;
|
|
@@ -77,22 +79,22 @@ function getProgram(ts, core, ls, sys) {
|
|
|
77
79
|
if (diagnostic.file !== undefined
|
|
78
80
|
&& diagnostic.start !== undefined
|
|
79
81
|
&& diagnostic.length !== undefined) {
|
|
80
|
-
const
|
|
82
|
+
const uri = getFileId(diagnostic.file.fileName);
|
|
83
|
+
const [virtualFile, source] = files.getVirtualFile(uri);
|
|
81
84
|
if (virtualFile && source) {
|
|
82
|
-
|
|
85
|
+
const sourceFileName = getFileName(source.id);
|
|
86
|
+
if (sys.fileExists?.(sourceFileName) === false)
|
|
83
87
|
continue;
|
|
84
|
-
for (const [_, [sourceSnapshot, map]] of
|
|
88
|
+
for (const [_, [sourceSnapshot, map]] of files.getMaps(virtualFile)) {
|
|
85
89
|
if (sourceSnapshot !== source.snapshot)
|
|
86
90
|
continue;
|
|
87
|
-
for (const start of map.
|
|
88
|
-
|
|
89
|
-
if (!reportStart)
|
|
91
|
+
for (const start of map.getSourceOffsets(diagnostic.start)) {
|
|
92
|
+
if (!(0, language_core_1.shouldReportDiagnostics)(start[1].data))
|
|
90
93
|
continue;
|
|
91
|
-
for (const end of map.
|
|
92
|
-
|
|
93
|
-
if (!reportEnd)
|
|
94
|
+
for (const end of map.getSourceOffsets(diagnostic.start + diagnostic.length)) {
|
|
95
|
+
if (!(0, language_core_1.shouldReportDiagnostics)(end[1].data))
|
|
94
96
|
continue;
|
|
95
|
-
onMapping(diagnostic,
|
|
97
|
+
onMapping(diagnostic, sourceFileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
|
|
96
98
|
break;
|
|
97
99
|
}
|
|
98
100
|
break;
|
|
@@ -116,7 +118,8 @@ function getProgram(ts, core, ls, sys) {
|
|
|
116
118
|
: undefined;
|
|
117
119
|
if (!file) {
|
|
118
120
|
if (docText === undefined) {
|
|
119
|
-
const
|
|
121
|
+
const uri = getFileId(fileName);
|
|
122
|
+
const snapshot = files.getSourceFile(uri)?.snapshot;
|
|
120
123
|
if (snapshot) {
|
|
121
124
|
docText = snapshot.getText(0, snapshot.getLength());
|
|
122
125
|
}
|
package/lib/typescript/core.d.ts
CHANGED
|
@@ -81,4 +81,3 @@ type GetCanonicalFileName = (fileName: string) => string;
|
|
|
81
81
|
export declare function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName;
|
|
82
82
|
export declare function startsWith(str: string, prefix: string): boolean;
|
|
83
83
|
export {};
|
|
84
|
-
//# sourceMappingURL=core.d.ts.map
|
package/lib/typescript/core.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.startsWith = exports.createGetCanonicalFileName = exports.stringContains = exports.endsWith = exports.getStringComparer = exports.compareStringsCaseSensitive = exports.equateStringsCaseSensitive = exports.equateStringsCaseInsensitive = exports.last = exports.lastOrUndefined = exports.sort = exports.some = exports.flatMap = exports.flatten = exports.map = exports.indexOfAnyCharCode = exports.findIndex = exports.every = void 0;
|
|
4
|
+
require("./corePublic");
|
|
4
5
|
const emptyArray = [];
|
|
5
6
|
/**
|
|
6
7
|
* Iterates through `array` by index and performs the callback on each element of array until the callback
|
|
@@ -12,7 +12,7 @@ exports.version = `${exports.versionMajorMinor}.0-dev`;
|
|
|
12
12
|
var NativeCollections;
|
|
13
13
|
(function (NativeCollections) {
|
|
14
14
|
const globals = typeof globalThis !== "undefined" ? globalThis :
|
|
15
|
-
// @ts-
|
|
15
|
+
// @ts-ignore node global
|
|
16
16
|
typeof global !== "undefined" ? global :
|
|
17
17
|
typeof self !== "undefined" ? self :
|
|
18
18
|
undefined;
|
package/lib/typescript/path.d.ts
CHANGED
|
@@ -110,4 +110,3 @@ export declare function removeTrailingDirectorySeparator(path: string): string;
|
|
|
110
110
|
*/
|
|
111
111
|
export declare function containsPath(parent: string, child: string, ignoreCase?: boolean): boolean;
|
|
112
112
|
export declare function containsPath(parent: string, child: string, currentDirectory: string, ignoreCase?: boolean): boolean;
|
|
113
|
-
//# sourceMappingURL=path.d.ts.map
|
package/lib/typescript/path.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.containsPath = exports.removeTrailingDirectorySeparator = exports.normalizePath = exports.getNormalizedPathComponents = exports.combinePaths = exports.getDirectoryPath = exports.fileExtensionIsOneOf = exports.hasExtension = exports.isRootedDiskPath = exports.directorySeparator = void 0;
|
|
4
4
|
const core_1 = require("./core");
|
|
5
|
+
require("./types");
|
|
5
6
|
/**
|
|
6
7
|
* Internally, we represent paths as strings with '/' as the directory separator.
|
|
7
8
|
* When we make system calls (eg: LanguageServiceHost.getDirectory()),
|