@volar/typescript 1.4.0-alpha.0 → 1.4.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.
- package/out/getProgram.js +14 -14
- package/out/index.js +31 -11
- package/package.json +3 -3
package/out/getProgram.js
CHANGED
|
@@ -32,7 +32,7 @@ function getProgram(ts, core, ls) {
|
|
|
32
32
|
return ls.getProgram();
|
|
33
33
|
}
|
|
34
34
|
function getRootFileNames() {
|
|
35
|
-
return getProgram().getRootFileNames().filter(fileName =>
|
|
35
|
+
return getProgram().getRootFileNames().filter(fileName => core.typescript.languageServiceHost.fileExists?.(fileName));
|
|
36
36
|
}
|
|
37
37
|
// for vue-tsc --noEmit --watch
|
|
38
38
|
function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
|
|
@@ -46,25 +46,22 @@ function getProgram(ts, core, ls) {
|
|
|
46
46
|
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSemanticDiagnostics');
|
|
47
47
|
}
|
|
48
48
|
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
49
|
-
var _a, _b, _c;
|
|
50
49
|
if (sourceFile) {
|
|
51
50
|
const [virtualFile, source] = core.virtualFiles.getVirtualFile(sourceFile.fileName);
|
|
52
51
|
if (virtualFile && source) {
|
|
53
52
|
if (!virtualFile.capabilities.diagnostic)
|
|
54
53
|
return [];
|
|
55
|
-
const errors = transformDiagnostics(
|
|
54
|
+
const errors = transformDiagnostics(ls.getProgram()?.[api](sourceFile, cancellationToken) ?? []);
|
|
56
55
|
return errors;
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
return transformDiagnostics(
|
|
58
|
+
return transformDiagnostics(getProgram()[api](sourceFile, cancellationToken) ?? []);
|
|
60
59
|
}
|
|
61
60
|
function getGlobalDiagnostics(cancellationToken) {
|
|
62
|
-
|
|
63
|
-
return transformDiagnostics((_a = getProgram().getGlobalDiagnostics(cancellationToken)) !== null && _a !== void 0 ? _a : []);
|
|
61
|
+
return transformDiagnostics(getProgram().getGlobalDiagnostics(cancellationToken) ?? []);
|
|
64
62
|
}
|
|
65
63
|
function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
|
|
66
|
-
|
|
67
|
-
const scriptResult = getProgram().emit(targetSourceFile, ((_a = core.typescript.languageServiceHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
64
|
+
const scriptResult = getProgram().emit(targetSourceFile, (core.typescript.languageServiceHost.writeFile ?? ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
68
65
|
return {
|
|
69
66
|
emitSkipped: scriptResult.emitSkipped,
|
|
70
67
|
emittedFiles: scriptResult.emittedFiles,
|
|
@@ -73,7 +70,6 @@ function getProgram(ts, core, ls) {
|
|
|
73
70
|
}
|
|
74
71
|
// transform
|
|
75
72
|
function transformDiagnostics(diagnostics) {
|
|
76
|
-
var _a, _b, _c, _d;
|
|
77
73
|
const result = [];
|
|
78
74
|
for (const diagnostic of diagnostics) {
|
|
79
75
|
if (diagnostic.file !== undefined
|
|
@@ -81,7 +77,7 @@ function getProgram(ts, core, ls) {
|
|
|
81
77
|
&& diagnostic.length !== undefined) {
|
|
82
78
|
const [virtualFile, source] = core.virtualFiles.getVirtualFile(diagnostic.file.fileName);
|
|
83
79
|
if (virtualFile && source) {
|
|
84
|
-
if (
|
|
80
|
+
if (core.typescript.languageServiceHost.fileExists?.(source.fileName) === false)
|
|
85
81
|
continue;
|
|
86
82
|
for (const [sourceFileName, map] of core.virtualFiles.getMaps(virtualFile)) {
|
|
87
83
|
if (sourceFileName !== source.fileName)
|
|
@@ -100,7 +96,7 @@ function getProgram(ts, core, ls) {
|
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
98
|
else {
|
|
103
|
-
if (
|
|
99
|
+
if (core.typescript.languageServiceHost.fileExists?.(diagnostic.file.fileName) === false)
|
|
104
100
|
continue;
|
|
105
101
|
onMapping(diagnostic, diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, diagnostic.file.text);
|
|
106
102
|
}
|
|
@@ -111,8 +107,7 @@ function getProgram(ts, core, ls) {
|
|
|
111
107
|
}
|
|
112
108
|
return result;
|
|
113
109
|
function onMapping(diagnostic, fileName, start, end, docText) {
|
|
114
|
-
|
|
115
|
-
let file = fileName === ((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName)
|
|
110
|
+
let file = fileName === diagnostic.file?.fileName
|
|
116
111
|
? diagnostic.file
|
|
117
112
|
: undefined;
|
|
118
113
|
if (!file) {
|
|
@@ -137,7 +132,12 @@ function getProgram(ts, core, ls) {
|
|
|
137
132
|
file = ts.createSourceFile(fileName, docText, scriptTarget);
|
|
138
133
|
}
|
|
139
134
|
}
|
|
140
|
-
const newDiagnostic =
|
|
135
|
+
const newDiagnostic = {
|
|
136
|
+
...diagnostic,
|
|
137
|
+
file,
|
|
138
|
+
start: start,
|
|
139
|
+
length: end - start,
|
|
140
|
+
};
|
|
141
141
|
const relatedInformation = diagnostic.relatedInformation;
|
|
142
142
|
if (relatedInformation) {
|
|
143
143
|
newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
|
package/out/index.js
CHANGED
|
@@ -3,9 +3,8 @@ exports.createLanguageService = void 0;
|
|
|
3
3
|
const getProgram_1 = require("./getProgram");
|
|
4
4
|
const embedded = require("@volar/language-core");
|
|
5
5
|
function createLanguageService(host, mods) {
|
|
6
|
-
var _a;
|
|
7
6
|
const core = embedded.createLanguageContext(host, mods);
|
|
8
|
-
const ts =
|
|
7
|
+
const ts = host.getTypeScriptModule?.();
|
|
9
8
|
if (!ts) {
|
|
10
9
|
throw new Error('TypeScript module not provided.');
|
|
11
10
|
}
|
|
@@ -46,13 +45,15 @@ function createLanguageService(host, mods) {
|
|
|
46
45
|
});
|
|
47
46
|
// apis
|
|
48
47
|
function organizeImports(args, formatOptions, preferences) {
|
|
49
|
-
var _a;
|
|
50
48
|
let edits = [];
|
|
51
|
-
const file =
|
|
49
|
+
const file = core.virtualFiles.getSource(args.fileName)?.root;
|
|
52
50
|
if (file) {
|
|
53
51
|
embedded.forEachEmbeddedFile(file, embeddedFile => {
|
|
54
52
|
if (embeddedFile.kind === embedded.FileKind.TypeScriptHostFile && embeddedFile.capabilities.codeAction) {
|
|
55
|
-
edits = edits.concat(ls.organizeImports(
|
|
53
|
+
edits = edits.concat(ls.organizeImports({
|
|
54
|
+
...args,
|
|
55
|
+
fileName: embeddedFile.fileName,
|
|
56
|
+
}, formatOptions, preferences));
|
|
56
57
|
}
|
|
57
58
|
});
|
|
58
59
|
}
|
|
@@ -125,7 +126,7 @@ function createLanguageService(host, mods) {
|
|
|
125
126
|
return;
|
|
126
127
|
return {
|
|
127
128
|
textSpan: textSpan,
|
|
128
|
-
definitions: symbols
|
|
129
|
+
definitions: symbols?.map(s => transformDocumentSpanLike(s)).filter(notEmpty),
|
|
129
130
|
};
|
|
130
131
|
function withMirrors(fileName, position) {
|
|
131
132
|
if (loopChecker.has(fileName + ':' + position))
|
|
@@ -195,12 +196,19 @@ function createLanguageService(host, mods) {
|
|
|
195
196
|
function transformFileTextChanges(changes) {
|
|
196
197
|
const [_, source] = core.virtualFiles.getVirtualFile(changes.fileName);
|
|
197
198
|
if (source) {
|
|
198
|
-
return
|
|
199
|
+
return {
|
|
200
|
+
...changes,
|
|
201
|
+
fileName: source.fileName,
|
|
202
|
+
textChanges: changes.textChanges.map(c => {
|
|
199
203
|
const span = transformSpan(changes.fileName, c.span);
|
|
200
204
|
if (span) {
|
|
201
|
-
return
|
|
205
|
+
return {
|
|
206
|
+
...c,
|
|
207
|
+
span: span.textSpan,
|
|
208
|
+
};
|
|
202
209
|
}
|
|
203
|
-
}).filter(notEmpty)
|
|
210
|
+
}).filter(notEmpty),
|
|
211
|
+
};
|
|
204
212
|
}
|
|
205
213
|
else {
|
|
206
214
|
return changes;
|
|
@@ -217,7 +225,11 @@ function createLanguageService(host, mods) {
|
|
|
217
225
|
}
|
|
218
226
|
else if (references.length) { // TODO: remove patching
|
|
219
227
|
return {
|
|
220
|
-
definition:
|
|
228
|
+
definition: {
|
|
229
|
+
...symbol.definition,
|
|
230
|
+
fileName: references[0].fileName,
|
|
231
|
+
textSpan: references[0].textSpan,
|
|
232
|
+
},
|
|
221
233
|
references,
|
|
222
234
|
};
|
|
223
235
|
}
|
|
@@ -229,7 +241,15 @@ function createLanguageService(host, mods) {
|
|
|
229
241
|
const contextSpan = transformSpan(documentSpan.fileName, documentSpan.contextSpan);
|
|
230
242
|
const originalTextSpan = transformSpan(documentSpan.originalFileName, documentSpan.originalTextSpan);
|
|
231
243
|
const originalContextSpan = transformSpan(documentSpan.originalFileName, documentSpan.originalContextSpan);
|
|
232
|
-
return
|
|
244
|
+
return {
|
|
245
|
+
...documentSpan,
|
|
246
|
+
fileName: textSpan.fileName,
|
|
247
|
+
textSpan: textSpan.textSpan,
|
|
248
|
+
contextSpan: contextSpan?.textSpan,
|
|
249
|
+
originalFileName: originalTextSpan?.fileName,
|
|
250
|
+
originalTextSpan: originalTextSpan?.textSpan,
|
|
251
|
+
originalContextSpan: originalContextSpan?.textSpan,
|
|
252
|
+
};
|
|
233
253
|
}
|
|
234
254
|
function transformSpan(fileName, textSpan) {
|
|
235
255
|
if (!fileName)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.2",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/typescript"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.4.0-alpha.
|
|
16
|
+
"@volar/language-core": "1.4.0-alpha.2"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "034b230da17794a6fcf5a0b07668710f98ff84e3"
|
|
19
19
|
}
|