@volar/language-server 1.0.12 → 1.0.14
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/browser.js +19 -2
- package/out/features/customFeatures.js +3 -5
- package/out/node.js +16 -5
- package/out/protocol.d.ts +10 -13
- package/out/protocol.js +13 -16
- package/out/registerFeatures.js +10 -7
- package/out/server.js +2 -2
- package/out/types.d.ts +4 -2
- package/out/utils/config.d.ts +1 -1
- package/out/utils/config.js +3 -2
- package/out/utils/documentServiceHost.d.ts +14 -14
- package/out/utils/documentServiceHost.js +2 -2
- package/out/utils/nodeFileSystemHost.js +1 -1
- package/out/utils/project.d.ts +61 -63
- package/out/utils/project.js +15 -7
- package/out/utils/snapshots.d.ts +4 -5
- package/out/utils/uriMap.d.ts +4 -5
- package/out/utils/uriMap.js +17 -22
- package/out/utils/webFileSystemHost.js +86 -39
- package/out/utils/workspaceProjects.d.ts +10 -11
- package/out/utils/workspaceProjects.js +23 -24
- package/out/utils/workspaces.d.ts +20 -21
- package/out/utils/workspaces.js +2 -4
- package/package.json +5 -5
package/out/utils/snapshots.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
2
|
import * as vscode from 'vscode-languageserver';
|
|
3
3
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
-
import type * as _ from 'vscode-uri';
|
|
5
4
|
interface IncrementalScriptSnapshotChange {
|
|
6
5
|
applied: boolean;
|
|
7
6
|
changeRange: ts.TextChangeRange | undefined;
|
|
@@ -33,10 +32,10 @@ export declare function createSnapshots(connection: vscode.Connection): {
|
|
|
33
32
|
uriGet: (_uri: string) => IncrementalScriptSnapshot | undefined;
|
|
34
33
|
uriHas: (_uri: string) => boolean;
|
|
35
34
|
uriSet: (_uri: string, item: IncrementalScriptSnapshot) => void;
|
|
36
|
-
pathDelete: (
|
|
37
|
-
pathGet: (
|
|
38
|
-
pathHas: (
|
|
39
|
-
pathSet: (
|
|
35
|
+
pathDelete: (path: string) => boolean;
|
|
36
|
+
pathGet: (path: string) => IncrementalScriptSnapshot | undefined;
|
|
37
|
+
pathHas: (path: string) => IncrementalScriptSnapshot | undefined;
|
|
38
|
+
pathSet: (path: string, item: IncrementalScriptSnapshot) => void;
|
|
40
39
|
};
|
|
41
40
|
onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => () => boolean;
|
|
42
41
|
onDidClose: (cb: (params: vscode.DidCloseTextDocumentParams) => void) => () => boolean;
|
package/out/utils/uriMap.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { URI } from 'vscode-uri';
|
|
2
1
|
export * as _ from 'vscode-uri';
|
|
3
2
|
interface Options<T> {
|
|
4
3
|
delete(key: string): boolean;
|
|
@@ -15,8 +14,8 @@ export declare function createUriMap<T>(map?: Options<T>): {
|
|
|
15
14
|
uriGet: (_uri: string) => T | undefined;
|
|
16
15
|
uriHas: (_uri: string) => boolean;
|
|
17
16
|
uriSet: (_uri: string, item: T) => void;
|
|
18
|
-
pathDelete: (
|
|
19
|
-
pathGet: (
|
|
20
|
-
pathHas: (
|
|
21
|
-
pathSet: (
|
|
17
|
+
pathDelete: (path: string) => boolean;
|
|
18
|
+
pathGet: (path: string) => T | undefined;
|
|
19
|
+
pathHas: (path: string) => T | undefined;
|
|
20
|
+
pathSet: (path: string, item: T) => void;
|
|
22
21
|
};
|
package/out/utils/uriMap.js
CHANGED
|
@@ -4,8 +4,8 @@ const vscode_uri_1 = require("vscode-uri");
|
|
|
4
4
|
const shared = require("@volar/shared");
|
|
5
5
|
exports._ = require("vscode-uri");
|
|
6
6
|
function createUriMap(map = new Map()) {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const uriToUri = new Map();
|
|
8
|
+
const pathToUri = new Map();
|
|
9
9
|
return {
|
|
10
10
|
clear,
|
|
11
11
|
values,
|
|
@@ -19,20 +19,15 @@ function createUriMap(map = new Map()) {
|
|
|
19
19
|
pathSet,
|
|
20
20
|
};
|
|
21
21
|
function getUriByUri(uri) {
|
|
22
|
-
if (!
|
|
23
|
-
|
|
24
|
-
return
|
|
22
|
+
if (!uriToUri.has(uri))
|
|
23
|
+
uriToUri.set(uri, normalizeUri(uri).toLowerCase());
|
|
24
|
+
return uriToUri.get(uri);
|
|
25
25
|
}
|
|
26
|
-
function getUriByPath(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
map = new Map();
|
|
30
|
-
pathToUriKeys.set(rootUri, map);
|
|
26
|
+
function getUriByPath(path) {
|
|
27
|
+
if (!pathToUri.has(path)) {
|
|
28
|
+
pathToUri.set(path, shared.getUriByPath(path).toLowerCase());
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
map.set(path, shared.getUriByPath(path).toLowerCase());
|
|
34
|
-
}
|
|
35
|
-
return map.get(path);
|
|
30
|
+
return pathToUri.get(path);
|
|
36
31
|
}
|
|
37
32
|
function clear() {
|
|
38
33
|
return map.clear();
|
|
@@ -52,17 +47,17 @@ function createUriMap(map = new Map()) {
|
|
|
52
47
|
function uriSet(_uri, item) {
|
|
53
48
|
return map.set(getUriByUri(_uri), item);
|
|
54
49
|
}
|
|
55
|
-
function pathDelete(
|
|
56
|
-
return uriDelete(getUriByPath(
|
|
50
|
+
function pathDelete(path) {
|
|
51
|
+
return uriDelete(getUriByPath(path));
|
|
57
52
|
}
|
|
58
|
-
function pathGet(
|
|
59
|
-
return uriGet(getUriByPath(
|
|
53
|
+
function pathGet(path) {
|
|
54
|
+
return uriGet(getUriByPath(path));
|
|
60
55
|
}
|
|
61
|
-
function pathHas(
|
|
62
|
-
return uriGet(getUriByPath(
|
|
56
|
+
function pathHas(path) {
|
|
57
|
+
return uriGet(getUriByPath(path));
|
|
63
58
|
}
|
|
64
|
-
function pathSet(
|
|
65
|
-
return uriSet(getUriByPath(
|
|
59
|
+
function pathSet(path, item) {
|
|
60
|
+
return uriSet(getUriByPath(path), item);
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
exports.createUriMap = createUriMap;
|
|
@@ -12,6 +12,7 @@ exports.createWebFileSystemHost = void 0;
|
|
|
12
12
|
const path = require("typesafe-path");
|
|
13
13
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
14
14
|
const vscode = require("vscode-languageserver");
|
|
15
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
15
16
|
const protocol_1 = require("../protocol");
|
|
16
17
|
const utilities_1 = require("./ts/utilities");
|
|
17
18
|
const uriMap_1 = require("./uriMap");
|
|
@@ -26,10 +27,10 @@ function createWebFileSystemHost() {
|
|
|
26
27
|
fileTypes: new Map(),
|
|
27
28
|
searched: false,
|
|
28
29
|
};
|
|
29
|
-
const pendings =
|
|
30
|
+
const pendings = [];
|
|
30
31
|
const changes = [];
|
|
31
32
|
const onReadys = [];
|
|
32
|
-
let
|
|
33
|
+
let loading = false;
|
|
33
34
|
let connection;
|
|
34
35
|
return {
|
|
35
36
|
ready(_connection) {
|
|
@@ -50,7 +51,7 @@ function createWebFileSystemHost() {
|
|
|
50
51
|
dir.fileTexts.delete(name);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
fireChanges(params
|
|
54
|
+
fireChanges(params);
|
|
54
55
|
});
|
|
55
56
|
for (const cb of onReadys) {
|
|
56
57
|
cb(connection);
|
|
@@ -105,10 +106,10 @@ function createWebFileSystemHost() {
|
|
|
105
106
|
}
|
|
106
107
|
dir.fileTypes.set(name, undefined);
|
|
107
108
|
if (connection) {
|
|
108
|
-
addPending(statAsync(connection, fsPath, dir));
|
|
109
|
+
addPending('Stat', fsPath, statAsync(connection, fsPath, dir));
|
|
109
110
|
}
|
|
110
111
|
else {
|
|
111
|
-
onReadys.push((connection) => addPending(statAsync(connection, fsPath, dir)));
|
|
112
|
+
onReadys.push((connection) => addPending('Stat', fsPath, statAsync(connection, fsPath, dir)));
|
|
112
113
|
}
|
|
113
114
|
return false;
|
|
114
115
|
}
|
|
@@ -121,10 +122,10 @@ function createWebFileSystemHost() {
|
|
|
121
122
|
}
|
|
122
123
|
dir.fileTexts.set(name, '');
|
|
123
124
|
if (connection) {
|
|
124
|
-
addPending(readFileAsync(connection, fsPath, dir));
|
|
125
|
+
addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir));
|
|
125
126
|
}
|
|
126
127
|
else {
|
|
127
|
-
onReadys.push((connection) => addPending(readFileAsync(connection, fsPath, dir)));
|
|
128
|
+
onReadys.push((connection) => addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir)));
|
|
128
129
|
}
|
|
129
130
|
return '';
|
|
130
131
|
}
|
|
@@ -138,10 +139,10 @@ function createWebFileSystemHost() {
|
|
|
138
139
|
if (!dir.searched) {
|
|
139
140
|
dir.searched = true;
|
|
140
141
|
if (connection) {
|
|
141
|
-
addPending(readDirectoryAsync(connection, dirPath, dir));
|
|
142
|
+
addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir));
|
|
142
143
|
}
|
|
143
144
|
else {
|
|
144
|
-
onReadys.push((connection) => addPending(readDirectoryAsync(connection, dirPath, dir)));
|
|
145
|
+
onReadys.push((connection) => addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir)));
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
return {
|
|
@@ -158,10 +159,10 @@ function createWebFileSystemHost() {
|
|
|
158
159
|
if (!dir.searched) {
|
|
159
160
|
dir.searched = true;
|
|
160
161
|
if (connection) {
|
|
161
|
-
addPending(readDirectoryAsync(connection, fsPath, dir));
|
|
162
|
+
addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir));
|
|
162
163
|
}
|
|
163
164
|
else {
|
|
164
|
-
onReadys.push((connection) => addPending(readDirectoryAsync(connection, fsPath, dir)));
|
|
165
|
+
onReadys.push((connection) => addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir)));
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
return files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]);
|
|
@@ -169,28 +170,69 @@ function createWebFileSystemHost() {
|
|
|
169
170
|
function statAsync(connection, fsPath, dir) {
|
|
170
171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
172
|
const uri = shared.getUriByPath(fsPath);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) { // stat request always response file type for jsdelivr
|
|
174
|
+
const text = yield readJsdelivrFile(connection, uri);
|
|
175
|
+
if (text !== undefined) {
|
|
176
|
+
const name = path.basename(fsPath);
|
|
177
|
+
dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File);
|
|
178
|
+
dir.fileTexts.set(name, text);
|
|
179
|
+
changes.push({
|
|
180
|
+
uri: uri,
|
|
181
|
+
type: vscode.FileChangeType.Created,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri);
|
|
187
|
+
if ((result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.File || (result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.SymbolicLink) {
|
|
188
|
+
const name = path.basename(fsPath);
|
|
189
|
+
dir.fileTypes.set(name, result.type);
|
|
190
|
+
changes.push({
|
|
191
|
+
uri: uri,
|
|
192
|
+
type: vscode.FileChangeType.Created,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
180
195
|
}
|
|
181
196
|
});
|
|
182
197
|
}
|
|
183
198
|
function readFileAsync(connection, fsPath, dir) {
|
|
184
199
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
200
|
const uri = shared.getUriByPath(fsPath);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
201
|
+
if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) {
|
|
202
|
+
const text = yield readJsdelivrFile(connection, uri);
|
|
203
|
+
if (text !== undefined) {
|
|
204
|
+
const name = path.basename(fsPath);
|
|
205
|
+
dir.fileTexts.set(name, text);
|
|
206
|
+
changes.push({
|
|
207
|
+
uri: uri,
|
|
208
|
+
type: vscode.FileChangeType.Changed,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri);
|
|
214
|
+
if (text) {
|
|
215
|
+
const name = path.basename(fsPath);
|
|
216
|
+
dir.fileTexts.set(name, text);
|
|
217
|
+
changes.push({
|
|
218
|
+
uri: uri,
|
|
219
|
+
type: vscode.FileChangeType.Changed,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function readJsdelivrFile(connection, uri) {
|
|
226
|
+
var _a;
|
|
227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
// ignore .js because it's no help for intellisense
|
|
229
|
+
if (uri.endsWith('.d.ts') || uri.endsWith('.json')) {
|
|
230
|
+
const text = (_a = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri)) !== null && _a !== void 0 ? _a : undefined;
|
|
231
|
+
if (text !== undefined
|
|
232
|
+
// ignore https://cdn.jsdelivr.net/npm/@vue/runtime-dom
|
|
233
|
+
&& text.indexOf('Minified by jsDelivr') === -1) {
|
|
234
|
+
return text;
|
|
235
|
+
}
|
|
194
236
|
}
|
|
195
237
|
});
|
|
196
238
|
}
|
|
@@ -210,29 +252,34 @@ function createWebFileSystemHost() {
|
|
|
210
252
|
});
|
|
211
253
|
}
|
|
212
254
|
}
|
|
213
|
-
function addPending(p) {
|
|
255
|
+
function addPending(action, fileName, p) {
|
|
214
256
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
pendings.
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
257
|
+
pendings.push([action, fileName, p]);
|
|
258
|
+
if (loading === false) {
|
|
259
|
+
loading = true;
|
|
260
|
+
const progress = yield (connection === null || connection === void 0 ? void 0 : connection.window.createWorkDoneProgress());
|
|
261
|
+
progress === null || progress === void 0 ? void 0 : progress.begin(action);
|
|
262
|
+
let i = 0;
|
|
263
|
+
while (pendings.length) {
|
|
264
|
+
const current = pendings.shift();
|
|
265
|
+
progress === null || progress === void 0 ? void 0 : progress.report(i / pendings.length, vscode_uri_1.URI.parse(shared.getUriByPath(current[1])).fsPath);
|
|
266
|
+
yield current;
|
|
267
|
+
i++;
|
|
222
268
|
}
|
|
269
|
+
progress === null || progress === void 0 ? void 0 : progress.done();
|
|
223
270
|
if (changes.length) {
|
|
224
|
-
fireChanges({ changes: [...changes] }
|
|
271
|
+
fireChanges({ changes: [...changes] });
|
|
225
272
|
changes.length = 0;
|
|
226
273
|
}
|
|
227
|
-
|
|
274
|
+
loading = false;
|
|
228
275
|
}
|
|
229
276
|
});
|
|
230
277
|
}
|
|
231
|
-
function fireChanges(params
|
|
278
|
+
function fireChanges(params) {
|
|
232
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
233
280
|
for (const cb of [...onDidChangeWatchedFilesCb]) {
|
|
234
281
|
if (onDidChangeWatchedFilesCb.has(cb)) {
|
|
235
|
-
yield cb(params
|
|
282
|
+
yield cb(params);
|
|
236
283
|
}
|
|
237
284
|
}
|
|
238
285
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as shared from '@volar/shared';
|
|
2
1
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
2
|
import * as path from 'typesafe-path';
|
|
4
3
|
import * as vscode from 'vscode-languageserver';
|
|
@@ -17,16 +16,16 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
|
|
|
17
16
|
uriGet: (_uri: string) => Project | undefined;
|
|
18
17
|
uriHas: (_uri: string) => boolean;
|
|
19
18
|
uriSet: (_uri: string, item: Project) => void;
|
|
20
|
-
pathDelete: (
|
|
21
|
-
pathGet: (
|
|
22
|
-
pathHas: (
|
|
23
|
-
pathSet: (
|
|
19
|
+
pathDelete: (path: string) => boolean;
|
|
20
|
+
pathGet: (path: string) => Project | undefined;
|
|
21
|
+
pathHas: (path: string) => Project | undefined;
|
|
22
|
+
pathSet: (path: string, item: Project) => void;
|
|
24
23
|
};
|
|
25
24
|
documentRegistry: ts.DocumentRegistry;
|
|
26
25
|
getProjectAndTsConfig: (uri: string) => Promise<{
|
|
27
26
|
tsconfig: string;
|
|
28
27
|
project: {
|
|
29
|
-
tsConfig:
|
|
28
|
+
tsConfig: ts.CompilerOptions | path.PosixPath;
|
|
30
29
|
scripts: {
|
|
31
30
|
clear: () => void;
|
|
32
31
|
values: () => IterableIterator<{
|
|
@@ -49,20 +48,20 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
|
|
|
49
48
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
50
49
|
snapshotVersion: number | undefined;
|
|
51
50
|
}) => void;
|
|
52
|
-
pathDelete: (
|
|
53
|
-
pathGet: (
|
|
51
|
+
pathDelete: (path: string) => boolean;
|
|
52
|
+
pathGet: (path: string) => {
|
|
54
53
|
version: number;
|
|
55
54
|
fileName: string;
|
|
56
55
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
57
56
|
snapshotVersion: number | undefined;
|
|
58
57
|
} | undefined;
|
|
59
|
-
pathHas: (
|
|
58
|
+
pathHas: (path: string) => {
|
|
60
59
|
version: number;
|
|
61
60
|
fileName: string;
|
|
62
61
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
63
62
|
snapshotVersion: number | undefined;
|
|
64
63
|
} | undefined;
|
|
65
|
-
pathSet: (
|
|
64
|
+
pathSet: (path: string, item: {
|
|
66
65
|
version: number;
|
|
67
66
|
fileName: string;
|
|
68
67
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
@@ -160,4 +159,4 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
|
|
|
160
159
|
reload: () => void;
|
|
161
160
|
dispose(): void;
|
|
162
161
|
}>;
|
|
163
|
-
export declare function sortTsConfigs(
|
|
162
|
+
export declare function sortTsConfigs(file: path.PosixPath, a: path.PosixPath, b: path.PosixPath): number;
|
|
@@ -21,21 +21,21 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
let inferredProject;
|
|
23
23
|
const sys = fsHost.getWorkspaceFileSystem(rootUri);
|
|
24
|
-
const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.
|
|
24
|
+
const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.getPathOfUri(rootUri.toString()));
|
|
25
25
|
const projects = (0, uriMap_1.createUriMap)();
|
|
26
|
-
const rootTsConfigs = new Set(sys.readDirectory(rootUri.
|
|
27
|
-
const disposeWatch = fsHost.onDidChangeWatchedFiles((params
|
|
26
|
+
const rootTsConfigs = new Set(sys.readDirectory(shared.getPathOfUri(rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
|
|
27
|
+
const disposeWatch = fsHost.onDidChangeWatchedFiles((params) => __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const disposes = [];
|
|
29
29
|
for (const change of params.changes) {
|
|
30
30
|
if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
|
|
31
31
|
if (change.type === vscode.FileChangeType.Created) {
|
|
32
|
-
if (shared.isFileInDir(
|
|
33
|
-
rootTsConfigs.add(
|
|
32
|
+
if (shared.isFileInDir(shared.getPathOfUri(change.uri), shared.getPathOfUri(rootUri.toString()))) {
|
|
33
|
+
rootTsConfigs.add(shared.getPathOfUri(change.uri));
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && projects.uriHas(change.uri)) {
|
|
37
37
|
if (change.type === vscode.FileChangeType.Deleted) {
|
|
38
|
-
rootTsConfigs.delete(
|
|
38
|
+
rootTsConfigs.delete(shared.getPathOfUri(change.uri));
|
|
39
39
|
}
|
|
40
40
|
const _project = projects.uriGet(change.uri);
|
|
41
41
|
projects.uriDelete(change.uri);
|
|
@@ -46,9 +46,6 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
if (reason === 'web-cache-updated' && params.changes.some(change => change.uri.indexOf('/node_modules/') >= 0)) {
|
|
50
|
-
clearProjects();
|
|
51
|
-
}
|
|
52
49
|
return Promise.all(disposes);
|
|
53
50
|
}));
|
|
54
51
|
return {
|
|
@@ -105,11 +102,11 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
105
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
103
|
let matches = [];
|
|
107
104
|
for (const rootTsConfig of rootTsConfigs) {
|
|
108
|
-
if (shared.isFileInDir(uri.
|
|
105
|
+
if (shared.isFileInDir(shared.getPathOfUri(uri.toString()), path.dirname(rootTsConfig))) {
|
|
109
106
|
matches.push(rootTsConfig);
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
|
-
matches = matches.sort((a, b) => sortTsConfigs(uri.
|
|
109
|
+
matches = matches.sort((a, b) => sortTsConfigs(shared.getPathOfUri(uri.toString()), a, b));
|
|
113
110
|
if (matches.length) {
|
|
114
111
|
yield getParsedCommandLine(matches[0]);
|
|
115
112
|
}
|
|
@@ -117,16 +114,18 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
117
114
|
}
|
|
118
115
|
function findDirectIncludeTsconfig() {
|
|
119
116
|
return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const map = (0, uriMap_1.createUriMap)();
|
|
120
118
|
const parsedCommandLine = yield getParsedCommandLine(tsconfig);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
for (const fileName of parsedCommandLine.fileNames) {
|
|
120
|
+
map.pathSet(fileName, true);
|
|
121
|
+
}
|
|
122
|
+
return map.uriHas(uri.toString());
|
|
124
123
|
}));
|
|
125
124
|
}
|
|
126
125
|
function findIndirectReferenceTsconfig() {
|
|
127
126
|
return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
|
|
128
127
|
var _a;
|
|
129
|
-
const project = yield projects.pathGet(
|
|
128
|
+
const project = yield projects.pathGet(tsconfig);
|
|
130
129
|
const ls = project === null || project === void 0 ? void 0 : project.getLanguageServiceDontCreate();
|
|
131
130
|
const validDoc = (_a = ls === null || ls === void 0 ? void 0 : ls.context.typescriptLanguageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(shared.getPathOfUri(uri.toString()));
|
|
132
131
|
return !!validDoc;
|
|
@@ -135,8 +134,8 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
135
134
|
function findTsconfig(match) {
|
|
136
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
136
|
const checked = new Set();
|
|
138
|
-
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(uri.
|
|
139
|
-
const project = yield projects.pathGet(
|
|
137
|
+
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(shared.getPathOfUri(uri.toString()), a, b))) {
|
|
138
|
+
const project = yield projects.pathGet(rootTsConfig);
|
|
140
139
|
if (project) {
|
|
141
140
|
let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
|
|
142
141
|
if (serverOptions.reverseConfigFilePriority) {
|
|
@@ -203,26 +202,26 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
203
202
|
}
|
|
204
203
|
function getProjectByCreate(_tsConfig) {
|
|
205
204
|
const tsConfig = shared.normalizeFileName(_tsConfig);
|
|
206
|
-
let project = projects.pathGet(
|
|
205
|
+
let project = projects.pathGet(tsConfig);
|
|
207
206
|
if (!project) {
|
|
208
207
|
project = (0, project_1.createProject)(runtimeEnv, plugins, fsHost, ts, vscode_uri_1.URI.parse(shared.getUriByPath(path.dirname(tsConfig))), tsConfig, tsLocalized, documents, configHost, documentRegistry, cancelTokenHost, serverOptions);
|
|
209
|
-
projects.pathSet(
|
|
208
|
+
projects.pathSet(tsConfig, project);
|
|
210
209
|
}
|
|
211
210
|
return project;
|
|
212
211
|
}
|
|
213
212
|
});
|
|
214
213
|
}
|
|
215
214
|
exports.createWorkspaceProjects = createWorkspaceProjects;
|
|
216
|
-
function sortTsConfigs(
|
|
217
|
-
const inA = shared.isFileInDir(
|
|
218
|
-
const inB = shared.isFileInDir(
|
|
215
|
+
function sortTsConfigs(file, a, b) {
|
|
216
|
+
const inA = shared.isFileInDir(file, path.dirname(a));
|
|
217
|
+
const inB = shared.isFileInDir(file, path.dirname(b));
|
|
219
218
|
if (inA !== inB) {
|
|
220
219
|
const aWeight = inA ? 1 : 0;
|
|
221
220
|
const bWeight = inB ? 1 : 0;
|
|
222
221
|
return bWeight - aWeight;
|
|
223
222
|
}
|
|
224
|
-
const aLength =
|
|
225
|
-
const bLength =
|
|
223
|
+
const aLength = a.split('/').length;
|
|
224
|
+
const bLength = b.split('/').length;
|
|
226
225
|
if (aLength === bLength) {
|
|
227
226
|
const aWeight = path.basename(a) === 'tsconfig.json' ? 1 : 0;
|
|
228
227
|
const bWeight = path.basename(b) === 'tsconfig.json' ? 1 : 0;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="typesafe-path" />
|
|
2
2
|
import { ConfigurationHost } from '@volar/language-service';
|
|
3
3
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
4
|
import * as vscode from 'vscode-languageserver';
|
|
5
5
|
import { URI } from 'vscode-uri';
|
|
6
6
|
import { FileSystemHost, LanguageServerPlugin, RuntimeEnvironment, LanguageServerInitializationOptions } from '../types';
|
|
7
7
|
import { createSnapshots } from './snapshots';
|
|
8
|
-
import * as path from 'typesafe-path';
|
|
9
8
|
import { CancellationTokenHost } from './cancellationPipe';
|
|
10
9
|
export interface Workspaces extends ReturnType<typeof createWorkspaces> {
|
|
11
10
|
}
|
|
@@ -18,16 +17,16 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
|
|
|
18
17
|
uriGet: (_uri: string) => import("./project").Project | undefined;
|
|
19
18
|
uriHas: (_uri: string) => boolean;
|
|
20
19
|
uriSet: (_uri: string, item: import("./project").Project) => void;
|
|
21
|
-
pathDelete: (
|
|
22
|
-
pathGet: (
|
|
23
|
-
pathHas: (
|
|
24
|
-
pathSet: (
|
|
20
|
+
pathDelete: (path: string) => boolean;
|
|
21
|
+
pathGet: (path: string) => import("./project").Project | undefined;
|
|
22
|
+
pathHas: (path: string) => import("./project").Project | undefined;
|
|
23
|
+
pathSet: (path: string, item: import("./project").Project) => void;
|
|
25
24
|
};
|
|
26
25
|
documentRegistry: ts.DocumentRegistry;
|
|
27
26
|
getProjectAndTsConfig: (uri: string) => Promise<{
|
|
28
27
|
tsconfig: string;
|
|
29
28
|
project: {
|
|
30
|
-
tsConfig:
|
|
29
|
+
tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
|
|
31
30
|
scripts: {
|
|
32
31
|
clear: () => void;
|
|
33
32
|
values: () => IterableIterator<{
|
|
@@ -50,20 +49,20 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
|
|
|
50
49
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
51
50
|
snapshotVersion: number | undefined;
|
|
52
51
|
}) => void;
|
|
53
|
-
pathDelete: (
|
|
54
|
-
pathGet: (
|
|
52
|
+
pathDelete: (path: string) => boolean;
|
|
53
|
+
pathGet: (path: string) => {
|
|
55
54
|
version: number;
|
|
56
55
|
fileName: string;
|
|
57
56
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
58
57
|
snapshotVersion: number | undefined;
|
|
59
58
|
} | undefined;
|
|
60
|
-
pathHas: (
|
|
59
|
+
pathHas: (path: string) => {
|
|
61
60
|
version: number;
|
|
62
61
|
fileName: string;
|
|
63
62
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
64
63
|
snapshotVersion: number | undefined;
|
|
65
64
|
} | undefined;
|
|
66
|
-
pathSet: (
|
|
65
|
+
pathSet: (path: string, item: {
|
|
67
66
|
version: number;
|
|
68
67
|
fileName: string;
|
|
69
68
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
@@ -164,7 +163,7 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
|
|
|
164
163
|
getProject: (uri: string) => Promise<{
|
|
165
164
|
tsconfig: string;
|
|
166
165
|
project: {
|
|
167
|
-
tsConfig:
|
|
166
|
+
tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
|
|
168
167
|
scripts: {
|
|
169
168
|
clear: () => void;
|
|
170
169
|
values: () => IterableIterator<{
|
|
@@ -187,20 +186,20 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
|
|
|
187
186
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
188
187
|
snapshotVersion: number | undefined;
|
|
189
188
|
}) => void;
|
|
190
|
-
pathDelete: (
|
|
191
|
-
pathGet: (
|
|
189
|
+
pathDelete: (path: string) => boolean;
|
|
190
|
+
pathGet: (path: string) => {
|
|
192
191
|
version: number;
|
|
193
192
|
fileName: string;
|
|
194
193
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
195
194
|
snapshotVersion: number | undefined;
|
|
196
195
|
} | undefined;
|
|
197
|
-
pathHas: (
|
|
196
|
+
pathHas: (path: string) => {
|
|
198
197
|
version: number;
|
|
199
198
|
fileName: string;
|
|
200
199
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
201
200
|
snapshotVersion: number | undefined;
|
|
202
201
|
} | undefined;
|
|
203
|
-
pathSet: (
|
|
202
|
+
pathSet: (path: string, item: {
|
|
204
203
|
version: number;
|
|
205
204
|
fileName: string;
|
|
206
205
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
@@ -295,7 +294,7 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
|
|
|
295
294
|
} | {
|
|
296
295
|
tsconfig: undefined;
|
|
297
296
|
project: {
|
|
298
|
-
tsConfig:
|
|
297
|
+
tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
|
|
299
298
|
scripts: {
|
|
300
299
|
clear: () => void;
|
|
301
300
|
values: () => IterableIterator<{
|
|
@@ -318,20 +317,20 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
|
|
|
318
317
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
319
318
|
snapshotVersion: number | undefined;
|
|
320
319
|
}) => void;
|
|
321
|
-
pathDelete: (
|
|
322
|
-
pathGet: (
|
|
320
|
+
pathDelete: (path: string) => boolean;
|
|
321
|
+
pathGet: (path: string) => {
|
|
323
322
|
version: number;
|
|
324
323
|
fileName: string;
|
|
325
324
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
326
325
|
snapshotVersion: number | undefined;
|
|
327
326
|
} | undefined;
|
|
328
|
-
pathHas: (
|
|
327
|
+
pathHas: (path: string) => {
|
|
329
328
|
version: number;
|
|
330
329
|
fileName: string;
|
|
331
330
|
snapshot: ts.IScriptSnapshot | undefined;
|
|
332
331
|
snapshotVersion: number | undefined;
|
|
333
332
|
} | undefined;
|
|
334
|
-
pathSet: (
|
|
333
|
+
pathSet: (path: string, item: {
|
|
335
334
|
version: number;
|
|
336
335
|
fileName: string;
|
|
337
336
|
snapshot: ts.IScriptSnapshot | undefined;
|
package/out/utils/workspaces.js
CHANGED
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.createWorkspaces = void 0;
|
|
12
12
|
const shared = require("@volar/shared");
|
|
13
13
|
const vscode = require("vscode-languageserver");
|
|
14
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
15
14
|
const types_1 = require("../types");
|
|
16
15
|
const workspaceProjects_1 = require("./workspaceProjects");
|
|
17
16
|
function createWorkspaces(runtimeEnv, plugins, fsHost, configurationHost, ts, tsLocalized, client, options, documents, connection, cancelTokenHost) {
|
|
@@ -141,9 +140,8 @@ function createWorkspaces(runtimeEnv, plugins, fsHost, configurationHost, ts, ts
|
|
|
141
140
|
var _a;
|
|
142
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
142
|
const rootUris = [...workspaces.keys()]
|
|
144
|
-
.filter(rootUri =>
|
|
145
|
-
.
|
|
146
|
-
.sort((a, b) => (0, workspaceProjects_1.sortTsConfigs)(vscode_uri_1.URI.parse(uri).fsPath, vscode_uri_1.URI.parse(a).fsPath, vscode_uri_1.URI.parse(b).fsPath));
|
|
143
|
+
.filter(rootUri => shared.isFileInDir(shared.getPathOfUri(uri), shared.getPathOfUri(rootUri)))
|
|
144
|
+
.sort((a, b) => (0, workspaceProjects_1.sortTsConfigs)(shared.getPathOfUri(uri), shared.getPathOfUri(a), shared.getPathOfUri(b)));
|
|
147
145
|
for (const rootUri of rootUris) {
|
|
148
146
|
const workspace = yield workspaces.get(rootUri);
|
|
149
147
|
const project = yield (workspace === null || workspace === void 0 ? void 0 : workspace.getProjectAndTsConfig(uri));
|