@volar/language-core 1.4.0-alpha.0 → 1.4.0-alpha.10
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.js +1 -0
- package/out/languageContext.d.ts +3 -1
- package/out/languageContext.js +10 -14
- package/out/sourceMaps.js +1 -0
- package/out/types.d.ts +0 -1
- package/out/types.js +1 -0
- package/out/virtualFiles.d.ts +2 -1
- package/out/virtualFiles.js +3 -3
- package/package.json +3 -3
package/out/index.js
CHANGED
package/out/languageContext.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { LanguageModule, LanguageServiceHost } from './types';
|
|
3
3
|
export type LanguageContext = ReturnType<typeof createLanguageContext>;
|
|
4
|
-
export declare function createLanguageContext(host: LanguageServiceHost,
|
|
4
|
+
export declare function createLanguageContext(host: LanguageServiceHost, modules: {
|
|
5
|
+
typescript?: typeof import('typescript/lib/tsserverlibrary');
|
|
6
|
+
}, languageModules: LanguageModule[]): {
|
|
5
7
|
typescript: {
|
|
6
8
|
languageServiceHost: ts.LanguageServiceHost;
|
|
7
9
|
};
|
package/out/languageContext.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
3
|
exports.createLanguageContext = void 0;
|
|
3
4
|
const path_1 = require("path");
|
|
4
5
|
const virtualFiles_1 = require("./virtualFiles");
|
|
5
6
|
const types_1 = require("./types");
|
|
6
|
-
function createLanguageContext(host, languageModules) {
|
|
7
|
-
var _a;
|
|
7
|
+
function createLanguageContext(host, modules, languageModules) {
|
|
8
8
|
for (const languageModule of languageModules.reverse()) {
|
|
9
9
|
if (languageModule.proxyLanguageServiceHost) {
|
|
10
10
|
const proxyApis = languageModule.proxyLanguageServiceHost(host);
|
|
@@ -21,7 +21,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
21
21
|
let lastProjectVersion;
|
|
22
22
|
let tsProjectVersion = 0;
|
|
23
23
|
const virtualFiles = (0, virtualFiles_1.createVirtualFiles)(languageModules);
|
|
24
|
-
const ts =
|
|
24
|
+
const ts = modules.typescript;
|
|
25
25
|
const scriptSnapshots = new Map();
|
|
26
26
|
const sourceTsFileVersions = new Map();
|
|
27
27
|
const sourceFileVersions = new Map();
|
|
@@ -29,7 +29,6 @@ function createLanguageContext(host, languageModules) {
|
|
|
29
29
|
const _tsHost = {
|
|
30
30
|
fileExists: host.fileExists
|
|
31
31
|
? fileName => {
|
|
32
|
-
var _a, _b;
|
|
33
32
|
const ext = fileName.substring(fileName.lastIndexOf('.'));
|
|
34
33
|
if (ext === '.js'
|
|
35
34
|
|| ext === '.ts'
|
|
@@ -46,14 +45,14 @@ function createLanguageContext(host, languageModules) {
|
|
|
46
45
|
if (!virtualFiles.hasSource(sourceFileName)) {
|
|
47
46
|
const scriptSnapshot = host.getScriptSnapshot(sourceFileName);
|
|
48
47
|
if (scriptSnapshot) {
|
|
49
|
-
virtualFiles.updateSource(sourceFileName, scriptSnapshot,
|
|
48
|
+
virtualFiles.updateSource(sourceFileName, scriptSnapshot, host.getScriptLanguageId?.(sourceFileName));
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
if (virtualFiles.hasVirtualFile(fileName)) {
|
|
54
53
|
return true;
|
|
55
54
|
}
|
|
56
|
-
return !!
|
|
55
|
+
return !!host.fileExists?.(fileName);
|
|
57
56
|
}
|
|
58
57
|
: undefined,
|
|
59
58
|
getProjectVersion: () => {
|
|
@@ -63,8 +62,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
63
62
|
getScriptVersion,
|
|
64
63
|
getScriptSnapshot,
|
|
65
64
|
readDirectory: (_path, extensions, exclude, include, depth) => {
|
|
66
|
-
|
|
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 : [];
|
|
65
|
+
const result = host.readDirectory?.(_path, extensions, exclude, include, depth) ?? [];
|
|
68
66
|
for (const { fileName } of virtualFiles.allSources()) {
|
|
69
67
|
const vuePath2 = path_1.posix.join(_path, path_1.posix.basename(fileName));
|
|
70
68
|
if (path_1.posix.relative(_path.toLowerCase(), fileName.toLowerCase()).startsWith('..')) {
|
|
@@ -112,8 +110,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
112
110
|
}),
|
|
113
111
|
};
|
|
114
112
|
function update() {
|
|
115
|
-
|
|
116
|
-
const newProjectVersion = (_a = host.getProjectVersion) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
113
|
+
const newProjectVersion = host.getProjectVersion?.();
|
|
117
114
|
const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion;
|
|
118
115
|
lastProjectVersion = newProjectVersion;
|
|
119
116
|
if (!shouldUpdate)
|
|
@@ -136,7 +133,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
136
133
|
if (sourceFileVersions.get(fileName) !== newVersion) {
|
|
137
134
|
// update
|
|
138
135
|
sourceFileVersions.set(fileName, newVersion);
|
|
139
|
-
virtualFiles.updateSource(fileName, snapshot,
|
|
136
|
+
virtualFiles.updateSource(fileName, snapshot, host.getScriptLanguageId?.(fileName));
|
|
140
137
|
virtualFilesUpdatedNum++;
|
|
141
138
|
}
|
|
142
139
|
}
|
|
@@ -148,7 +145,7 @@ function createLanguageContext(host, languageModules) {
|
|
|
148
145
|
for (const fileName of [...remainRootFiles]) {
|
|
149
146
|
const snapshot = host.getScriptSnapshot(fileName);
|
|
150
147
|
if (snapshot) {
|
|
151
|
-
const virtualFile = virtualFiles.updateSource(fileName, snapshot,
|
|
148
|
+
const virtualFile = virtualFiles.updateSource(fileName, snapshot, host.getScriptLanguageId?.(fileName));
|
|
152
149
|
if (virtualFile) {
|
|
153
150
|
remainRootFiles.delete(fileName);
|
|
154
151
|
}
|
|
@@ -180,9 +177,8 @@ function createLanguageContext(host, languageModules) {
|
|
|
180
177
|
for (const { root: rootVirtualFile } of virtualFiles.allSources()) {
|
|
181
178
|
if (!shouldUpdateTsProject) {
|
|
182
179
|
(0, virtualFiles_1.forEachEmbeddedFile)(rootVirtualFile, embedded => {
|
|
183
|
-
var _a;
|
|
184
180
|
if (embedded.kind === types_1.FileKind.TypeScriptHostFile) {
|
|
185
|
-
if (virtualFileVersions.has(embedded.fileName) &&
|
|
181
|
+
if (virtualFileVersions.has(embedded.fileName) && virtualFileVersions.get(embedded.fileName)?.virtualFileSnapshot !== embedded.snapshot) {
|
|
186
182
|
shouldUpdateTsProject = true;
|
|
187
183
|
}
|
|
188
184
|
}
|
package/out/sourceMaps.js
CHANGED
package/out/types.d.ts
CHANGED
|
@@ -59,7 +59,6 @@ export interface LanguageModule<T extends VirtualFile = VirtualFile> {
|
|
|
59
59
|
proxyLanguageServiceHost?(host: LanguageServiceHost): Partial<LanguageServiceHost>;
|
|
60
60
|
}
|
|
61
61
|
export interface LanguageServiceHost extends ts.LanguageServiceHost {
|
|
62
|
-
getTypeScriptModule?(): typeof import('typescript/lib/tsserverlibrary');
|
|
63
62
|
getScriptLanguageId?(fileName: string): string | undefined;
|
|
64
63
|
isTsc?: boolean;
|
|
65
64
|
}
|
package/out/types.js
CHANGED
package/out/virtualFiles.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SourceMap } from '@volar/source-map';
|
|
2
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
3
|
import { MirrorMap } from './sourceMaps';
|
|
3
|
-
import type {
|
|
4
|
+
import type { FileRangeCapabilities, LanguageModule, VirtualFile } from './types';
|
|
4
5
|
export type VirtualFiles = ReturnType<typeof createVirtualFiles>;
|
|
5
6
|
export interface Source {
|
|
6
7
|
fileName: string;
|
package/out/virtualFiles.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
3
|
exports.forEachEmbeddedFile = exports.createVirtualFiles = void 0;
|
|
3
4
|
const source_map_1 = require("@volar/source-map");
|
|
@@ -31,11 +32,10 @@ function createVirtualFiles(languageModules) {
|
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
34
|
deleteSource(fileName) {
|
|
34
|
-
var _a, _b;
|
|
35
35
|
const key = normalizePath(fileName);
|
|
36
36
|
const value = sourceFiles.get(key);
|
|
37
37
|
if (value) {
|
|
38
|
-
|
|
38
|
+
value.languageModule.deleteFile?.(value.root);
|
|
39
39
|
sourceFiles.delete(key); // deleted
|
|
40
40
|
sourceFilesDirty = true;
|
|
41
41
|
}
|
|
@@ -81,7 +81,7 @@ function createVirtualFiles(languageModules) {
|
|
|
81
81
|
sources.add(map.source);
|
|
82
82
|
}
|
|
83
83
|
for (const source of sources) {
|
|
84
|
-
const sourceFileName = source
|
|
84
|
+
const sourceFileName = source ?? getVirtualFilesMap().get(normalizePath(virtualFile.fileName)).source.fileName;
|
|
85
85
|
if (!sourceMapsBySourceFileName.has(sourceFileName)) {
|
|
86
86
|
sourceMapsBySourceFileName.set(sourceFileName, [
|
|
87
87
|
sourceFileName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.10",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/source-map": "1.4.0-alpha.
|
|
16
|
+
"@volar/source-map": "1.4.0-alpha.10"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "715bc5f17a0d1cadd4190712dcaff732989eb330"
|
|
19
19
|
}
|