@volar/language-core 1.0.18 → 1.0.20
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/documentRegistry.d.ts +2 -2
- package/out/documentRegistry.js +37 -28
- package/out/languageContext.d.ts +1 -1
- package/out/languageContext.js +17 -13
- package/out/types.d.ts +1 -1
- package/package.json +3 -4
|
@@ -2,18 +2,18 @@ import { SourceMap } from '@volar/source-map';
|
|
|
2
2
|
import { MirrorMap } from './sourceMaps';
|
|
3
3
|
import type { LanguageModule, FileRangeCapabilities, VirtualFile } from './types';
|
|
4
4
|
export type VirtualFiles = ReturnType<typeof createVirtualFiles>;
|
|
5
|
-
type
|
|
5
|
+
type Source = [
|
|
6
6
|
string,
|
|
7
7
|
ts.IScriptSnapshot,
|
|
8
8
|
VirtualFile,
|
|
9
9
|
LanguageModule
|
|
10
10
|
];
|
|
11
11
|
export declare function createVirtualFiles(languageModules: LanguageModule[]): {
|
|
12
|
+
all: Map<string, Source>;
|
|
12
13
|
update(fileName: string, snapshot: ts.IScriptSnapshot): VirtualFile | undefined;
|
|
13
14
|
delete(fileName: string): void;
|
|
14
15
|
get(fileName: string): readonly [import("typescript/lib/tsserverlibrary").IScriptSnapshot, VirtualFile] | undefined;
|
|
15
16
|
hasSourceFile: (fileName: string) => boolean;
|
|
16
|
-
all: () => Row[];
|
|
17
17
|
getMirrorMap: (file: VirtualFile) => MirrorMap | undefined;
|
|
18
18
|
getMaps: (virtualFile: VirtualFile) => [string, SourceMap<FileRangeCapabilities>][];
|
|
19
19
|
getSourceByVirtualFileName(fileName: string): readonly [string, import("typescript/lib/tsserverlibrary").IScriptSnapshot, VirtualFile] | undefined;
|
package/out/documentRegistry.js
CHANGED
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
2
|
exports.forEachEmbeddedFile = exports.createVirtualFiles = void 0;
|
|
3
3
|
const source_map_1 = require("@volar/source-map");
|
|
4
|
-
const reactivity_1 = require("@vue/reactivity");
|
|
5
4
|
const sourceMaps_1 = require("./sourceMaps");
|
|
6
5
|
function createVirtualFiles(languageModules) {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const virtualFileNameToSource = (0, reactivity_1.computed)(() => {
|
|
10
|
-
const map = new Map();
|
|
11
|
-
for (const row of all.value) {
|
|
12
|
-
forEachEmbeddedFile(row[2], file => {
|
|
13
|
-
map.set(normalizePath(file.fileName), [file, row]);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return map;
|
|
17
|
-
});
|
|
6
|
+
const sourceFiles = new Map();
|
|
7
|
+
const virtualFiles = new Map();
|
|
18
8
|
const virtualFileToSourceMapsMap = new WeakMap();
|
|
19
9
|
const virtualFileToMirrorMap = new WeakMap();
|
|
10
|
+
let sourceFilesDirty = true;
|
|
20
11
|
return {
|
|
12
|
+
all: sourceFiles,
|
|
21
13
|
update(fileName, snapshot) {
|
|
22
14
|
const key = normalizePath(fileName);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const value = sourceFiles.get(key);
|
|
16
|
+
if (value) {
|
|
17
|
+
const virtualFile = value[2];
|
|
18
|
+
value[1] = snapshot;
|
|
19
|
+
value[3].updateFile(virtualFile, snapshot);
|
|
20
|
+
sourceFilesDirty = true;
|
|
27
21
|
return virtualFile; // updated
|
|
28
22
|
}
|
|
29
23
|
for (const languageModule of languageModules) {
|
|
30
24
|
const virtualFile = languageModule.createFile(fileName, snapshot);
|
|
31
25
|
if (virtualFile) {
|
|
32
|
-
|
|
26
|
+
sourceFiles.set(key, [fileName, snapshot, virtualFile, languageModule]);
|
|
27
|
+
sourceFilesDirty = true;
|
|
33
28
|
return virtualFile; // created
|
|
34
29
|
}
|
|
35
30
|
}
|
|
@@ -37,27 +32,29 @@ function createVirtualFiles(languageModules) {
|
|
|
37
32
|
delete(fileName) {
|
|
38
33
|
var _a, _b;
|
|
39
34
|
const key = normalizePath(fileName);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
const value = sourceFiles.get(key);
|
|
36
|
+
if (value) {
|
|
37
|
+
const virtualFile = value[2];
|
|
38
|
+
(_b = (_a = value[3]).deleteFile) === null || _b === void 0 ? void 0 : _b.call(_a, virtualFile);
|
|
39
|
+
sourceFiles.delete(key); // deleted
|
|
40
|
+
sourceFilesDirty = true;
|
|
44
41
|
}
|
|
45
42
|
},
|
|
46
43
|
get(fileName) {
|
|
47
44
|
const key = normalizePath(fileName);
|
|
48
|
-
|
|
45
|
+
const value = sourceFiles.get(key);
|
|
46
|
+
if (value) {
|
|
49
47
|
return [
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
value[1],
|
|
49
|
+
value[2],
|
|
52
50
|
];
|
|
53
51
|
}
|
|
54
52
|
},
|
|
55
|
-
hasSourceFile: (fileName) =>
|
|
56
|
-
all: () => all.value,
|
|
53
|
+
hasSourceFile: (fileName) => sourceFiles.has(normalizePath(fileName)),
|
|
57
54
|
getMirrorMap: getMirrorMap,
|
|
58
55
|
getMaps: getSourceMaps,
|
|
59
56
|
getSourceByVirtualFileName(fileName) {
|
|
60
|
-
const source =
|
|
57
|
+
const source = getVirtualFilesMap().get(normalizePath(fileName));
|
|
61
58
|
if (source) {
|
|
62
59
|
return [
|
|
63
60
|
source[1][0],
|
|
@@ -67,6 +64,18 @@ function createVirtualFiles(languageModules) {
|
|
|
67
64
|
}
|
|
68
65
|
},
|
|
69
66
|
};
|
|
67
|
+
function getVirtualFilesMap() {
|
|
68
|
+
if (sourceFilesDirty) {
|
|
69
|
+
sourceFilesDirty = false;
|
|
70
|
+
virtualFiles.clear();
|
|
71
|
+
for (const [_, row] of sourceFiles) {
|
|
72
|
+
forEachEmbeddedFile(row[2], file => {
|
|
73
|
+
virtualFiles.set(normalizePath(file.fileName), [file, row]);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return virtualFiles;
|
|
78
|
+
}
|
|
70
79
|
function getSourceMaps(virtualFile) {
|
|
71
80
|
let sourceMapsBySourceFileName = virtualFileToSourceMapsMap.get(virtualFile.snapshot);
|
|
72
81
|
if (!sourceMapsBySourceFileName) {
|
|
@@ -78,7 +87,7 @@ function createVirtualFiles(languageModules) {
|
|
|
78
87
|
sources.add(map.source);
|
|
79
88
|
}
|
|
80
89
|
for (const source of sources) {
|
|
81
|
-
const sourceFileName = source !== null && source !== void 0 ? source :
|
|
90
|
+
const sourceFileName = source !== null && source !== void 0 ? source : getVirtualFilesMap().get(normalizePath(virtualFile.fileName))[1][0];
|
|
82
91
|
if (!sourceMapsBySourceFileName.has(sourceFileName)) {
|
|
83
92
|
sourceMapsBySourceFileName.set(sourceFileName, [
|
|
84
93
|
sourceFileName,
|
package/out/languageContext.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ export declare function createLanguageContext(host: LanguageServiceHost, languag
|
|
|
6
6
|
languageServiceHost: ts.LanguageServiceHost;
|
|
7
7
|
};
|
|
8
8
|
virtualFiles: {
|
|
9
|
+
all: Map<string, [string, ts.IScriptSnapshot, import("./types").VirtualFile, LanguageModule<import("./types").VirtualFile>]>;
|
|
9
10
|
update(fileName: string, snapshot: ts.IScriptSnapshot): import("./types").VirtualFile | undefined;
|
|
10
11
|
delete(fileName: string): void;
|
|
11
12
|
get(fileName: string): readonly [ts.IScriptSnapshot, import("./types").VirtualFile] | undefined;
|
|
12
13
|
hasSourceFile: (fileName: string) => boolean;
|
|
13
|
-
all: () => [string, ts.IScriptSnapshot, import("./types").VirtualFile, LanguageModule<import("./types").VirtualFile>][];
|
|
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
|
getSourceByVirtualFileName(fileName: string): readonly [string, ts.IScriptSnapshot, import("./types").VirtualFile] | undefined;
|
package/out/languageContext.js
CHANGED
|
@@ -55,7 +55,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
55
55
|
readDirectory: (_path, extensions, exclude, include, depth) => {
|
|
56
56
|
var _a, _b;
|
|
57
57
|
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 [fileName] of virtualFiles.all
|
|
58
|
+
for (const [, [fileName]] of virtualFiles.all) {
|
|
59
59
|
const vuePath2 = path_1.posix.join(_path, path_1.posix.basename(fileName));
|
|
60
60
|
if (path_1.posix.relative(_path.toLowerCase(), fileName.toLowerCase()).startsWith('..')) {
|
|
61
61
|
continue;
|
|
@@ -70,16 +70,19 @@ function createLanguageContext(host, languageModules) {
|
|
|
70
70
|
return result;
|
|
71
71
|
},
|
|
72
72
|
getScriptKind(fileName) {
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
if (ts) {
|
|
74
|
+
if (virtualFiles.hasSourceFile(fileName))
|
|
75
|
+
return ts.ScriptKind.Deferred;
|
|
76
|
+
switch (path_1.posix.extname(fileName)) {
|
|
77
|
+
case '.js': return ts.ScriptKind.JS;
|
|
78
|
+
case '.jsx': return ts.ScriptKind.JSX;
|
|
79
|
+
case '.ts': return ts.ScriptKind.TS;
|
|
80
|
+
case '.tsx': return ts.ScriptKind.TSX;
|
|
81
|
+
case '.json': return ts.ScriptKind.JSON;
|
|
82
|
+
default: return ts.ScriptKind.Unknown;
|
|
83
|
+
}
|
|
82
84
|
}
|
|
85
|
+
return 0;
|
|
83
86
|
},
|
|
84
87
|
};
|
|
85
88
|
return {
|
|
@@ -109,13 +112,14 @@ function createLanguageContext(host, languageModules) {
|
|
|
109
112
|
let virtualFilesUpdatedNum = 0;
|
|
110
113
|
const remainRootFiles = new Set(host.getScriptFileNames());
|
|
111
114
|
// .vue
|
|
112
|
-
for (const [fileName] of virtualFiles.all
|
|
115
|
+
for (const [_, [fileName]] of virtualFiles.all) {
|
|
113
116
|
remainRootFiles.delete(fileName);
|
|
114
117
|
const snapshot = host.getScriptSnapshot(fileName);
|
|
115
118
|
if (!snapshot) {
|
|
116
119
|
// delete
|
|
117
120
|
virtualFiles.delete(fileName);
|
|
118
121
|
shouldUpdateTsProject = true;
|
|
122
|
+
virtualFilesUpdatedNum++;
|
|
119
123
|
continue;
|
|
120
124
|
}
|
|
121
125
|
const newVersion = host.getScriptVersion(fileName);
|
|
@@ -163,7 +167,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
163
167
|
shouldUpdateTsProject = true;
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
|
-
for (const [_1, _2, virtualFile] of virtualFiles.all
|
|
170
|
+
for (const [_, [_1, _2, virtualFile]] of virtualFiles.all) {
|
|
167
171
|
if (!shouldUpdateTsProject) {
|
|
168
172
|
(0, documentRegistry_1.forEachEmbeddedFile)(virtualFile, embedded => {
|
|
169
173
|
var _a;
|
|
@@ -181,7 +185,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
181
185
|
}
|
|
182
186
|
function getScriptFileNames() {
|
|
183
187
|
const tsFileNames = new Set();
|
|
184
|
-
for (const [_1, _2, sourceFile] of virtualFiles.all
|
|
188
|
+
for (const [_, [_1, _2, sourceFile]] of virtualFiles.all) {
|
|
185
189
|
(0, documentRegistry_1.forEachEmbeddedFile)(sourceFile, embedded => {
|
|
186
190
|
if (embedded.kind === types_1.FileKind.TypeScriptHostFile) {
|
|
187
191
|
tsFileNames.add(embedded.fileName); // virtual .ts
|
package/out/types.d.ts
CHANGED
|
@@ -52,6 +52,6 @@ export interface LanguageModule<T extends VirtualFile = VirtualFile> {
|
|
|
52
52
|
proxyLanguageServiceHost?(host: LanguageServiceHost): Partial<LanguageServiceHost>;
|
|
53
53
|
}
|
|
54
54
|
export interface LanguageServiceHost extends ts.LanguageServiceHost {
|
|
55
|
-
getTypeScriptModule(): typeof import('typescript/lib/tsserverlibrary');
|
|
55
|
+
getTypeScriptModule(): typeof import('typescript/lib/tsserverlibrary') | undefined;
|
|
56
56
|
isTsc?: boolean;
|
|
57
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
"directory": "packages/language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/source-map": "1.0.
|
|
17
|
-
"@vue/reactivity": "^3.2.45",
|
|
16
|
+
"@volar/source-map": "1.0.20",
|
|
18
17
|
"muggle-string": "^0.1.0"
|
|
19
18
|
},
|
|
20
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "e00f068e812677791c93efe9cf20995764350ec6"
|
|
21
20
|
}
|