@volar/typescript 1.9.2 → 1.10.1
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LanguageContext } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import { ServiceEnvironment } from '@volar/language-service';
|
|
3
4
|
export declare function createLanguageServiceHost(ctx: LanguageContext, ts: typeof import('typescript/lib/tsserverlibrary'), sys: ts.System & {
|
|
4
5
|
version?: number;
|
|
5
|
-
}): ts.LanguageServiceHost;
|
|
6
|
+
}, env: ServiceEnvironment | undefined): ts.LanguageServiceHost;
|
|
@@ -4,7 +4,7 @@ exports.createLanguageServiceHost = void 0;
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const utilities_1 = require("./typescript/utilities");
|
|
6
6
|
const fileVersions = new Map();
|
|
7
|
-
function createLanguageServiceHost(ctx, ts, sys) {
|
|
7
|
+
function createLanguageServiceHost(ctx, ts, sys, env) {
|
|
8
8
|
let lastProjectVersion;
|
|
9
9
|
let tsProjectVersion = 0;
|
|
10
10
|
let tsFileNames = [];
|
|
@@ -15,8 +15,6 @@ function createLanguageServiceHost(ctx, ts, sys) {
|
|
|
15
15
|
getCancellationToken: ctx.host.getCancellationToken ? () => ctx.host.getCancellationToken() : undefined,
|
|
16
16
|
getLocalizedDiagnosticMessages: ctx.host.getLocalizedDiagnosticMessages ? () => ctx.host.getLocalizedDiagnosticMessages() : undefined,
|
|
17
17
|
getProjectReferences: ctx.host.getProjectReferences ? () => ctx.host.getProjectReferences() : undefined,
|
|
18
|
-
resolveModuleNames: ctx.host.resolveModuleNames ? (...args) => ctx.host.resolveModuleNames(...args) : undefined,
|
|
19
|
-
resolveModuleNameLiterals: ctx.host.resolveModuleNameLiterals ? (...args) => ctx.host.resolveModuleNameLiterals(...args) : undefined,
|
|
20
18
|
getDefaultLibFileName: (options) => {
|
|
21
19
|
try {
|
|
22
20
|
return ts.getDefaultLibFilePath(options);
|
|
@@ -68,6 +66,35 @@ function createLanguageServiceHost(ctx, ts, sys) {
|
|
|
68
66
|
},
|
|
69
67
|
};
|
|
70
68
|
const fsFileSnapshots = new Map();
|
|
69
|
+
if (ctx.host.resolveModuleName) {
|
|
70
|
+
// TODO: can this share between monorepo packages?
|
|
71
|
+
const moduleCache = ts.createModuleResolutionCache(_tsHost.getCurrentDirectory(), _tsHost.useCaseSensitiveFileNames ? s => s : s => s.toLowerCase(), _tsHost.getCompilationSettings());
|
|
72
|
+
const watching = !!env?.onDidChangeWatchedFiles?.(() => {
|
|
73
|
+
moduleCache.clear();
|
|
74
|
+
});
|
|
75
|
+
let lastProjectVersion = ctx.host.getProjectVersion();
|
|
76
|
+
_tsHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, sourceFile) => {
|
|
77
|
+
if (!watching && lastProjectVersion !== ctx.host.getProjectVersion()) {
|
|
78
|
+
lastProjectVersion = ctx.host.getProjectVersion();
|
|
79
|
+
moduleCache.clear();
|
|
80
|
+
}
|
|
81
|
+
return moduleLiterals.map((moduleLiteral) => {
|
|
82
|
+
let moduleName = moduleLiteral.text;
|
|
83
|
+
moduleName = ctx.host.resolveModuleName(moduleName, sourceFile.impliedNodeFormat);
|
|
84
|
+
return ts.resolveModuleName(moduleName, containingFile, options, _tsHost, moduleCache, redirectedReference, sourceFile.impliedNodeFormat);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
_tsHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options, sourceFile) => {
|
|
88
|
+
if (!watching && lastProjectVersion !== ctx.host.getProjectVersion()) {
|
|
89
|
+
lastProjectVersion = ctx.host.getProjectVersion();
|
|
90
|
+
moduleCache.clear();
|
|
91
|
+
}
|
|
92
|
+
return moduleNames.map((moduleName) => {
|
|
93
|
+
moduleName = ctx.host.resolveModuleName(moduleName, sourceFile?.impliedNodeFormat);
|
|
94
|
+
return ts.resolveModuleName(moduleName, containingFile, options, _tsHost, moduleCache, redirectedReference, sourceFile?.impliedNodeFormat).resolvedModule;
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
|
71
98
|
let oldTsVirtualFileSnapshots = new Set();
|
|
72
99
|
let oldOtherVirtualFileSnapshots = new Set();
|
|
73
100
|
return new Proxy(_tsHost, {
|
|
@@ -212,6 +239,27 @@ function createLanguageServiceHost(ctx, ts, sys) {
|
|
|
212
239
|
|| tsFileNames.some(fileName => fileName.toLowerCase().startsWith(dirName.toLowerCase()));
|
|
213
240
|
}
|
|
214
241
|
function fileExists(fileName) {
|
|
242
|
+
// fill external virtual files
|
|
243
|
+
const ext = fileName.substring(fileName.lastIndexOf('.'));
|
|
244
|
+
if (ext === '.js'
|
|
245
|
+
|| ext === '.ts'
|
|
246
|
+
|| ext === '.jsx'
|
|
247
|
+
|| ext === '.tsx') {
|
|
248
|
+
/**
|
|
249
|
+
* If try to access a external .vue file that outside of the project,
|
|
250
|
+
* the file will not process by language service host,
|
|
251
|
+
* so virtual file will not be created.
|
|
252
|
+
*
|
|
253
|
+
* We try to create virtual file here.
|
|
254
|
+
*/
|
|
255
|
+
const sourceFileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
|
256
|
+
if (!ctx.virtualFiles.hasSource(sourceFileName)) {
|
|
257
|
+
const scriptSnapshot = getScriptSnapshot(sourceFileName);
|
|
258
|
+
if (scriptSnapshot) {
|
|
259
|
+
ctx.virtualFiles.updateSource(sourceFileName, scriptSnapshot, ctx.host.getLanguageId?.(sourceFileName));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
215
263
|
// virtual files
|
|
216
264
|
if (ctx.virtualFiles.hasVirtualFile(fileName)) {
|
|
217
265
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"directory": "packages/typescript"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.
|
|
16
|
+
"@volar/language-core": "1.10.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@volar/language-service": "1.
|
|
19
|
+
"@volar/language-service": "1.10.1"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "65775648936d786847511f3d8bdd8a3d1dca2e4e"
|
|
22
22
|
}
|