@volar/typescript 1.8.3 → 1.9.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.
- package/out/languageServiceHost.js +7 -8
- package/out/serverPlugin.js +8 -2
- package/out/sys.js +42 -34
- package/package.json +4 -4
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createLanguageServiceHost = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const utilities_1 = require("./typescript/utilities");
|
|
6
|
+
const fileVersions = new Map();
|
|
6
7
|
function createLanguageServiceHost(ctx, ts, sys) {
|
|
7
8
|
let lastProjectVersion;
|
|
8
9
|
let tsProjectVersion = 0;
|
|
9
10
|
let tsFileNames = [];
|
|
10
11
|
const _tsHost = {
|
|
11
12
|
...sys,
|
|
12
|
-
getCurrentDirectory: () => ctx.host.
|
|
13
|
+
getCurrentDirectory: () => ctx.host.workspacePath,
|
|
13
14
|
getCompilationSettings: () => ctx.host.getCompilationSettings(),
|
|
14
15
|
getCancellationToken: ctx.host.getCancellationToken ? () => ctx.host.getCancellationToken() : undefined,
|
|
15
16
|
getLocalizedDiagnosticMessages: ctx.host.getLocalizedDiagnosticMessages ? () => ctx.host.getLocalizedDiagnosticMessages() : undefined,
|
|
@@ -67,7 +68,6 @@ function createLanguageServiceHost(ctx, ts, sys) {
|
|
|
67
68
|
},
|
|
68
69
|
};
|
|
69
70
|
const fsFileSnapshots = new Map();
|
|
70
|
-
const fileVersions = new Map();
|
|
71
71
|
let oldTsVirtualFileSnapshots = new Set();
|
|
72
72
|
let oldOtherVirtualFileSnapshots = new Set();
|
|
73
73
|
return new Proxy(_tsHost, {
|
|
@@ -119,7 +119,7 @@ function createLanguageServiceHost(ctx, ts, sys) {
|
|
|
119
119
|
tsFileNames = [...tsFileNamesSet];
|
|
120
120
|
}
|
|
121
121
|
function readDirectory(dirName, extensions, excludes, includes, depth) {
|
|
122
|
-
let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, ctx.host.
|
|
122
|
+
let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, ctx.host.workspacePath, depth, (dirPath) => {
|
|
123
123
|
const files = [];
|
|
124
124
|
for (const fileName of tsFileNames) {
|
|
125
125
|
if (fileName.toLowerCase().startsWith(dirPath.toLowerCase())) {
|
|
@@ -196,14 +196,13 @@ function createLanguageServiceHost(ctx, ts, sys) {
|
|
|
196
196
|
const snapshot = virtualFile?.snapshot ?? ctx.host.getScriptSnapshot(fileName);
|
|
197
197
|
if (snapshot) {
|
|
198
198
|
if (!fileVersions.has(fileName)) {
|
|
199
|
-
fileVersions.set(fileName, {
|
|
199
|
+
fileVersions.set(fileName, { lastVersion: 0, snapshotVersions: new WeakMap() });
|
|
200
200
|
}
|
|
201
201
|
const version = fileVersions.get(fileName);
|
|
202
|
-
if (version.snapshot
|
|
203
|
-
version.
|
|
204
|
-
version.snapshot = snapshot;
|
|
202
|
+
if (!version.snapshotVersions.has(snapshot)) {
|
|
203
|
+
version.snapshotVersions.set(snapshot, version.lastVersion++);
|
|
205
204
|
}
|
|
206
|
-
return version.
|
|
205
|
+
return version.snapshotVersions.get(snapshot).toString();
|
|
207
206
|
}
|
|
208
207
|
// fs files
|
|
209
208
|
return sys.getModifiedTime?.(fileName)?.valueOf().toString() ?? '';
|
package/out/serverPlugin.js
CHANGED
|
@@ -29,7 +29,10 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
|
|
|
29
29
|
const resolvedModules = resolveModuleNameLiterals(moduleNames, containingFile, redirectedReference, options, ...rest);
|
|
30
30
|
return moduleNames.map((name, i) => {
|
|
31
31
|
if (exts.some(ext => name.text.endsWith(ext))) {
|
|
32
|
-
|
|
32
|
+
const resolved = resolveModuleName(name.text, containingFile, options, redirectedReference);
|
|
33
|
+
if (resolved.resolvedModule) {
|
|
34
|
+
return resolved;
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
37
|
return resolvedModules[i];
|
|
35
38
|
});
|
|
@@ -40,7 +43,10 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
|
|
|
40
43
|
const resolvedModules = resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options, containingSourceFile);
|
|
41
44
|
return moduleNames.map((name, i) => {
|
|
42
45
|
if (exts.some(ext => name.endsWith(ext))) {
|
|
43
|
-
|
|
46
|
+
const resolved = resolveModuleName(name, containingFile, options, redirectedReference);
|
|
47
|
+
if (resolved.resolvedModule) {
|
|
48
|
+
return resolved.resolvedModule;
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
return resolvedModules[i];
|
|
46
52
|
});
|
package/out/sys.js
CHANGED
|
@@ -83,16 +83,6 @@ function createSys(ts, env) {
|
|
|
83
83
|
}
|
|
84
84
|
return path_1.posix.resolve(fsPath).replace(/\\/g, '/');
|
|
85
85
|
}
|
|
86
|
-
function getModifiedTime(fileName) {
|
|
87
|
-
fileName = resolvePath(fileName);
|
|
88
|
-
const dirPath = path_1.posix.dirname(fileName);
|
|
89
|
-
const dir = getDir(dirPath);
|
|
90
|
-
const name = path_1.posix.basename(fileName);
|
|
91
|
-
const modifiedTime = dir.files[name]?.modifiedTime;
|
|
92
|
-
if (modifiedTime !== undefined) {
|
|
93
|
-
return new Date(modifiedTime);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
86
|
function readFile(fileName, encoding) {
|
|
97
87
|
fileName = resolvePath(fileName);
|
|
98
88
|
const dirPath = path_1.posix.dirname(fileName);
|
|
@@ -124,33 +114,55 @@ function createSys(ts, env) {
|
|
|
124
114
|
}
|
|
125
115
|
return dir.exists;
|
|
126
116
|
}
|
|
117
|
+
function getModifiedTime(fileName) {
|
|
118
|
+
fileName = resolvePath(fileName);
|
|
119
|
+
const file = getFile(fileName);
|
|
120
|
+
if (file.modifiedTime === undefined) {
|
|
121
|
+
file.modifiedTime = new Date(0);
|
|
122
|
+
handleStat(fileName, file);
|
|
123
|
+
}
|
|
124
|
+
return file.modifiedTime;
|
|
125
|
+
}
|
|
127
126
|
function fileExists(fileName) {
|
|
128
127
|
fileName = resolvePath(fileName);
|
|
129
|
-
const
|
|
130
|
-
const baseName = path_1.posix.basename(fileName);
|
|
131
|
-
const dir = getDir(dirPath);
|
|
132
|
-
const file = dir.files[baseName] ??= {};
|
|
128
|
+
const file = getFile(fileName);
|
|
133
129
|
if (file.exists === undefined) {
|
|
134
130
|
file.exists = false;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
131
|
+
handleStat(fileName, file);
|
|
132
|
+
}
|
|
133
|
+
return file.exists;
|
|
134
|
+
}
|
|
135
|
+
function handleStat(fileName, file) {
|
|
136
|
+
const result = env.fs?.stat(env.fileNameToUri(fileName));
|
|
137
|
+
if (typeof result === 'object' && 'then' in result) {
|
|
138
|
+
const promise = result;
|
|
139
|
+
promises.add(promise);
|
|
140
|
+
result.then(result => {
|
|
141
|
+
promises.delete(promise);
|
|
150
142
|
file.exists = result?.type === 1;
|
|
143
|
+
if (result) {
|
|
144
|
+
file.modifiedTime = new Date(result.mtime);
|
|
145
|
+
}
|
|
146
|
+
if (file.exists) {
|
|
147
|
+
file.requested = false;
|
|
148
|
+
version++;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
file.exists = result?.type === 1;
|
|
154
|
+
if (result) {
|
|
155
|
+
file.modifiedTime = new Date(result.mtime);
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
|
-
|
|
158
|
+
}
|
|
159
|
+
function getFile(fileName) {
|
|
160
|
+
fileName = resolvePath(fileName);
|
|
161
|
+
const dirPath = path_1.posix.dirname(fileName);
|
|
162
|
+
const baseName = path_1.posix.basename(fileName);
|
|
163
|
+
const dir = getDir(dirPath);
|
|
164
|
+
const file = dir.files[baseName] ??= {};
|
|
165
|
+
return file;
|
|
154
166
|
}
|
|
155
167
|
// for import path completion
|
|
156
168
|
function getDirectories(dirName) {
|
|
@@ -190,8 +202,6 @@ function createSys(ts, env) {
|
|
|
190
202
|
if (result !== undefined) {
|
|
191
203
|
file.exists = true;
|
|
192
204
|
file.text = result;
|
|
193
|
-
const time = Date.now();
|
|
194
|
-
file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
|
|
195
205
|
version++;
|
|
196
206
|
}
|
|
197
207
|
else {
|
|
@@ -202,8 +212,6 @@ function createSys(ts, env) {
|
|
|
202
212
|
else if (result !== undefined) {
|
|
203
213
|
file.exists = true;
|
|
204
214
|
file.text = result;
|
|
205
|
-
const time = Date.now();
|
|
206
|
-
file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
|
|
207
215
|
}
|
|
208
216
|
else {
|
|
209
217
|
file.exists = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/typescript",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.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.9.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@volar/language-service": "1.
|
|
19
|
+
"@volar/language-service": "1.9.1"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "68f064d587ef230b2f8a90157b1f7133b33f1d33"
|
|
22
22
|
}
|