@volar/typescript 1.0.22 → 1.1.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/out/getProgram.js +9 -9
- package/out/index.js +19 -26
- package/package.json +4 -4
package/out/getProgram.js
CHANGED
|
@@ -42,9 +42,9 @@ function getProgram(ts, core, ls) {
|
|
|
42
42
|
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
43
43
|
var _a, _b, _c;
|
|
44
44
|
if (sourceFile) {
|
|
45
|
-
const source = core.virtualFiles.
|
|
46
|
-
if (source) {
|
|
47
|
-
if (!
|
|
45
|
+
const [virtualFile, source] = core.virtualFiles.getVirtualFile(sourceFile.fileName);
|
|
46
|
+
if (virtualFile && source) {
|
|
47
|
+
if (!virtualFile.capabilities.diagnostic)
|
|
48
48
|
return [];
|
|
49
49
|
const errors = transformDiagnostics((_b = (_a = ls.getProgram()) === null || _a === void 0 ? void 0 : _a[api](sourceFile, cancellationToken)) !== null && _b !== void 0 ? _b : []);
|
|
50
50
|
return errors;
|
|
@@ -73,12 +73,12 @@ function getProgram(ts, core, ls) {
|
|
|
73
73
|
if (diagnostic.file !== undefined
|
|
74
74
|
&& diagnostic.start !== undefined
|
|
75
75
|
&& diagnostic.length !== undefined) {
|
|
76
|
-
const source = core.virtualFiles.
|
|
77
|
-
if (source) {
|
|
78
|
-
if (((_b = (_a = core.typescript.languageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, source
|
|
76
|
+
const [virtualFile, source] = core.virtualFiles.getVirtualFile(diagnostic.file.fileName);
|
|
77
|
+
if (virtualFile && source) {
|
|
78
|
+
if (((_b = (_a = core.typescript.languageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, source.fileName)) === false)
|
|
79
79
|
continue;
|
|
80
|
-
for (const [sourceFileName, map] of core.virtualFiles.getMaps(
|
|
81
|
-
if (sourceFileName !== source
|
|
80
|
+
for (const [sourceFileName, map] of core.virtualFiles.getMaps(virtualFile)) {
|
|
81
|
+
if (sourceFileName !== source.fileName)
|
|
82
82
|
continue;
|
|
83
83
|
for (const start of map.toSourceOffsets(diagnostic.start)) {
|
|
84
84
|
if (!start[1].data.diagnostic)
|
|
@@ -86,7 +86,7 @@ function getProgram(ts, core, ls) {
|
|
|
86
86
|
for (const end of map.toSourceOffsets(diagnostic.start + diagnostic.length, true)) {
|
|
87
87
|
if (!end[1].data.diagnostic)
|
|
88
88
|
continue;
|
|
89
|
-
onMapping(diagnostic, source
|
|
89
|
+
onMapping(diagnostic, source.fileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
|
|
90
90
|
break;
|
|
91
91
|
}
|
|
92
92
|
break;
|
package/out/index.js
CHANGED
|
@@ -3,13 +3,16 @@ 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;
|
|
6
7
|
const core = embedded.createLanguageContext(host, mods);
|
|
7
|
-
const ts = host.getTypeScriptModule();
|
|
8
|
+
const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
9
|
+
if (!ts) {
|
|
10
|
+
throw new Error('TypeScript module not provided.');
|
|
11
|
+
}
|
|
8
12
|
const ls = ts.createLanguageService(core.typescript.languageServiceHost);
|
|
9
13
|
return new Proxy({
|
|
10
14
|
organizeImports,
|
|
11
15
|
// only support for .ts for now, not support for .vue
|
|
12
|
-
getCompletionsAtPosition,
|
|
13
16
|
getDefinitionAtPosition,
|
|
14
17
|
getDefinitionAndBoundSpan,
|
|
15
18
|
getTypeDefinitionAtPosition,
|
|
@@ -45,11 +48,11 @@ function createLanguageService(host, mods) {
|
|
|
45
48
|
function organizeImports(args, formatOptions, preferences) {
|
|
46
49
|
var _a;
|
|
47
50
|
let edits = [];
|
|
48
|
-
const file = (_a = core.virtualFiles.
|
|
51
|
+
const file = (_a = core.virtualFiles.getSource(args.fileName)) === null || _a === void 0 ? void 0 : _a.root;
|
|
49
52
|
if (file) {
|
|
50
|
-
embedded.forEachEmbeddedFile(file,
|
|
51
|
-
if (
|
|
52
|
-
edits = edits.concat(ls.organizeImports(Object.assign(Object.assign({}, args), { fileName:
|
|
53
|
+
embedded.forEachEmbeddedFile(file, embeddedFile => {
|
|
54
|
+
if (embeddedFile.kind === embedded.FileKind.TypeScriptHostFile && embeddedFile.capabilities.codeAction) {
|
|
55
|
+
edits = edits.concat(ls.organizeImports(Object.assign(Object.assign({}, args), { fileName: embeddedFile.fileName }), formatOptions, preferences));
|
|
53
56
|
}
|
|
54
57
|
});
|
|
55
58
|
}
|
|
@@ -58,13 +61,6 @@ function createLanguageService(host, mods) {
|
|
|
58
61
|
}
|
|
59
62
|
return edits.map(transformFileTextChanges).filter(notEmpty);
|
|
60
63
|
}
|
|
61
|
-
function getCompletionsAtPosition(fileName, position, options) {
|
|
62
|
-
const finalResult = ls.getCompletionsAtPosition(fileName, position, options);
|
|
63
|
-
if (finalResult) {
|
|
64
|
-
finalResult.entries = finalResult.entries.filter(entry => entry.name.indexOf('__VLS_') === -1);
|
|
65
|
-
}
|
|
66
|
-
return finalResult;
|
|
67
|
-
}
|
|
68
64
|
function getReferencesAtPosition(fileName, position) {
|
|
69
65
|
return findLocations(fileName, position, 'references');
|
|
70
66
|
}
|
|
@@ -86,7 +82,6 @@ function createLanguageService(host, mods) {
|
|
|
86
82
|
withMirrors(fileName, position);
|
|
87
83
|
return symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty);
|
|
88
84
|
function withMirrors(fileName, position) {
|
|
89
|
-
var _a;
|
|
90
85
|
if (loopChecker.has(fileName + ':' + position))
|
|
91
86
|
return;
|
|
92
87
|
loopChecker.add(fileName + ':' + position);
|
|
@@ -101,7 +96,7 @@ function createLanguageService(host, mods) {
|
|
|
101
96
|
symbols = symbols.concat(_symbols);
|
|
102
97
|
for (const ref of _symbols) {
|
|
103
98
|
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
104
|
-
const virtualFile =
|
|
99
|
+
const [virtualFile] = core.virtualFiles.getVirtualFile(ref.fileName);
|
|
105
100
|
if (!virtualFile)
|
|
106
101
|
continue;
|
|
107
102
|
const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
|
|
@@ -133,7 +128,6 @@ function createLanguageService(host, mods) {
|
|
|
133
128
|
definitions: symbols === null || symbols === void 0 ? void 0 : symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty),
|
|
134
129
|
};
|
|
135
130
|
function withMirrors(fileName, position) {
|
|
136
|
-
var _a;
|
|
137
131
|
if (loopChecker.has(fileName + ':' + position))
|
|
138
132
|
return;
|
|
139
133
|
loopChecker.add(fileName + ':' + position);
|
|
@@ -148,7 +142,7 @@ function createLanguageService(host, mods) {
|
|
|
148
142
|
symbols = symbols.concat(_symbols.definitions);
|
|
149
143
|
for (const ref of _symbols.definitions) {
|
|
150
144
|
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
151
|
-
const virtualFile =
|
|
145
|
+
const [virtualFile] = core.virtualFiles.getVirtualFile(ref.fileName);
|
|
152
146
|
if (!virtualFile)
|
|
153
147
|
continue;
|
|
154
148
|
const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
|
|
@@ -170,7 +164,6 @@ function createLanguageService(host, mods) {
|
|
|
170
164
|
withMirrors(fileName, position);
|
|
171
165
|
return symbols.map(s => transformReferencedSymbol(s)).filter(notEmpty);
|
|
172
166
|
function withMirrors(fileName, position) {
|
|
173
|
-
var _a;
|
|
174
167
|
if (loopChecker.has(fileName + ':' + position))
|
|
175
168
|
return;
|
|
176
169
|
loopChecker.add(fileName + ':' + position);
|
|
@@ -181,7 +174,7 @@ function createLanguageService(host, mods) {
|
|
|
181
174
|
for (const symbol of _symbols) {
|
|
182
175
|
for (const ref of symbol.references) {
|
|
183
176
|
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
184
|
-
const virtualFile =
|
|
177
|
+
const [virtualFile] = core.virtualFiles.getVirtualFile(ref.fileName);
|
|
185
178
|
if (!virtualFile)
|
|
186
179
|
continue;
|
|
187
180
|
const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
|
|
@@ -200,9 +193,9 @@ function createLanguageService(host, mods) {
|
|
|
200
193
|
}
|
|
201
194
|
// transforms
|
|
202
195
|
function transformFileTextChanges(changes) {
|
|
203
|
-
const source = core.virtualFiles.
|
|
196
|
+
const [_, source] = core.virtualFiles.getVirtualFile(changes.fileName);
|
|
204
197
|
if (source) {
|
|
205
|
-
return Object.assign(Object.assign({}, changes), { fileName: source
|
|
198
|
+
return Object.assign(Object.assign({}, changes), { fileName: source.fileName, textChanges: changes.textChanges.map(c => {
|
|
206
199
|
const span = transformSpan(changes.fileName, c.span);
|
|
207
200
|
if (span) {
|
|
208
201
|
return Object.assign(Object.assign({}, c), { span: span.textSpan });
|
|
@@ -243,15 +236,15 @@ function createLanguageService(host, mods) {
|
|
|
243
236
|
return;
|
|
244
237
|
if (!textSpan)
|
|
245
238
|
return;
|
|
246
|
-
const source = core.virtualFiles.
|
|
247
|
-
if (source) {
|
|
248
|
-
for (const [sourceFileName, map] of core.virtualFiles.getMaps(
|
|
249
|
-
if (source
|
|
239
|
+
const [virtualFile, source] = core.virtualFiles.getVirtualFile(fileName);
|
|
240
|
+
if (virtualFile && source) {
|
|
241
|
+
for (const [sourceFileName, map] of core.virtualFiles.getMaps(virtualFile)) {
|
|
242
|
+
if (source.fileName !== sourceFileName)
|
|
250
243
|
continue;
|
|
251
244
|
const sourceLoc = map.toSourceOffset(textSpan.start);
|
|
252
245
|
if (sourceLoc) {
|
|
253
246
|
return {
|
|
254
|
-
fileName: source
|
|
247
|
+
fileName: source.fileName,
|
|
255
248
|
textSpan: {
|
|
256
249
|
start: sourceLoc[0],
|
|
257
250
|
length: textSpan.length,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.0",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
],
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/volarjs/framework.git",
|
|
13
13
|
"directory": "packages/typescript"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.0.
|
|
16
|
+
"@volar/language-core": "1.1.0-alpha.0"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "1cb85f17f5b90e40633e26710be7ecd4fd2994fb"
|
|
19
19
|
}
|