@volar/language-server 1.10.0 → 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.
@@ -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.reloadProject();
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 workspace of workspaces.workspaces.values()) {
91
- for (const _project of (await workspace).projects.values()) {
92
- const project = await _project;
93
- const service = project.getLanguageServiceDontCreate();
94
- const languageService = service?.context.inject('typescript/languageService');
95
- const program = languageService?.getProgram();
96
- if (program) {
97
- const projectName = typeof project.tsConfig === 'string' ? project.tsConfig : (project.languageHost.workspacePath + '(inferred)');
98
- const sourceFiles = program?.getSourceFiles() ?? [];
99
- for (const sourceFile of sourceFiles) {
100
- if (!sourceFilesData.has(sourceFile)) {
101
- let nodes = 0;
102
- sourceFile.forEachChild(function walk(node) {
103
- nodes++;
104
- node.forEachChild(walk);
105
- });
106
- sourceFilesData.set(sourceFile, {
107
- projectNames: [],
108
- size: nodes * 128,
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, projects: Workspaces, initParams: vscode.InitializeParams, initOptions: InitializationOptions, cancelHost: CancellationTokenHost, semanticTokensLegend: vscode.SemanticTokensLegend, runtime: RuntimeEnvironment, documents: ReturnType<typeof createDocuments>): void;
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, projects, initParams, initOptions, cancelHost, semanticTokensLegend, runtime, documents) {
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
- for (const _workspace of projects.workspaces.values()) {
199
- const workspace = await _workspace;
200
- let projects = [...workspace.projects.values()];
201
- projects = projects.length ? projects : [workspace.getInferredProject()];
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));
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 projects.getProject(uri))?.project;
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;
@@ -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 { WorkspaceContext } from './workspace';
7
- export interface ProjectContext extends WorkspaceContext {
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
  };
@@ -13,7 +14,7 @@ export interface ProjectContext extends WorkspaceContext {
13
14
  export type Project = ReturnType<typeof createProject>;
14
15
  export declare function createProject(context: ProjectContext): Promise<{
15
16
  context: ProjectContext;
16
- tsConfig: ts.CompilerOptions | path.PosixPath;
17
+ tsConfig: path.PosixPath | ts.CompilerOptions;
17
18
  languageHost: TypeScriptLanguageHost;
18
19
  getLanguageService: () => {
19
20
  getTriggerCharacters: () => string[];
@@ -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;
@@ -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.workspace.rootUri,
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.workspace.rootUri.toString()),
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.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.server.runtimeEnv.console, context.server.runtimeEnv.uriToFileName(context.workspace.rootUri.toString()), context.workspaces.initOptions.configFilePath) : {}) ?? {};
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, {
@@ -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): Promise<void>;
14
+ export declare function startCommonLanguageServer(connection: vscode.Connection, _plugins: LanguageServerPlugin[], getRuntimeEnv: (params: vscode.InitializeParams, options: InitializationOptions) => RuntimeEnvironment): void;
@@ -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
- async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
16
+ function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
17
17
  let initParams;
18
18
  let options;
19
19
  let roots = [];
20
- let projects;
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
- projects?.add(vscode_uri_1.URI.parse(folder.uri));
112
+ workspaces?.add(vscode_uri_1.URI.parse(folder.uri));
113
113
  }
114
114
  for (const folder of e.removed) {
115
- projects?.remove(vscode_uri_1.URI.parse(folder.uri));
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
- if (projects) {
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
- projects = (0, workspaces_1.createWorkspaces)({
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
- for (const root of roots) {
212
- projects.add(root);
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 projects.getProject(uri))?.project;
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
  }
@@ -14,7 +14,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
14
14
  clear: () => void;
15
15
  values: () => IterableIterator<Promise<{
16
16
  context: import("./project").ProjectContext;
17
- tsConfig: ts.CompilerOptions | path.PosixPath;
17
+ tsConfig: path.PosixPath | ts.CompilerOptions;
18
18
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
19
19
  getLanguageService: () => {
20
20
  getTriggerCharacters: () => string[];
@@ -141,7 +141,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
141
141
  uriDelete: (_uri: string) => boolean;
142
142
  uriGet: (_uri: string) => Promise<{
143
143
  context: import("./project").ProjectContext;
144
- tsConfig: ts.CompilerOptions | path.PosixPath;
144
+ tsConfig: path.PosixPath | ts.CompilerOptions;
145
145
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
146
146
  getLanguageService: () => {
147
147
  getTriggerCharacters: () => string[];
@@ -268,7 +268,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
268
268
  uriHas: (_uri: string) => boolean;
269
269
  uriSet: (_uri: string, item: Promise<{
270
270
  context: import("./project").ProjectContext;
271
- tsConfig: ts.CompilerOptions | path.PosixPath;
271
+ tsConfig: path.PosixPath | ts.CompilerOptions;
272
272
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
273
273
  getLanguageService: () => {
274
274
  getTriggerCharacters: () => string[];
@@ -395,7 +395,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
395
395
  pathDelete: (path: string) => boolean;
396
396
  pathGet: (path: string) => Promise<{
397
397
  context: import("./project").ProjectContext;
398
- tsConfig: ts.CompilerOptions | path.PosixPath;
398
+ tsConfig: path.PosixPath | ts.CompilerOptions;
399
399
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
400
400
  getLanguageService: () => {
401
401
  getTriggerCharacters: () => string[];
@@ -521,7 +521,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
521
521
  }> | undefined;
522
522
  pathHas: (path: string) => Promise<{
523
523
  context: import("./project").ProjectContext;
524
- tsConfig: ts.CompilerOptions | path.PosixPath;
524
+ tsConfig: path.PosixPath | ts.CompilerOptions;
525
525
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
526
526
  getLanguageService: () => {
527
527
  getTriggerCharacters: () => string[];
@@ -647,7 +647,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
647
647
  }> | undefined;
648
648
  pathSet: (path: string, item: Promise<{
649
649
  context: import("./project").ProjectContext;
650
- tsConfig: ts.CompilerOptions | path.PosixPath;
650
+ tsConfig: path.PosixPath | ts.CompilerOptions;
651
651
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
652
652
  getLanguageService: () => {
653
653
  getTriggerCharacters: () => string[];
@@ -776,7 +776,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
776
776
  tsconfig: string;
777
777
  project: {
778
778
  context: import("./project").ProjectContext;
779
- tsConfig: ts.CompilerOptions | path.PosixPath;
779
+ tsConfig: path.PosixPath | ts.CompilerOptions;
780
780
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
781
781
  getLanguageService: () => {
782
782
  getTriggerCharacters: () => string[];
@@ -903,7 +903,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
903
903
  } | undefined>;
904
904
  getInferredProject: () => Promise<{
905
905
  context: import("./project").ProjectContext;
906
- tsConfig: ts.CompilerOptions | path.PosixPath;
906
+ tsConfig: path.PosixPath | ts.CompilerOptions;
907
907
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
908
908
  getLanguageService: () => {
909
909
  getTriggerCharacters: () => string[];
@@ -1029,7 +1029,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
1029
1029
  }>;
1030
1030
  getInferredProjectDontCreate: () => Promise<{
1031
1031
  context: import("./project").ProjectContext;
1032
- tsConfig: ts.CompilerOptions | path.PosixPath;
1032
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1033
1033
  languageHost: import("@volar/language-service").TypeScriptLanguageHost;
1034
1034
  getLanguageService: () => {
1035
1035
  getTriggerCharacters: () => string[];