@volar/typescript 2.0.0-alpha.1 → 2.0.0-alpha.2
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.
|
@@ -554,7 +554,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
|
|
|
554
554
|
if (source) {
|
|
555
555
|
return {
|
|
556
556
|
...changes,
|
|
557
|
-
fileName: source.
|
|
557
|
+
fileName: source.fileName,
|
|
558
558
|
textChanges: changes.textChanges.map(c => {
|
|
559
559
|
const span = transformSpan(changes.fileName, c.span, filter);
|
|
560
560
|
if (span) {
|
|
@@ -576,7 +576,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
|
|
|
576
576
|
const [virtualFile, source] = getVirtualFileAndMap(documentSpan.fileName);
|
|
577
577
|
if (virtualFile) {
|
|
578
578
|
textSpan = {
|
|
579
|
-
fileName: source.
|
|
579
|
+
fileName: source.fileName,
|
|
580
580
|
textSpan: { start: 0, length: 0 },
|
|
581
581
|
};
|
|
582
582
|
}
|
|
@@ -608,7 +608,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
|
|
|
608
608
|
for (const sourceEnd of map.getSourceOffsets(textSpan.start + textSpan.length - (isTsPlugin ? sourceFile.snapshot.getLength() : 0))) {
|
|
609
609
|
if (filter(sourceEnd[1].data)) {
|
|
610
610
|
return {
|
|
611
|
-
fileName: sourceFile.
|
|
611
|
+
fileName: sourceFile.fileName,
|
|
612
612
|
textSpan: {
|
|
613
613
|
start: sourceStart[0],
|
|
614
614
|
length: sourceEnd[0] - sourceStart[0],
|
|
@@ -631,7 +631,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
|
|
|
631
631
|
const sourceFile = virtualFiles.getSourceFile(fileName);
|
|
632
632
|
if (sourceFile?.virtualFile) {
|
|
633
633
|
for (const virtualFile of (0, language_core_1.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
|
|
634
|
-
const ext = virtualFile.
|
|
634
|
+
const ext = virtualFile.fileName.substring(fileName.length);
|
|
635
635
|
if (virtualFile.typescript && (ext === '.d.ts' || ext.match(/^\.(js|ts)x?$/))) {
|
|
636
636
|
for (const map of virtualFiles.getMaps(virtualFile)) {
|
|
637
637
|
if (map[1][0] === sourceFile.snapshot) {
|
|
@@ -121,7 +121,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
|
|
|
121
121
|
const text = snapshot.getText(0, snapshot.getLength());
|
|
122
122
|
let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
|
|
123
123
|
for (const file of (0, language_core_1.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
|
|
124
|
-
const ext = file.
|
|
124
|
+
const ext = file.fileName.substring(fileName.length);
|
|
125
125
|
if (file.typescript && (ext === '.d.ts' || ext.match(/^\.(js|ts)x?$/))) {
|
|
126
126
|
extension = ext;
|
|
127
127
|
scriptKind = file.typescript.scriptKind;
|
|
@@ -8,8 +8,7 @@ const utilities_1 = require("../typescript/utilities");
|
|
|
8
8
|
const scriptVersions = new Map();
|
|
9
9
|
const fsFileSnapshots = new Map();
|
|
10
10
|
function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
11
|
-
const files = (0, language_core_1.createFileProvider)(languages, sys.useCaseSensitiveFileNames,
|
|
12
|
-
const fileName = projectHost.getFileName(id);
|
|
11
|
+
const files = (0, language_core_1.createFileProvider)(languages, sys.useCaseSensitiveFileNames, fileName => {
|
|
13
12
|
// opened files
|
|
14
13
|
let snapshot = projectHost.getScriptSnapshot(fileName);
|
|
15
14
|
if (!snapshot) {
|
|
@@ -29,10 +28,10 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
29
28
|
snapshot = fsFileSnapshots.get(fileName)?.[1];
|
|
30
29
|
}
|
|
31
30
|
if (snapshot) {
|
|
32
|
-
files.updateSourceFile(
|
|
31
|
+
files.updateSourceFile(fileName, projectHost.getLanguageId(fileName), snapshot);
|
|
33
32
|
}
|
|
34
33
|
else {
|
|
35
|
-
files.deleteSourceFile(
|
|
34
|
+
files.deleteSourceFile(fileName);
|
|
36
35
|
}
|
|
37
36
|
});
|
|
38
37
|
let languageServiceHost = createLanguageServiceHost();
|
|
@@ -153,9 +152,9 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
153
152
|
};
|
|
154
153
|
}, sys?.realpath ? (path => sys.realpath(path)) : (path => path));
|
|
155
154
|
matches = matches.map(match => {
|
|
156
|
-
const [_, source] = files.getVirtualFile(
|
|
155
|
+
const [_, source] = files.getVirtualFile(match);
|
|
157
156
|
if (source) {
|
|
158
|
-
return
|
|
157
|
+
return source.fileName;
|
|
159
158
|
}
|
|
160
159
|
return match;
|
|
161
160
|
});
|
|
@@ -174,11 +173,11 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
174
173
|
},
|
|
175
174
|
getScriptKind(fileName) {
|
|
176
175
|
syncSourceFile(fileName);
|
|
177
|
-
const virtualFile = files.getVirtualFile(
|
|
176
|
+
const virtualFile = files.getVirtualFile(fileName)[0];
|
|
178
177
|
if (virtualFile?.typescript) {
|
|
179
178
|
return virtualFile.typescript.scriptKind;
|
|
180
179
|
}
|
|
181
|
-
const sourceFile = files.getSourceFile(
|
|
180
|
+
const sourceFile = files.getSourceFile(fileName);
|
|
182
181
|
if (sourceFile?.virtualFile) {
|
|
183
182
|
return ts.ScriptKind.Deferred;
|
|
184
183
|
}
|
|
@@ -209,7 +208,7 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
209
208
|
for (const language of languages) {
|
|
210
209
|
const sourceFileName = language.typescript?.resolveSourceFileName(tsFileName);
|
|
211
210
|
if (sourceFileName) {
|
|
212
|
-
files.getSourceFile(
|
|
211
|
+
files.getSourceFile(sourceFileName); // trigger sync
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
}
|
|
@@ -223,13 +222,12 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
223
222
|
const newOtherVirtualFileSnapshots = new Set();
|
|
224
223
|
const tsFileNamesSet = new Set();
|
|
225
224
|
for (const fileName of projectHost.getScriptFileNames()) {
|
|
226
|
-
const
|
|
227
|
-
const sourceFile = files.getSourceFile(uri);
|
|
225
|
+
const sourceFile = files.getSourceFile(fileName);
|
|
228
226
|
if (sourceFile?.virtualFile) {
|
|
229
227
|
for (const file of (0, language_core_2.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
|
|
230
228
|
if (file.typescript) {
|
|
231
229
|
newTsVirtualFileSnapshots.add(file.snapshot);
|
|
232
|
-
tsFileNamesSet.add(
|
|
230
|
+
tsFileNamesSet.add(file.fileName); // virtual .ts
|
|
233
231
|
}
|
|
234
232
|
else {
|
|
235
233
|
newOtherVirtualFileSnapshots.add(file.snapshot);
|
|
@@ -256,12 +254,11 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
256
254
|
}
|
|
257
255
|
function getScriptSnapshot(fileName) {
|
|
258
256
|
syncSourceFile(fileName);
|
|
259
|
-
const
|
|
260
|
-
const virtualFile = files.getVirtualFile(uri)[0];
|
|
257
|
+
const virtualFile = files.getVirtualFile(fileName)[0];
|
|
261
258
|
if (virtualFile) {
|
|
262
259
|
return virtualFile.snapshot;
|
|
263
260
|
}
|
|
264
|
-
const sourceFile = files.getSourceFile(
|
|
261
|
+
const sourceFile = files.getSourceFile(fileName);
|
|
265
262
|
if (sourceFile && !sourceFile.virtualFile) {
|
|
266
263
|
return sourceFile.snapshot;
|
|
267
264
|
}
|
|
@@ -272,7 +269,7 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
272
269
|
scriptVersions.set(fileName, { lastVersion: 0, map: new WeakMap() });
|
|
273
270
|
}
|
|
274
271
|
const version = scriptVersions.get(fileName);
|
|
275
|
-
const virtualFile = files.getVirtualFile(
|
|
272
|
+
const virtualFile = files.getVirtualFile(fileName)[0];
|
|
276
273
|
if (virtualFile) {
|
|
277
274
|
if (!version.map.has(virtualFile.snapshot)) {
|
|
278
275
|
version.map.set(virtualFile.snapshot, version.lastVersion++);
|
|
@@ -281,7 +278,7 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
|
|
|
281
278
|
}
|
|
282
279
|
const isOpenedFile = !!projectHost.getScriptSnapshot(fileName);
|
|
283
280
|
if (isOpenedFile) {
|
|
284
|
-
const sourceFile = files.getSourceFile(
|
|
281
|
+
const sourceFile = files.getSourceFile(fileName);
|
|
285
282
|
if (sourceFile && !sourceFile.virtualFile) {
|
|
286
283
|
if (!version.map.has(sourceFile.snapshot)) {
|
|
287
284
|
version.map.set(sourceFile.snapshot, version.lastVersion++);
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { type FileProvider } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), files: FileProvider,
|
|
4
|
-
getFileId(fileName: string): string;
|
|
5
|
-
getFileName(id: string): string;
|
|
6
|
-
}, ls: ts.LanguageService, sys: ts.System): ts.Program;
|
|
3
|
+
export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), files: FileProvider, ls: ts.LanguageService, sys: ts.System): ts.Program;
|
|
@@ -2,7 +2,7 @@
|
|
|
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,
|
|
5
|
+
function getProgram(ts, files, ls, sys) {
|
|
6
6
|
const proxy = {
|
|
7
7
|
getRootFileNames,
|
|
8
8
|
emit,
|
|
@@ -50,8 +50,7 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
|
|
|
50
50
|
}
|
|
51
51
|
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
52
52
|
if (sourceFile) {
|
|
53
|
-
const
|
|
54
|
-
const [virtualFile, source] = files.getVirtualFile(uri);
|
|
53
|
+
const [virtualFile, source] = files.getVirtualFile(sourceFile.fileName);
|
|
55
54
|
if (virtualFile && source) {
|
|
56
55
|
if (!virtualFile.mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)))
|
|
57
56
|
return [];
|
|
@@ -79,11 +78,9 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
|
|
|
79
78
|
if (diagnostic.file !== undefined
|
|
80
79
|
&& diagnostic.start !== undefined
|
|
81
80
|
&& diagnostic.length !== undefined) {
|
|
82
|
-
const
|
|
83
|
-
const [virtualFile, source] = files.getVirtualFile(uri);
|
|
81
|
+
const [virtualFile, source] = files.getVirtualFile(diagnostic.file.fileName);
|
|
84
82
|
if (virtualFile && source) {
|
|
85
|
-
|
|
86
|
-
if (sys.fileExists?.(sourceFileName) === false)
|
|
83
|
+
if (sys.fileExists?.(source.fileName) === false)
|
|
87
84
|
continue;
|
|
88
85
|
for (const [_, [sourceSnapshot, map]] of files.getMaps(virtualFile)) {
|
|
89
86
|
if (sourceSnapshot !== source.snapshot)
|
|
@@ -94,7 +91,7 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
|
|
|
94
91
|
for (const end of map.getSourceOffsets(diagnostic.start + diagnostic.length)) {
|
|
95
92
|
if (!(0, language_core_1.shouldReportDiagnostics)(end[1].data))
|
|
96
93
|
continue;
|
|
97
|
-
onMapping(diagnostic,
|
|
94
|
+
onMapping(diagnostic, source.fileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
|
|
98
95
|
break;
|
|
99
96
|
}
|
|
100
97
|
break;
|
|
@@ -118,8 +115,7 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
|
|
|
118
115
|
: undefined;
|
|
119
116
|
if (!file) {
|
|
120
117
|
if (docText === undefined) {
|
|
121
|
-
const
|
|
122
|
-
const snapshot = files.getSourceFile(uri)?.snapshot;
|
|
118
|
+
const snapshot = files.getSourceFile(fileName)?.snapshot;
|
|
123
119
|
if (snapshot) {
|
|
124
120
|
docText = snapshot.getText(0, snapshot.getLength());
|
|
125
121
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"directory": "packages/typescript"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.0.0-alpha.
|
|
15
|
+
"@volar/language-core": "2.0.0-alpha.2",
|
|
16
16
|
"path-browserify": "^1.0.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/path-browserify": "latest",
|
|
20
|
-
"@volar/language-service": "2.0.0-alpha.
|
|
20
|
+
"@volar/language-service": "2.0.0-alpha.2"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "88e80b9f00541ab9478b9c7b7af213813fc8cb20"
|
|
23
23
|
}
|