@volar/typescript 1.0.16 → 1.0.18
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.d.ts +1 -1
- package/out/getProgram.js +28 -16
- package/out/index.d.ts +1 -1
- package/out/index.js +68 -39
- package/package.json +3 -3
package/out/getProgram.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import type * as embedded from '@volar/language-core';
|
|
3
|
-
export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), core: embedded.
|
|
3
|
+
export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), core: embedded.LanguageContext, ls: ts.LanguageService): any;
|
package/out/getProgram.js
CHANGED
|
@@ -26,7 +26,7 @@ function getProgram(ts, core, ls) {
|
|
|
26
26
|
return ls.getProgram();
|
|
27
27
|
}
|
|
28
28
|
function getRootFileNames() {
|
|
29
|
-
return getProgram().getRootFileNames().filter(fileName => { var _a, _b; return (_b = (_a = core.
|
|
29
|
+
return getProgram().getRootFileNames().filter(fileName => { var _a, _b; return (_b = (_a = core.typescript.languageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, fileName); });
|
|
30
30
|
}
|
|
31
31
|
// for vue-tsc --noEmit --watch
|
|
32
32
|
function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
|
|
@@ -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
|
|
46
|
-
if (
|
|
47
|
-
if (!
|
|
45
|
+
const source = core.virtualFiles.getSourceByVirtualFileName(sourceFile.fileName);
|
|
46
|
+
if (source) {
|
|
47
|
+
if (!source[2].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;
|
|
@@ -58,7 +58,7 @@ function getProgram(ts, core, ls) {
|
|
|
58
58
|
}
|
|
59
59
|
function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
|
|
60
60
|
var _a;
|
|
61
|
-
const scriptResult = getProgram().emit(targetSourceFile, ((_a = core.
|
|
61
|
+
const scriptResult = getProgram().emit(targetSourceFile, ((_a = core.typescript.languageServiceHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
62
62
|
return {
|
|
63
63
|
emitSkipped: scriptResult.emitSkipped,
|
|
64
64
|
emittedFiles: scriptResult.emittedFiles,
|
|
@@ -67,24 +67,36 @@ function getProgram(ts, core, ls) {
|
|
|
67
67
|
}
|
|
68
68
|
// transform
|
|
69
69
|
function transformDiagnostics(diagnostics) {
|
|
70
|
-
var _a, _b, _c;
|
|
70
|
+
var _a, _b, _c, _d;
|
|
71
71
|
const result = [];
|
|
72
72
|
for (const diagnostic of diagnostics) {
|
|
73
73
|
if (diagnostic.file !== undefined
|
|
74
74
|
&& diagnostic.start !== undefined
|
|
75
75
|
&& diagnostic.length !== undefined) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!((_b = (_a = core.typescriptLanguageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, start.fileName)))
|
|
76
|
+
const source = core.virtualFiles.getSourceByVirtualFileName(diagnostic.file.fileName);
|
|
77
|
+
if (source) {
|
|
78
|
+
if (((_b = (_a = core.typescript.languageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, source[0])) === false)
|
|
80
79
|
continue;
|
|
81
|
-
for (const
|
|
82
|
-
if (
|
|
80
|
+
for (const [sourceFileName, map] of core.virtualFiles.getMaps(source[2])) {
|
|
81
|
+
if (sourceFileName !== source[0])
|
|
83
82
|
continue;
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
for (const start of map.toSourceOffsets(diagnostic.start)) {
|
|
84
|
+
if (!start[1].data.diagnostic)
|
|
85
|
+
continue;
|
|
86
|
+
for (const end of map.toSourceOffsets(diagnostic.start + diagnostic.length, true)) {
|
|
87
|
+
if (!end[1].data.diagnostic)
|
|
88
|
+
continue;
|
|
89
|
+
onMapping(diagnostic, source[0], start[0], end[0], source[1].getText(0, source[1].getLength()));
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
86
94
|
}
|
|
87
|
-
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
if (((_d = (_c = core.typescript.languageServiceHost).fileExists) === null || _d === void 0 ? void 0 : _d.call(_c, diagnostic.file.fileName)) === false)
|
|
98
|
+
continue;
|
|
99
|
+
onMapping(diagnostic, diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, diagnostic.file.text);
|
|
88
100
|
}
|
|
89
101
|
}
|
|
90
102
|
else if (diagnostic.file === undefined) {
|
|
@@ -99,7 +111,7 @@ function getProgram(ts, core, ls) {
|
|
|
99
111
|
: undefined;
|
|
100
112
|
if (!file) {
|
|
101
113
|
if (docText === undefined) {
|
|
102
|
-
const snapshot = core.
|
|
114
|
+
const snapshot = core.typescript.languageServiceHost.getScriptSnapshot(fileName);
|
|
103
115
|
if (snapshot) {
|
|
104
116
|
docText = snapshot.getText(0, snapshot.getLength());
|
|
105
117
|
}
|
package/out/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import * as embedded from '@volar/language-core';
|
|
|
3
3
|
export declare function createLanguageService(host: embedded.LanguageServiceHost, mods: embedded.LanguageModule[]): {
|
|
4
4
|
__internal__: {
|
|
5
5
|
languageService: ts.LanguageService;
|
|
6
|
-
context: embedded.
|
|
6
|
+
context: embedded.LanguageContext;
|
|
7
7
|
};
|
|
8
8
|
} & ts.LanguageService;
|
package/out/index.js
CHANGED
|
@@ -3,9 +3,9 @@ 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
|
-
const core = embedded.
|
|
6
|
+
const core = embedded.createLanguageContext(host, mods);
|
|
7
7
|
const ts = host.getTypeScriptModule();
|
|
8
|
-
const ls = ts.createLanguageService(core.
|
|
8
|
+
const ls = ts.createLanguageService(core.typescript.languageServiceHost);
|
|
9
9
|
return new Proxy({
|
|
10
10
|
organizeImports,
|
|
11
11
|
// only support for .ts for now, not support for .vue
|
|
@@ -43,10 +43,11 @@ function createLanguageService(host, mods) {
|
|
|
43
43
|
});
|
|
44
44
|
// apis
|
|
45
45
|
function organizeImports(args, formatOptions, preferences) {
|
|
46
|
-
|
|
46
|
+
var _a;
|
|
47
47
|
let edits = [];
|
|
48
|
+
const file = (_a = core.virtualFiles.get(args.fileName)) === null || _a === void 0 ? void 0 : _a[1];
|
|
48
49
|
if (file) {
|
|
49
|
-
embedded.
|
|
50
|
+
embedded.forEachEmbeddedFile(file, embedded => {
|
|
50
51
|
if (embedded.kind && embedded.capabilities.codeAction) {
|
|
51
52
|
edits = edits.concat(ls.organizeImports(Object.assign(Object.assign({}, args), { fileName: embedded.fileName }), formatOptions, preferences));
|
|
52
53
|
}
|
|
@@ -82,9 +83,10 @@ function createLanguageService(host, mods) {
|
|
|
82
83
|
function findLocations(fileName, position, mode, findInStrings = false, findInComments = false, providePrefixAndSuffixTextForRename) {
|
|
83
84
|
const loopChecker = new Set();
|
|
84
85
|
let symbols = [];
|
|
85
|
-
|
|
86
|
+
withMirrors(fileName, position);
|
|
86
87
|
return symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty);
|
|
87
|
-
function
|
|
88
|
+
function withMirrors(fileName, position) {
|
|
89
|
+
var _a;
|
|
88
90
|
if (loopChecker.has(fileName + ':' + position))
|
|
89
91
|
return;
|
|
90
92
|
loopChecker.add(fileName + ':' + position);
|
|
@@ -99,21 +101,22 @@ function createLanguageService(host, mods) {
|
|
|
99
101
|
symbols = symbols.concat(_symbols);
|
|
100
102
|
for (const ref of _symbols) {
|
|
101
103
|
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
+
const virtualFile = (_a = core.virtualFiles.getSourceByVirtualFileName(ref.fileName)) === null || _a === void 0 ? void 0 : _a[2];
|
|
105
|
+
if (!virtualFile)
|
|
104
106
|
continue;
|
|
105
|
-
|
|
107
|
+
const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
|
|
108
|
+
if (!mirrorMap)
|
|
109
|
+
continue;
|
|
110
|
+
for (const [mirrorOffset, data] of mirrorMap.findMirrorOffsets(ref.textSpan.start)) {
|
|
106
111
|
if ((mode === 'definition' || mode === 'typeDefinition' || mode === 'implementation') && !data.definition)
|
|
107
|
-
|
|
112
|
+
continue;
|
|
108
113
|
if ((mode === 'references') && !data.references)
|
|
109
|
-
|
|
114
|
+
continue;
|
|
110
115
|
if ((mode === 'rename') && !data.rename)
|
|
111
|
-
return false;
|
|
112
|
-
return true;
|
|
113
|
-
})) {
|
|
114
|
-
if (loopChecker.has(ref.fileName + ':' + teleOffset))
|
|
115
116
|
continue;
|
|
116
|
-
|
|
117
|
+
if (loopChecker.has(ref.fileName + ':' + mirrorOffset))
|
|
118
|
+
continue;
|
|
119
|
+
withMirrors(ref.fileName, mirrorOffset);
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
}
|
|
@@ -122,14 +125,15 @@ function createLanguageService(host, mods) {
|
|
|
122
125
|
const loopChecker = new Set();
|
|
123
126
|
let textSpan;
|
|
124
127
|
let symbols = [];
|
|
125
|
-
|
|
128
|
+
withMirrors(fileName, position);
|
|
126
129
|
if (!textSpan)
|
|
127
130
|
return;
|
|
128
131
|
return {
|
|
129
132
|
textSpan: textSpan,
|
|
130
133
|
definitions: symbols === null || symbols === void 0 ? void 0 : symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty),
|
|
131
134
|
};
|
|
132
|
-
function
|
|
135
|
+
function withMirrors(fileName, position) {
|
|
136
|
+
var _a;
|
|
133
137
|
if (loopChecker.has(fileName + ':' + position))
|
|
134
138
|
return;
|
|
135
139
|
loopChecker.add(fileName + ':' + position);
|
|
@@ -144,13 +148,18 @@ function createLanguageService(host, mods) {
|
|
|
144
148
|
symbols = symbols.concat(_symbols.definitions);
|
|
145
149
|
for (const ref of _symbols.definitions) {
|
|
146
150
|
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
151
|
+
const virtualFile = (_a = core.virtualFiles.getSourceByVirtualFileName(ref.fileName)) === null || _a === void 0 ? void 0 : _a[2];
|
|
152
|
+
if (!virtualFile)
|
|
149
153
|
continue;
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
|
|
155
|
+
if (!mirrorMap)
|
|
156
|
+
continue;
|
|
157
|
+
for (const [mirrorOffset, data] of mirrorMap.findMirrorOffsets(ref.textSpan.start)) {
|
|
158
|
+
if (!data.definition)
|
|
159
|
+
continue;
|
|
160
|
+
if (loopChecker.has(ref.fileName + ':' + mirrorOffset))
|
|
152
161
|
continue;
|
|
153
|
-
|
|
162
|
+
withMirrors(ref.fileName, mirrorOffset);
|
|
154
163
|
}
|
|
155
164
|
}
|
|
156
165
|
}
|
|
@@ -158,9 +167,10 @@ function createLanguageService(host, mods) {
|
|
|
158
167
|
function findReferences(fileName, position) {
|
|
159
168
|
const loopChecker = new Set();
|
|
160
169
|
let symbols = [];
|
|
161
|
-
|
|
170
|
+
withMirrors(fileName, position);
|
|
162
171
|
return symbols.map(s => transformReferencedSymbol(s)).filter(notEmpty);
|
|
163
|
-
function
|
|
172
|
+
function withMirrors(fileName, position) {
|
|
173
|
+
var _a;
|
|
164
174
|
if (loopChecker.has(fileName + ':' + position))
|
|
165
175
|
return;
|
|
166
176
|
loopChecker.add(fileName + ':' + position);
|
|
@@ -171,13 +181,18 @@ function createLanguageService(host, mods) {
|
|
|
171
181
|
for (const symbol of _symbols) {
|
|
172
182
|
for (const ref of symbol.references) {
|
|
173
183
|
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
174
|
-
const
|
|
175
|
-
if (!
|
|
184
|
+
const virtualFile = (_a = core.virtualFiles.getSourceByVirtualFileName(ref.fileName)) === null || _a === void 0 ? void 0 : _a[2];
|
|
185
|
+
if (!virtualFile)
|
|
186
|
+
continue;
|
|
187
|
+
const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
|
|
188
|
+
if (!mirrorMap)
|
|
176
189
|
continue;
|
|
177
|
-
for (const
|
|
178
|
-
if (
|
|
190
|
+
for (const [mirrorOffset, data] of mirrorMap.findMirrorOffsets(ref.textSpan.start)) {
|
|
191
|
+
if (!data.references)
|
|
179
192
|
continue;
|
|
180
|
-
|
|
193
|
+
if (loopChecker.has(ref.fileName + ':' + mirrorOffset))
|
|
194
|
+
continue;
|
|
195
|
+
withMirrors(ref.fileName, mirrorOffset);
|
|
181
196
|
}
|
|
182
197
|
}
|
|
183
198
|
}
|
|
@@ -185,9 +200,9 @@ function createLanguageService(host, mods) {
|
|
|
185
200
|
}
|
|
186
201
|
// transforms
|
|
187
202
|
function transformFileTextChanges(changes) {
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
return Object.assign(Object.assign({}, changes), { fileName:
|
|
203
|
+
const source = core.virtualFiles.getSourceByVirtualFileName(changes.fileName);
|
|
204
|
+
if (source) {
|
|
205
|
+
return Object.assign(Object.assign({}, changes), { fileName: source[0], textChanges: changes.textChanges.map(c => {
|
|
191
206
|
const span = transformSpan(changes.fileName, c.span);
|
|
192
207
|
if (span) {
|
|
193
208
|
return Object.assign(Object.assign({}, c), { span: span.textSpan });
|
|
@@ -228,13 +243,27 @@ function createLanguageService(host, mods) {
|
|
|
228
243
|
return;
|
|
229
244
|
if (!textSpan)
|
|
230
245
|
return;
|
|
231
|
-
|
|
246
|
+
const source = core.virtualFiles.getSourceByVirtualFileName(fileName);
|
|
247
|
+
if (source) {
|
|
248
|
+
for (const [sourceFileName, map] of core.virtualFiles.getMaps(source[2])) {
|
|
249
|
+
if (source[0] !== sourceFileName)
|
|
250
|
+
continue;
|
|
251
|
+
const sourceLoc = map.toSourceOffset(textSpan.start);
|
|
252
|
+
if (sourceLoc) {
|
|
253
|
+
return {
|
|
254
|
+
fileName: source[0],
|
|
255
|
+
textSpan: {
|
|
256
|
+
start: sourceLoc[0],
|
|
257
|
+
length: textSpan.length,
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
232
264
|
return {
|
|
233
|
-
fileName
|
|
234
|
-
textSpan
|
|
235
|
-
start: sourceLoc.offset,
|
|
236
|
-
length: textSpan.length,
|
|
237
|
-
},
|
|
265
|
+
fileName,
|
|
266
|
+
textSpan,
|
|
238
267
|
};
|
|
239
268
|
}
|
|
240
269
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
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.0.
|
|
16
|
+
"@volar/language-core": "1.0.18"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "f102ee7bfc96792c63746a5dcb9742e3346d5cc7"
|
|
19
19
|
}
|