@volar/language-core 1.0.18 → 1.0.19
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.
|
@@ -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;
|
|
@@ -109,13 +109,14 @@ function createLanguageContext(host, languageModules) {
|
|
|
109
109
|
let virtualFilesUpdatedNum = 0;
|
|
110
110
|
const remainRootFiles = new Set(host.getScriptFileNames());
|
|
111
111
|
// .vue
|
|
112
|
-
for (const [fileName] of virtualFiles.all
|
|
112
|
+
for (const [_, [fileName]] of virtualFiles.all) {
|
|
113
113
|
remainRootFiles.delete(fileName);
|
|
114
114
|
const snapshot = host.getScriptSnapshot(fileName);
|
|
115
115
|
if (!snapshot) {
|
|
116
116
|
// delete
|
|
117
117
|
virtualFiles.delete(fileName);
|
|
118
118
|
shouldUpdateTsProject = true;
|
|
119
|
+
virtualFilesUpdatedNum++;
|
|
119
120
|
continue;
|
|
120
121
|
}
|
|
121
122
|
const newVersion = host.getScriptVersion(fileName);
|
|
@@ -163,7 +164,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
163
164
|
shouldUpdateTsProject = true;
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
|
-
for (const [_1, _2, virtualFile] of virtualFiles.all
|
|
167
|
+
for (const [_, [_1, _2, virtualFile]] of virtualFiles.all) {
|
|
167
168
|
if (!shouldUpdateTsProject) {
|
|
168
169
|
(0, documentRegistry_1.forEachEmbeddedFile)(virtualFile, embedded => {
|
|
169
170
|
var _a;
|
|
@@ -181,7 +182,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
181
182
|
}
|
|
182
183
|
function getScriptFileNames() {
|
|
183
184
|
const tsFileNames = new Set();
|
|
184
|
-
for (const [_1, _2, sourceFile] of virtualFiles.all
|
|
185
|
+
for (const [_, [_1, _2, sourceFile]] of virtualFiles.all) {
|
|
185
186
|
(0, documentRegistry_1.forEachEmbeddedFile)(sourceFile, embedded => {
|
|
186
187
|
if (embedded.kind === types_1.FileKind.TypeScriptHostFile) {
|
|
187
188
|
tsFileNames.add(embedded.fileName); // virtual .ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
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.19",
|
|
18
17
|
"muggle-string": "^0.1.0"
|
|
19
18
|
},
|
|
20
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "02267fe83a5567b1cae7025e834cf084c8248546"
|
|
21
20
|
}
|