@volar/language-core 1.0.22 → 1.1.0-1.2.0-alpha.1.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/index.d.ts +1 -1
- package/out/index.js +1 -1
- package/out/languageContext.d.ts +7 -6
- package/out/languageContext.js +50 -40
- package/out/types.d.ts +12 -2
- package/out/types.js +32 -1
- package/out/virtualFiles.d.ts +22 -0
- package/out/{documentRegistry.js → virtualFiles.js} +26 -32
- package/package.json +4 -4
- package/out/documentRegistry.d.ts +0 -22
package/out/index.d.ts
CHANGED
package/out/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
13
13
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
__exportStar(require("./
|
|
16
|
+
__exportStar(require("./virtualFiles"), exports);
|
|
17
17
|
__exportStar(require("./languageContext"), exports);
|
|
18
18
|
__exportStar(require("./sourceMaps"), exports);
|
|
19
19
|
__exportStar(require("./types"), exports);
|
package/out/languageContext.d.ts
CHANGED
|
@@ -6,13 +6,14 @@ export declare function createLanguageContext(host: LanguageServiceHost, languag
|
|
|
6
6
|
languageServiceHost: ts.LanguageServiceHost;
|
|
7
7
|
};
|
|
8
8
|
virtualFiles: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
allSources(): import("./virtualFiles").Source[];
|
|
10
|
+
updateSource(fileName: string, snapshot: ts.IScriptSnapshot, languageId: string | undefined): import("./types").VirtualFile | undefined;
|
|
11
|
+
deleteSource(fileName: string): void;
|
|
12
|
+
getSource(fileName: string): import("./virtualFiles").Source | undefined;
|
|
13
|
+
hasSource: (fileName: string) => boolean;
|
|
14
14
|
getMirrorMap: (file: import("./types").VirtualFile) => import("./sourceMaps").MirrorMap | undefined;
|
|
15
15
|
getMaps: (virtualFile: import("./types").VirtualFile) => [string, import("@volar/source-map").SourceMap<import("./types").FileRangeCapabilities>][];
|
|
16
|
-
|
|
16
|
+
hasVirtualFile(fileName: string): boolean;
|
|
17
|
+
getVirtualFile(fileName: string): readonly [import("./types").VirtualFile, import("./virtualFiles").Source] | readonly [undefined, undefined];
|
|
17
18
|
};
|
|
18
19
|
};
|
package/out/languageContext.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
2
|
exports.createLanguageContext = void 0;
|
|
3
3
|
const path_1 = require("path");
|
|
4
|
-
const
|
|
4
|
+
const virtualFiles_1 = require("./virtualFiles");
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
function createLanguageContext(host, languageModules) {
|
|
7
|
+
var _a;
|
|
7
8
|
for (const languageModule of languageModules.reverse()) {
|
|
8
9
|
if (languageModule.proxyLanguageServiceHost) {
|
|
9
10
|
const proxyApis = languageModule.proxyLanguageServiceHost(host);
|
|
@@ -19,8 +20,8 @@ function createLanguageContext(host, languageModules) {
|
|
|
19
20
|
}
|
|
20
21
|
let lastProjectVersion;
|
|
21
22
|
let tsProjectVersion = 0;
|
|
22
|
-
const virtualFiles = (0,
|
|
23
|
-
const ts = host.getTypeScriptModule();
|
|
23
|
+
const virtualFiles = (0, virtualFiles_1.createVirtualFiles)(languageModules);
|
|
24
|
+
const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
24
25
|
const scriptSnapshots = new Map();
|
|
25
26
|
const sourceTsFileVersions = new Map();
|
|
26
27
|
const sourceFileVersions = new Map();
|
|
@@ -28,22 +29,31 @@ function createLanguageContext(host, languageModules) {
|
|
|
28
29
|
const _tsHost = {
|
|
29
30
|
fileExists: host.fileExists
|
|
30
31
|
? fileName => {
|
|
31
|
-
var _a;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const ext = fileName.substring(fileName.lastIndexOf('.'));
|
|
34
|
+
if (ext === '.js'
|
|
35
|
+
|| ext === '.ts'
|
|
36
|
+
|| ext === '.jsx'
|
|
37
|
+
|| ext === '.tsx') {
|
|
38
|
+
/**
|
|
39
|
+
* If try to access a external .vue file that outside of the project,
|
|
40
|
+
* the file will not process by language service host,
|
|
41
|
+
* so virtual file will not be created.
|
|
42
|
+
*
|
|
43
|
+
* We try to create virtual file here.
|
|
44
|
+
*/
|
|
45
|
+
const sourceFileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
|
46
|
+
if (!virtualFiles.hasSource(sourceFileName)) {
|
|
47
|
+
const scriptSnapshot = host.getScriptSnapshot(sourceFileName);
|
|
48
|
+
if (scriptSnapshot) {
|
|
49
|
+
virtualFiles.updateSource(sourceFileName, scriptSnapshot, (_a = host.getScriptLanguageId) === null || _a === void 0 ? void 0 : _a.call(host, sourceFileName));
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
|
-
if (virtualFiles.
|
|
53
|
+
if (virtualFiles.hasVirtualFile(fileName)) {
|
|
44
54
|
return true;
|
|
45
55
|
}
|
|
46
|
-
return !!((
|
|
56
|
+
return !!((_b = host.fileExists) === null || _b === void 0 ? void 0 : _b.call(host, fileName));
|
|
47
57
|
}
|
|
48
58
|
: undefined,
|
|
49
59
|
getProjectVersion: () => {
|
|
@@ -55,7 +65,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
55
65
|
readDirectory: (_path, extensions, exclude, include, depth) => {
|
|
56
66
|
var _a, _b;
|
|
57
67
|
const result = (_b = (_a = host.readDirectory) === null || _a === void 0 ? void 0 : _a.call(host, _path, extensions, exclude, include, depth)) !== null && _b !== void 0 ? _b : [];
|
|
58
|
-
for (const
|
|
68
|
+
for (const { fileName } of virtualFiles.allSources()) {
|
|
59
69
|
const vuePath2 = path_1.posix.join(_path, path_1.posix.basename(fileName));
|
|
60
70
|
if (path_1.posix.relative(_path.toLowerCase(), fileName.toLowerCase()).startsWith('..')) {
|
|
61
71
|
continue;
|
|
@@ -71,7 +81,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
71
81
|
},
|
|
72
82
|
getScriptKind(fileName) {
|
|
73
83
|
if (ts) {
|
|
74
|
-
if (virtualFiles.
|
|
84
|
+
if (virtualFiles.hasSource(fileName))
|
|
75
85
|
return ts.ScriptKind.Deferred;
|
|
76
86
|
switch (path_1.posix.extname(fileName)) {
|
|
77
87
|
case '.js': return ts.ScriptKind.JS;
|
|
@@ -102,7 +112,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
102
112
|
}),
|
|
103
113
|
};
|
|
104
114
|
function update() {
|
|
105
|
-
var _a;
|
|
115
|
+
var _a, _b, _c;
|
|
106
116
|
const newProjectVersion = (_a = host.getProjectVersion) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
107
117
|
const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion;
|
|
108
118
|
lastProjectVersion = newProjectVersion;
|
|
@@ -112,12 +122,12 @@ function createLanguageContext(host, languageModules) {
|
|
|
112
122
|
let virtualFilesUpdatedNum = 0;
|
|
113
123
|
const remainRootFiles = new Set(host.getScriptFileNames());
|
|
114
124
|
// .vue
|
|
115
|
-
for (const
|
|
125
|
+
for (const { fileName } of virtualFiles.allSources()) {
|
|
116
126
|
remainRootFiles.delete(fileName);
|
|
117
127
|
const snapshot = host.getScriptSnapshot(fileName);
|
|
118
128
|
if (!snapshot) {
|
|
119
129
|
// delete
|
|
120
|
-
virtualFiles.
|
|
130
|
+
virtualFiles.deleteSource(fileName);
|
|
121
131
|
shouldUpdateTsProject = true;
|
|
122
132
|
virtualFilesUpdatedNum++;
|
|
123
133
|
continue;
|
|
@@ -126,7 +136,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
126
136
|
if (sourceFileVersions.get(fileName) !== newVersion) {
|
|
127
137
|
// update
|
|
128
138
|
sourceFileVersions.set(fileName, newVersion);
|
|
129
|
-
virtualFiles.
|
|
139
|
+
virtualFiles.updateSource(fileName, snapshot, (_b = host.getScriptLanguageId) === null || _b === void 0 ? void 0 : _b.call(host, fileName));
|
|
130
140
|
virtualFilesUpdatedNum++;
|
|
131
141
|
}
|
|
132
142
|
}
|
|
@@ -138,7 +148,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
138
148
|
for (const fileName of [...remainRootFiles]) {
|
|
139
149
|
const snapshot = host.getScriptSnapshot(fileName);
|
|
140
150
|
if (snapshot) {
|
|
141
|
-
const virtualFile = virtualFiles.
|
|
151
|
+
const virtualFile = virtualFiles.updateSource(fileName, snapshot, (_c = host.getScriptLanguageId) === null || _c === void 0 ? void 0 : _c.call(host, fileName));
|
|
142
152
|
if (virtualFile) {
|
|
143
153
|
remainRootFiles.delete(fileName);
|
|
144
154
|
}
|
|
@@ -167,9 +177,9 @@ function createLanguageContext(host, languageModules) {
|
|
|
167
177
|
shouldUpdateTsProject = true;
|
|
168
178
|
}
|
|
169
179
|
}
|
|
170
|
-
for (const
|
|
180
|
+
for (const { root: rootVirtualFile } of virtualFiles.allSources()) {
|
|
171
181
|
if (!shouldUpdateTsProject) {
|
|
172
|
-
(0,
|
|
182
|
+
(0, virtualFiles_1.forEachEmbeddedFile)(rootVirtualFile, embedded => {
|
|
173
183
|
var _a;
|
|
174
184
|
if (embedded.kind === types_1.FileKind.TypeScriptHostFile) {
|
|
175
185
|
if (virtualFileVersions.has(embedded.fileName) && ((_a = virtualFileVersions.get(embedded.fileName)) === null || _a === void 0 ? void 0 : _a.virtualFileSnapshot) !== embedded.snapshot) {
|
|
@@ -185,38 +195,38 @@ function createLanguageContext(host, languageModules) {
|
|
|
185
195
|
}
|
|
186
196
|
function getScriptFileNames() {
|
|
187
197
|
const tsFileNames = new Set();
|
|
188
|
-
for (const
|
|
189
|
-
(0,
|
|
198
|
+
for (const { root: rootVirtualFile } of virtualFiles.allSources()) {
|
|
199
|
+
(0, virtualFiles_1.forEachEmbeddedFile)(rootVirtualFile, embedded => {
|
|
190
200
|
if (embedded.kind === types_1.FileKind.TypeScriptHostFile) {
|
|
191
201
|
tsFileNames.add(embedded.fileName); // virtual .ts
|
|
192
202
|
}
|
|
193
203
|
});
|
|
194
204
|
}
|
|
195
205
|
for (const fileName of host.getScriptFileNames()) {
|
|
196
|
-
if (!virtualFiles.
|
|
206
|
+
if (!virtualFiles.hasSource(fileName)) {
|
|
197
207
|
tsFileNames.add(fileName); // .ts
|
|
198
208
|
}
|
|
199
209
|
}
|
|
200
210
|
return [...tsFileNames];
|
|
201
211
|
}
|
|
202
212
|
function getScriptVersion(fileName) {
|
|
203
|
-
let source = virtualFiles.
|
|
204
|
-
if (source) {
|
|
205
|
-
let version = virtualFileVersions.get(
|
|
213
|
+
let [virtualFile, source] = virtualFiles.getVirtualFile(fileName);
|
|
214
|
+
if (virtualFile && source) {
|
|
215
|
+
let version = virtualFileVersions.get(virtualFile.fileName);
|
|
206
216
|
if (!version) {
|
|
207
217
|
version = {
|
|
208
218
|
value: 0,
|
|
209
|
-
virtualFileSnapshot:
|
|
210
|
-
sourceFileSnapshot: source
|
|
219
|
+
virtualFileSnapshot: virtualFile.snapshot,
|
|
220
|
+
sourceFileSnapshot: source.snapshot,
|
|
211
221
|
};
|
|
212
|
-
virtualFileVersions.set(
|
|
222
|
+
virtualFileVersions.set(virtualFile.fileName, version);
|
|
213
223
|
}
|
|
214
|
-
else if (version.virtualFileSnapshot !==
|
|
215
|
-
|| (host.isTsc && version.sourceFileSnapshot !== source
|
|
224
|
+
else if (version.virtualFileSnapshot !== virtualFile.snapshot
|
|
225
|
+
|| (host.isTsc && version.sourceFileSnapshot !== source.snapshot) // fix https://github.com/johnsoncodehk/volar/issues/1082
|
|
216
226
|
) {
|
|
217
227
|
version.value++;
|
|
218
|
-
version.virtualFileSnapshot =
|
|
219
|
-
version.sourceFileSnapshot = source
|
|
228
|
+
version.virtualFileSnapshot = virtualFile.snapshot;
|
|
229
|
+
version.sourceFileSnapshot = source.snapshot;
|
|
220
230
|
}
|
|
221
231
|
return version.value.toString();
|
|
222
232
|
}
|
|
@@ -228,9 +238,9 @@ function createLanguageContext(host, languageModules) {
|
|
|
228
238
|
if (cache && cache[0] === version) {
|
|
229
239
|
return cache[1];
|
|
230
240
|
}
|
|
231
|
-
const
|
|
232
|
-
if (
|
|
233
|
-
const snapshot =
|
|
241
|
+
const [virtualFile] = virtualFiles.getVirtualFile(fileName);
|
|
242
|
+
if (virtualFile) {
|
|
243
|
+
const snapshot = virtualFile.snapshot;
|
|
234
244
|
scriptSnapshots.set(fileName.toLowerCase(), [version, snapshot]);
|
|
235
245
|
return snapshot;
|
|
236
246
|
}
|
package/out/types.d.ts
CHANGED
|
@@ -32,6 +32,15 @@ export interface MirrorBehaviorCapabilities {
|
|
|
32
32
|
definition?: boolean;
|
|
33
33
|
rename?: boolean;
|
|
34
34
|
}
|
|
35
|
+
export declare namespace FileCapabilities {
|
|
36
|
+
const full: FileCapabilities;
|
|
37
|
+
}
|
|
38
|
+
export declare namespace FileRangeCapabilities {
|
|
39
|
+
const full: FileRangeCapabilities;
|
|
40
|
+
}
|
|
41
|
+
export declare namespace MirrorBehaviorCapabilities {
|
|
42
|
+
const full: MirrorBehaviorCapabilities;
|
|
43
|
+
}
|
|
35
44
|
export declare enum FileKind {
|
|
36
45
|
TextFile = 0,
|
|
37
46
|
TypeScriptHostFile = 1
|
|
@@ -46,12 +55,13 @@ export interface VirtualFile {
|
|
|
46
55
|
embeddedFiles: VirtualFile[];
|
|
47
56
|
}
|
|
48
57
|
export interface LanguageModule<T extends VirtualFile = VirtualFile> {
|
|
49
|
-
createFile(fileName: string, snapshot: ts.IScriptSnapshot): T | undefined;
|
|
58
|
+
createFile(fileName: string, snapshot: ts.IScriptSnapshot, languageId: string | undefined): T | undefined;
|
|
50
59
|
updateFile(virtualFile: T, snapshot: ts.IScriptSnapshot): void;
|
|
51
60
|
deleteFile?(virtualFile: T): void;
|
|
52
61
|
proxyLanguageServiceHost?(host: LanguageServiceHost): Partial<LanguageServiceHost>;
|
|
53
62
|
}
|
|
54
63
|
export interface LanguageServiceHost extends ts.LanguageServiceHost {
|
|
55
|
-
getTypeScriptModule(): typeof import('typescript/lib/tsserverlibrary')
|
|
64
|
+
getTypeScriptModule?(): typeof import('typescript/lib/tsserverlibrary');
|
|
65
|
+
getScriptLanguageId?(fileName: string): string | undefined;
|
|
56
66
|
isTsc?: boolean;
|
|
57
67
|
}
|
package/out/types.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.FileKind = void 0;
|
|
2
|
+
exports.FileKind = exports.MirrorBehaviorCapabilities = exports.FileRangeCapabilities = exports.FileCapabilities = void 0;
|
|
3
|
+
var FileCapabilities;
|
|
4
|
+
(function (FileCapabilities) {
|
|
5
|
+
FileCapabilities.full = {
|
|
6
|
+
diagnostic: true,
|
|
7
|
+
foldingRange: true,
|
|
8
|
+
documentFormatting: true,
|
|
9
|
+
documentSymbol: true,
|
|
10
|
+
codeAction: true,
|
|
11
|
+
inlayHint: true,
|
|
12
|
+
};
|
|
13
|
+
})(FileCapabilities = exports.FileCapabilities || (exports.FileCapabilities = {}));
|
|
14
|
+
var FileRangeCapabilities;
|
|
15
|
+
(function (FileRangeCapabilities) {
|
|
16
|
+
FileRangeCapabilities.full = {
|
|
17
|
+
hover: true,
|
|
18
|
+
references: true,
|
|
19
|
+
definition: true,
|
|
20
|
+
rename: true,
|
|
21
|
+
completion: true,
|
|
22
|
+
diagnostic: true,
|
|
23
|
+
semanticTokens: true,
|
|
24
|
+
};
|
|
25
|
+
})(FileRangeCapabilities = exports.FileRangeCapabilities || (exports.FileRangeCapabilities = {}));
|
|
26
|
+
var MirrorBehaviorCapabilities;
|
|
27
|
+
(function (MirrorBehaviorCapabilities) {
|
|
28
|
+
MirrorBehaviorCapabilities.full = {
|
|
29
|
+
references: true,
|
|
30
|
+
definition: true,
|
|
31
|
+
rename: true,
|
|
32
|
+
};
|
|
33
|
+
})(MirrorBehaviorCapabilities = exports.MirrorBehaviorCapabilities || (exports.MirrorBehaviorCapabilities = {}));
|
|
3
34
|
var FileKind;
|
|
4
35
|
(function (FileKind) {
|
|
5
36
|
FileKind[FileKind["TextFile"] = 0] = "TextFile";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SourceMap } from '@volar/source-map';
|
|
2
|
+
import { MirrorMap } from './sourceMaps';
|
|
3
|
+
import type { LanguageModule, FileRangeCapabilities, VirtualFile } from './types';
|
|
4
|
+
export type VirtualFiles = ReturnType<typeof createVirtualFiles>;
|
|
5
|
+
export interface Source {
|
|
6
|
+
fileName: string;
|
|
7
|
+
snapshot: ts.IScriptSnapshot;
|
|
8
|
+
root: VirtualFile;
|
|
9
|
+
languageModule: LanguageModule;
|
|
10
|
+
}
|
|
11
|
+
export declare function createVirtualFiles(languageModules: LanguageModule[]): {
|
|
12
|
+
allSources(): Source[];
|
|
13
|
+
updateSource(fileName: string, snapshot: ts.IScriptSnapshot, languageId: string | undefined): VirtualFile | undefined;
|
|
14
|
+
deleteSource(fileName: string): void;
|
|
15
|
+
getSource(fileName: string): Source | undefined;
|
|
16
|
+
hasSource: (fileName: string) => boolean;
|
|
17
|
+
getMirrorMap: (file: VirtualFile) => MirrorMap | undefined;
|
|
18
|
+
getMaps: (virtualFile: VirtualFile) => [string, SourceMap<FileRangeCapabilities>][];
|
|
19
|
+
hasVirtualFile(fileName: string): boolean;
|
|
20
|
+
getVirtualFile(fileName: string): readonly [VirtualFile, Source] | readonly [undefined, undefined];
|
|
21
|
+
};
|
|
22
|
+
export declare function forEachEmbeddedFile(file: VirtualFile, cb: (embedded: VirtualFile) => void): void;
|
|
@@ -9,59 +9,53 @@ function createVirtualFiles(languageModules) {
|
|
|
9
9
|
const virtualFileToMirrorMap = new WeakMap();
|
|
10
10
|
let sourceFilesDirty = true;
|
|
11
11
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
allSources() {
|
|
13
|
+
return Array.from(sourceFiles.values());
|
|
14
|
+
},
|
|
15
|
+
updateSource(fileName, snapshot, languageId) {
|
|
14
16
|
const key = normalizePath(fileName);
|
|
15
17
|
const value = sourceFiles.get(key);
|
|
16
18
|
if (value) {
|
|
17
|
-
|
|
18
|
-
value
|
|
19
|
-
value[3].updateFile(virtualFile, snapshot);
|
|
19
|
+
value.snapshot = snapshot;
|
|
20
|
+
value.languageModule.updateFile(value.root, snapshot);
|
|
20
21
|
sourceFilesDirty = true;
|
|
21
|
-
return
|
|
22
|
+
return value.root; // updated
|
|
22
23
|
}
|
|
23
24
|
for (const languageModule of languageModules) {
|
|
24
|
-
const virtualFile = languageModule.createFile(fileName, snapshot);
|
|
25
|
+
const virtualFile = languageModule.createFile(fileName, snapshot, languageId);
|
|
25
26
|
if (virtualFile) {
|
|
26
|
-
sourceFiles.set(key,
|
|
27
|
+
sourceFiles.set(key, { fileName, snapshot, root: virtualFile, languageModule });
|
|
27
28
|
sourceFilesDirty = true;
|
|
28
29
|
return virtualFile; // created
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
|
-
|
|
33
|
+
deleteSource(fileName) {
|
|
33
34
|
var _a, _b;
|
|
34
35
|
const key = normalizePath(fileName);
|
|
35
36
|
const value = sourceFiles.get(key);
|
|
36
37
|
if (value) {
|
|
37
|
-
|
|
38
|
-
(_b = (_a = value[3]).deleteFile) === null || _b === void 0 ? void 0 : _b.call(_a, virtualFile);
|
|
38
|
+
(_b = (_a = value.languageModule).deleteFile) === null || _b === void 0 ? void 0 : _b.call(_a, value.root);
|
|
39
39
|
sourceFiles.delete(key); // deleted
|
|
40
40
|
sourceFilesDirty = true;
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
getSource(fileName) {
|
|
44
44
|
const key = normalizePath(fileName);
|
|
45
|
-
|
|
46
|
-
if (value) {
|
|
47
|
-
return [
|
|
48
|
-
value[1],
|
|
49
|
-
value[2],
|
|
50
|
-
];
|
|
51
|
-
}
|
|
45
|
+
return sourceFiles.get(key);
|
|
52
46
|
},
|
|
53
|
-
|
|
47
|
+
hasSource: (fileName) => sourceFiles.has(normalizePath(fileName)),
|
|
54
48
|
getMirrorMap: getMirrorMap,
|
|
55
49
|
getMaps: getSourceMaps,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
];
|
|
50
|
+
hasVirtualFile(fileName) {
|
|
51
|
+
return !!getVirtualFilesMap().get(normalizePath(fileName));
|
|
52
|
+
},
|
|
53
|
+
getVirtualFile(fileName) {
|
|
54
|
+
const sourceAndVirtual = getVirtualFilesMap().get(normalizePath(fileName));
|
|
55
|
+
if (sourceAndVirtual) {
|
|
56
|
+
return [sourceAndVirtual.virtualFile, sourceAndVirtual.source];
|
|
64
57
|
}
|
|
58
|
+
return [undefined, undefined];
|
|
65
59
|
},
|
|
66
60
|
};
|
|
67
61
|
function getVirtualFilesMap() {
|
|
@@ -69,8 +63,8 @@ function createVirtualFiles(languageModules) {
|
|
|
69
63
|
sourceFilesDirty = false;
|
|
70
64
|
virtualFiles.clear();
|
|
71
65
|
for (const [_, row] of sourceFiles) {
|
|
72
|
-
forEachEmbeddedFile(row
|
|
73
|
-
virtualFiles.set(normalizePath(file.fileName),
|
|
66
|
+
forEachEmbeddedFile(row.root, file => {
|
|
67
|
+
virtualFiles.set(normalizePath(file.fileName), { virtualFile: file, source: row });
|
|
74
68
|
});
|
|
75
69
|
}
|
|
76
70
|
}
|
|
@@ -87,7 +81,7 @@ function createVirtualFiles(languageModules) {
|
|
|
87
81
|
sources.add(map.source);
|
|
88
82
|
}
|
|
89
83
|
for (const source of sources) {
|
|
90
|
-
const sourceFileName = source !== null && source !== void 0 ? source : getVirtualFilesMap().get(normalizePath(virtualFile.fileName))
|
|
84
|
+
const sourceFileName = source !== null && source !== void 0 ? source : getVirtualFilesMap().get(normalizePath(virtualFile.fileName)).source.fileName;
|
|
91
85
|
if (!sourceMapsBySourceFileName.has(sourceFileName)) {
|
|
92
86
|
sourceMapsBySourceFileName.set(sourceFileName, [
|
|
93
87
|
sourceFileName,
|
|
@@ -115,4 +109,4 @@ exports.forEachEmbeddedFile = forEachEmbeddedFile;
|
|
|
115
109
|
function normalizePath(fileName) {
|
|
116
110
|
return fileName.replace(/\\/g, '/').toLowerCase();
|
|
117
111
|
}
|
|
118
|
-
//# sourceMappingURL=
|
|
112
|
+
//# sourceMappingURL=virtualFiles.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-1.2.0-alpha.1.0",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
],
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/volarjs/volar.js.git",
|
|
13
13
|
"directory": "packages/language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/source-map": "1.0.
|
|
16
|
+
"@volar/source-map": "1.1.0-1.2.0-alpha.1.0",
|
|
17
17
|
"muggle-string": "^0.1.0"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "ffc1267f2766722751551182ce1e717be661247a"
|
|
20
20
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { SourceMap } from '@volar/source-map';
|
|
2
|
-
import { MirrorMap } from './sourceMaps';
|
|
3
|
-
import type { LanguageModule, FileRangeCapabilities, VirtualFile } from './types';
|
|
4
|
-
export type VirtualFiles = ReturnType<typeof createVirtualFiles>;
|
|
5
|
-
type Source = [
|
|
6
|
-
string,
|
|
7
|
-
ts.IScriptSnapshot,
|
|
8
|
-
VirtualFile,
|
|
9
|
-
LanguageModule
|
|
10
|
-
];
|
|
11
|
-
export declare function createVirtualFiles(languageModules: LanguageModule[]): {
|
|
12
|
-
all: Map<string, Source>;
|
|
13
|
-
update(fileName: string, snapshot: ts.IScriptSnapshot): VirtualFile | undefined;
|
|
14
|
-
delete(fileName: string): void;
|
|
15
|
-
get(fileName: string): readonly [import("typescript/lib/tsserverlibrary").IScriptSnapshot, VirtualFile] | undefined;
|
|
16
|
-
hasSourceFile: (fileName: string) => boolean;
|
|
17
|
-
getMirrorMap: (file: VirtualFile) => MirrorMap | undefined;
|
|
18
|
-
getMaps: (virtualFile: VirtualFile) => [string, SourceMap<FileRangeCapabilities>][];
|
|
19
|
-
getSourceByVirtualFileName(fileName: string): readonly [string, import("typescript/lib/tsserverlibrary").IScriptSnapshot, VirtualFile] | undefined;
|
|
20
|
-
};
|
|
21
|
-
export declare function forEachEmbeddedFile(file: VirtualFile, cb: (embedded: VirtualFile) => void): void;
|
|
22
|
-
export {};
|