@volar/language-server 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.
- package/out/common/documents.d.ts +1 -0
- package/out/common/features/customFeatures.js +22 -24
- package/out/common/features/languageFeatures.d.ts +1 -1
- package/out/common/features/languageFeatures.js +11 -12
- package/out/common/project.d.ts +4 -2
- package/out/common/project.js +3 -3
- package/out/common/server.d.ts +1 -1
- package/out/common/server.js +10 -17
- package/out/common/utils/uriMap.d.ts +2 -0
- package/out/common/utils/uriMap.js +4 -0
- package/out/common/workspaces.d.ts +1289 -894
- package/out/common/workspaces.js +232 -39
- package/package.json +6 -6
|
@@ -30,6 +30,7 @@ export declare function createDocuments(env: RuntimeEnvironment, connection: vsc
|
|
|
30
30
|
data: {
|
|
31
31
|
clear: () => void;
|
|
32
32
|
values: () => IterableIterator<IncrementalScriptSnapshot>;
|
|
33
|
+
keys: () => IterableIterator<string>;
|
|
33
34
|
uriDelete: (_uri: string) => boolean;
|
|
34
35
|
uriGet: (_uri: string) => IncrementalScriptSnapshot | undefined;
|
|
35
36
|
uriHas: (_uri: string) => boolean;
|
|
@@ -54,7 +54,7 @@ function register(connection, workspaces, env) {
|
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
connection.onNotification(protocol_1.ReloadProjectNotification.type, () => {
|
|
57
|
-
workspaces.
|
|
57
|
+
workspaces.reloadProjects();
|
|
58
58
|
});
|
|
59
59
|
connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, async (params) => {
|
|
60
60
|
const fs = await Promise.resolve().then(() => require('fs'));
|
|
@@ -87,31 +87,29 @@ function register(connection, workspaces, env) {
|
|
|
87
87
|
});
|
|
88
88
|
connection.onRequest(protocol_1.LoadedTSFilesMetaRequest.type, async () => {
|
|
89
89
|
const sourceFilesData = new Map();
|
|
90
|
-
for (const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
sourceFilesData.get(sourceFile).projectNames.push(projectName);
|
|
90
|
+
for (const _project of [...workspaces.configProjects.values(), ...workspaces.inferredProjects.values()]) {
|
|
91
|
+
const project = await _project;
|
|
92
|
+
const service = project.getLanguageServiceDontCreate();
|
|
93
|
+
const languageService = service?.context.inject('typescript/languageService');
|
|
94
|
+
const program = languageService?.getProgram();
|
|
95
|
+
if (program) {
|
|
96
|
+
const projectName = typeof project.tsConfig === 'string' ? project.tsConfig : (project.languageHost.workspacePath + '(inferred)');
|
|
97
|
+
const sourceFiles = program?.getSourceFiles() ?? [];
|
|
98
|
+
for (const sourceFile of sourceFiles) {
|
|
99
|
+
if (!sourceFilesData.has(sourceFile)) {
|
|
100
|
+
let nodes = 0;
|
|
101
|
+
sourceFile.forEachChild(function walk(node) {
|
|
102
|
+
nodes++;
|
|
103
|
+
node.forEachChild(walk);
|
|
104
|
+
});
|
|
105
|
+
sourceFilesData.set(sourceFile, {
|
|
106
|
+
projectNames: [],
|
|
107
|
+
size: nodes * 128,
|
|
108
|
+
});
|
|
112
109
|
}
|
|
113
|
-
;
|
|
110
|
+
sourceFilesData.get(sourceFile).projectNames.push(projectName);
|
|
114
111
|
}
|
|
112
|
+
;
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
115
|
const result = {
|
|
@@ -3,5 +3,5 @@ import { CancellationTokenHost } from '../cancellationPipe';
|
|
|
3
3
|
import type { Workspaces } from '../workspaces';
|
|
4
4
|
import { RuntimeEnvironment, InitializationOptions } from '../../types';
|
|
5
5
|
import { createDocuments } from '../documents';
|
|
6
|
-
export declare function register(connection: vscode.Connection,
|
|
6
|
+
export declare function register(connection: vscode.Connection, workspaces: Workspaces, initParams: vscode.InitializeParams, initOptions: InitializationOptions, cancelHost: CancellationTokenHost, semanticTokensLegend: vscode.SemanticTokensLegend, runtime: RuntimeEnvironment, documents: ReturnType<typeof createDocuments>): void;
|
|
7
7
|
export declare function sleep(ms: number): Promise<unknown>;
|
|
@@ -5,7 +5,7 @@ const embedded = require("@volar/language-service");
|
|
|
5
5
|
const vscode = require("vscode-languageserver");
|
|
6
6
|
const protocol_1 = require("../../protocol");
|
|
7
7
|
const types_1 = require("../../types");
|
|
8
|
-
function register(connection,
|
|
8
|
+
function register(connection, workspaces, initParams, initOptions, cancelHost, semanticTokensLegend, runtime, documents) {
|
|
9
9
|
let lastCompleteUri;
|
|
10
10
|
let lastCompleteLs;
|
|
11
11
|
let lastCodeLensLs;
|
|
@@ -195,16 +195,15 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
195
195
|
});
|
|
196
196
|
connection.onWorkspaceSymbol(async (params, token) => {
|
|
197
197
|
let results = [];
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
198
|
+
let projects = [...workspaces.configProjects.values()];
|
|
199
|
+
if (!projects.length) {
|
|
200
|
+
projects = [...workspaces.inferredProjects.values()];
|
|
201
|
+
}
|
|
202
|
+
for (const project of projects) {
|
|
203
|
+
if (token.isCancellationRequested)
|
|
204
|
+
return;
|
|
205
|
+
const service = (await project).getLanguageService();
|
|
206
|
+
results = results.concat(await service.findWorkspaceSymbols(params.query, token));
|
|
208
207
|
}
|
|
209
208
|
return results;
|
|
210
209
|
});
|
|
@@ -312,7 +311,7 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
312
311
|
});
|
|
313
312
|
}
|
|
314
313
|
async function getProject(uri) {
|
|
315
|
-
return (await
|
|
314
|
+
return (await workspaces.getProject(uri))?.project;
|
|
316
315
|
}
|
|
317
316
|
function fixTextEdit(item) {
|
|
318
317
|
const insertReplaceSupport = initParams.capabilities.textDocument?.completion?.completionItem?.insertReplaceSupport ?? false;
|
package/out/common/project.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import * as path from 'typesafe-path/posix';
|
|
|
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
|
-
import {
|
|
7
|
-
export interface ProjectContext extends
|
|
6
|
+
import { WorkspacesContext } from './workspaces';
|
|
7
|
+
export interface ProjectContext extends WorkspacesContext {
|
|
8
8
|
project: {
|
|
9
|
+
workspaceUri: URI;
|
|
9
10
|
rootUri: URI;
|
|
10
11
|
tsConfig: path.PosixPath | ts.CompilerOptions;
|
|
11
12
|
};
|
|
@@ -126,6 +127,7 @@ export declare function createProject(context: ProjectContext): Promise<{
|
|
|
126
127
|
askedFiles: {
|
|
127
128
|
clear: () => void;
|
|
128
129
|
values: () => IterableIterator<boolean>;
|
|
130
|
+
keys: () => IterableIterator<string>;
|
|
129
131
|
uriDelete: (_uri: string) => boolean;
|
|
130
132
|
uriGet: (_uri: string) => boolean | undefined;
|
|
131
133
|
uriHas: (_uri: string) => boolean;
|
package/out/common/project.js
CHANGED
|
@@ -25,7 +25,7 @@ async function createProject(context) {
|
|
|
25
25
|
fs,
|
|
26
26
|
console: context.server.runtimeEnv.console,
|
|
27
27
|
locale: context.workspaces.initParams.locale,
|
|
28
|
-
workspaceUri: context.
|
|
28
|
+
workspaceUri: context.project.workspaceUri,
|
|
29
29
|
rootUri: context.project.rootUri,
|
|
30
30
|
clientCapabilities: context.workspaces.initParams.capabilities,
|
|
31
31
|
getConfiguration: context.server.configurationHost?.getConfiguration,
|
|
@@ -37,7 +37,7 @@ async function createProject(context) {
|
|
|
37
37
|
}
|
|
38
38
|
const askedFiles = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
39
39
|
const languageHost = {
|
|
40
|
-
workspacePath: uriToFileName(context.
|
|
40
|
+
workspacePath: uriToFileName(context.project.workspaceUri.toString()),
|
|
41
41
|
rootPath: uriToFileName(context.project.rootUri.toString()),
|
|
42
42
|
getProjectVersion: () => projectVersion.toString(),
|
|
43
43
|
getScriptFileNames: () => parsedCommandLine.fileNames,
|
|
@@ -72,7 +72,7 @@ async function createProject(context) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
let parsedCommandLine = await createParsedCommandLine(context.workspaces.ts, env, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins, existingOptions);
|
|
75
|
-
let config = (context.
|
|
75
|
+
let config = (context.project.workspaceUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.server.runtimeEnv.console, context.server.runtimeEnv.uriToFileName(context.project.workspaceUri.toString()), context.workspaces.initOptions.configFilePath) : {}) ?? {};
|
|
76
76
|
for (const plugin of context.workspaces.plugins) {
|
|
77
77
|
if (plugin.resolveConfig) {
|
|
78
78
|
config = await plugin.resolveConfig(config, {
|
package/out/common/server.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export interface ServerContext {
|
|
|
11
11
|
configurationHost: ReturnType<typeof createConfigurationHost> | undefined;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
export declare function startCommonLanguageServer(connection: vscode.Connection, _plugins: LanguageServerPlugin[], getRuntimeEnv: (params: vscode.InitializeParams, options: InitializationOptions) => RuntimeEnvironment):
|
|
14
|
+
export declare function startCommonLanguageServer(connection: vscode.Connection, _plugins: LanguageServerPlugin[], getRuntimeEnv: (params: vscode.InitializeParams, options: InitializationOptions) => RuntimeEnvironment): void;
|
package/out/common/server.js
CHANGED
|
@@ -13,11 +13,11 @@ const registerFeatures_1 = require("./utils/registerFeatures");
|
|
|
13
13
|
const serverConfig_1 = require("./utils/serverConfig");
|
|
14
14
|
const workspaces_1 = require("./workspaces");
|
|
15
15
|
const request_light_1 = require("request-light");
|
|
16
|
-
|
|
16
|
+
function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
|
|
17
17
|
let initParams;
|
|
18
18
|
let options;
|
|
19
19
|
let roots = [];
|
|
20
|
-
let
|
|
20
|
+
let workspaces;
|
|
21
21
|
let plugins;
|
|
22
22
|
let documents;
|
|
23
23
|
let context;
|
|
@@ -109,10 +109,10 @@ async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
|
|
|
109
109
|
if (initParams.capabilities.workspace?.workspaceFolders) {
|
|
110
110
|
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
111
111
|
for (const folder of e.added) {
|
|
112
|
-
|
|
112
|
+
workspaces?.add(vscode_uri_1.URI.parse(folder.uri));
|
|
113
113
|
}
|
|
114
114
|
for (const folder of e.removed) {
|
|
115
|
-
|
|
115
|
+
workspaces?.remove(vscode_uri_1.URI.parse(folder.uri));
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
}
|
|
@@ -140,11 +140,7 @@ async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
|
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
142
|
connection.onShutdown(async () => {
|
|
143
|
-
|
|
144
|
-
for (const workspace of projects.workspaces) {
|
|
145
|
-
(await workspace[1]).dispose();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
143
|
+
workspaces?.reloadProjects();
|
|
148
144
|
});
|
|
149
145
|
connection.listen();
|
|
150
146
|
function createFsWithCache(fs) {
|
|
@@ -196,7 +192,7 @@ async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
|
|
|
196
192
|
const ts = options.typescript ? context.server.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
|
|
197
193
|
const tsLocalized = options.typescript && initParams.locale ? await context.server.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
|
|
198
194
|
const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
|
|
199
|
-
|
|
195
|
+
workspaces = (0, workspaces_1.createWorkspaces)({
|
|
200
196
|
...context,
|
|
201
197
|
workspaces: {
|
|
202
198
|
ts,
|
|
@@ -207,17 +203,14 @@ async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
|
|
|
207
203
|
cancelTokenHost,
|
|
208
204
|
plugins,
|
|
209
205
|
},
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
(await Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.server.runtimeEnv);
|
|
215
|
-
(await Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.server.runtimeEnv, documents);
|
|
206
|
+
}, roots);
|
|
207
|
+
(await Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, workspaces, context.server.runtimeEnv);
|
|
208
|
+
(await Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, workspaces, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.server.runtimeEnv, documents);
|
|
216
209
|
for (const plugin of plugins) {
|
|
217
210
|
plugin.onInitialized?.(getLanguageService, context.server.runtimeEnv);
|
|
218
211
|
}
|
|
219
212
|
async function getLanguageService(uri) {
|
|
220
|
-
const project = (await
|
|
213
|
+
const project = (await workspaces.getProject(uri))?.project;
|
|
221
214
|
return project?.getLanguageService();
|
|
222
215
|
}
|
|
223
216
|
}
|
|
@@ -6,10 +6,12 @@ interface Options<T> {
|
|
|
6
6
|
set(key: string, value: T): void;
|
|
7
7
|
clear(): void;
|
|
8
8
|
values(): IterableIterator<T>;
|
|
9
|
+
keys(): IterableIterator<string>;
|
|
9
10
|
}
|
|
10
11
|
export declare function createUriMap<T>(fileNameToUri: (fileName: string) => string, map?: Options<T>): {
|
|
11
12
|
clear: () => void;
|
|
12
13
|
values: () => IterableIterator<T>;
|
|
14
|
+
keys: () => IterableIterator<string>;
|
|
13
15
|
uriDelete: (_uri: string) => boolean;
|
|
14
16
|
uriGet: (_uri: string) => T | undefined;
|
|
15
17
|
uriHas: (_uri: string) => boolean;
|
|
@@ -9,6 +9,7 @@ function createUriMap(fileNameToUri, map = new Map()) {
|
|
|
9
9
|
return {
|
|
10
10
|
clear,
|
|
11
11
|
values,
|
|
12
|
+
keys,
|
|
12
13
|
uriDelete,
|
|
13
14
|
uriGet,
|
|
14
15
|
uriHas,
|
|
@@ -35,6 +36,9 @@ function createUriMap(fileNameToUri, map = new Map()) {
|
|
|
35
36
|
function values() {
|
|
36
37
|
return map.values();
|
|
37
38
|
}
|
|
39
|
+
function keys() {
|
|
40
|
+
return map.keys();
|
|
41
|
+
}
|
|
38
42
|
function uriDelete(_uri) {
|
|
39
43
|
return map.delete(getUriByUri(_uri));
|
|
40
44
|
}
|