@volar/language-server 1.5.2 → 1.5.3

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.
@@ -4,15 +4,16 @@ import * as path from 'typesafe-path';
4
4
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
5
  import { URI } from 'vscode-uri';
6
6
  import { WorkspaceContext } from './workspace';
7
- export interface ProjectContext {
8
- workspace: WorkspaceContext;
9
- rootUri: URI;
10
- tsConfig: path.PosixPath | ts.CompilerOptions;
11
- documentRegistry: ts.DocumentRegistry | undefined;
7
+ export interface ProjectContext extends WorkspaceContext {
8
+ project: {
9
+ rootUri: URI;
10
+ tsConfig: path.PosixPath | ts.CompilerOptions;
11
+ documentRegistry: ts.DocumentRegistry | undefined;
12
+ };
12
13
  }
13
14
  export type Project = ReturnType<typeof createProject>;
14
15
  export declare function createProject(context: ProjectContext): Promise<{
15
- tsConfig: ts.CompilerOptions | path.PosixPath;
16
+ tsConfig: path.PosixPath | ts.CompilerOptions;
16
17
  scripts: {
17
18
  clear: () => void;
18
19
  values: () => IterableIterator<{
@@ -9,9 +9,9 @@ const types_1 = require("../types");
9
9
  const serverConfig_1 = require("./utils/serverConfig");
10
10
  const uriMap_1 = require("./utils/uriMap");
11
11
  async function createProject(context) {
12
- const uriToFileName = context.workspace.workspaces.server.runtimeEnv.uriToFileName;
13
- const fileNameToUri = context.workspace.workspaces.server.runtimeEnv.fileNameToUri;
14
- const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
12
+ const uriToFileName = context.server.runtimeEnv.uriToFileName;
13
+ const fileNameToUri = context.server.runtimeEnv.fileNameToUri;
14
+ const sys = context.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspaces.fileSystemHost
15
15
  ? {
16
16
  newLine: '\n',
17
17
  useCaseSensitiveFileNames: false,
@@ -22,23 +22,23 @@ async function createProject(context) {
22
22
  realpath: () => '',
23
23
  resolvePath: () => '',
24
24
  }
25
- : context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
25
+ : context.workspaces.fileSystemHost.getWorkspaceFileSystem(context.project.rootUri);
26
26
  let typeRootVersion = 0;
27
27
  let projectVersion = 0;
28
- let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
28
+ let projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
29
29
  let languageService;
30
- let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
30
+ let parsedCommandLine = createParsedCommandLine(context.workspaces.ts, sys, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins);
31
31
  const scripts = (0, uriMap_1.createUriMap)(fileNameToUri);
32
32
  const languageServiceHost = createLanguageServiceHost();
33
- const disposeWatchEvent = context.workspace.workspaces.fileSystemHost?.onDidChangeWatchedFiles(params => {
33
+ const disposeWatchEvent = context.workspaces.fileSystemHost?.onDidChangeWatchedFiles(params => {
34
34
  onWorkspaceFilesChanged(params.changes);
35
35
  });
36
- const disposeDocChange = context.workspace.workspaces.documents.onDidChangeContent(() => {
36
+ const disposeDocChange = context.workspaces.documents.onDidChangeContent(() => {
37
37
  projectVersion++;
38
- projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
38
+ projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
39
39
  });
40
40
  return {
41
- tsConfig: context.tsConfig,
41
+ tsConfig: context.project.tsConfig,
42
42
  scripts,
43
43
  languageServiceHost,
44
44
  getLanguageService,
@@ -48,7 +48,7 @@ async function createProject(context) {
48
48
  if (!parsedCommandLine.fileNames.includes(fileName)) {
49
49
  parsedCommandLine.fileNames.push(fileName);
50
50
  projectVersion++;
51
- projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
51
+ projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
52
52
  }
53
53
  },
54
54
  dispose,
@@ -58,35 +58,35 @@ async function createProject(context) {
58
58
  const env = {
59
59
  uriToFileName,
60
60
  fileNameToUri,
61
- locale: context.workspace.workspaces.initParams.locale,
62
- rootUri: context.rootUri,
63
- clientCapabilities: context.workspace.workspaces.initParams.capabilities,
64
- getConfiguration: context.workspace.workspaces.configurationHost?.getConfiguration,
65
- onDidChangeConfiguration: context.workspace.workspaces.configurationHost?.onDidChangeConfiguration,
66
- fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
67
- onDidChangeWatchedFiles: context.workspace.workspaces.fileSystemHost?.onDidChangeWatchedFiles,
68
- documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
61
+ locale: context.workspaces.initParams.locale,
62
+ rootUri: context.project.rootUri,
63
+ clientCapabilities: context.workspaces.initParams.capabilities,
64
+ getConfiguration: context.workspaces.configurationHost?.getConfiguration,
65
+ onDidChangeConfiguration: context.workspaces.configurationHost?.onDidChangeConfiguration,
66
+ fileSystemProvider: context.server.runtimeEnv.fileSystemProvide,
67
+ onDidChangeWatchedFiles: context.workspaces.fileSystemHost?.onDidChangeWatchedFiles,
68
+ documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspaces.ts, languageServiceHost, context.project.rootUri.toString()),
69
69
  schemaRequestService: async (uri) => {
70
70
  const protocol = uri.substring(0, uri.indexOf(':'));
71
- const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
71
+ const builtInHandler = context.server.runtimeEnv.schemaRequestHandlers[protocol];
72
72
  if (builtInHandler) {
73
73
  return await builtInHandler(uri) ?? '';
74
74
  }
75
75
  return '';
76
76
  },
77
77
  };
78
- let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.workspace.rootUri.path, context.workspace.workspaces.initOptions.configFilePath) : {}) ?? {};
79
- for (const plugin of context.workspace.workspaces.plugins) {
78
+ let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.workspace.rootUri.path, context.workspaces.initOptions.configFilePath) : {}) ?? {};
79
+ for (const plugin of context.workspaces.plugins) {
80
80
  if (plugin.resolveConfig) {
81
81
  config = plugin.resolveConfig(config, {
82
+ ...context,
82
83
  env,
83
- project: context,
84
84
  sys,
85
85
  host: languageServiceHost,
86
86
  });
87
87
  }
88
88
  }
89
- languageService = embeddedLS.createLanguageService({ typescript: context.workspace.workspaces.ts }, env, config, languageServiceHost, context.documentRegistry);
89
+ languageService = embeddedLS.createLanguageService({ typescript: context.workspaces.ts }, env, config, languageServiceHost, context.project.documentRegistry);
90
90
  }
91
91
  return languageService;
92
92
  }
@@ -114,18 +114,18 @@ async function createProject(context) {
114
114
  const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
115
115
  const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
116
116
  if (creates.length || deletes.length) {
117
- parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
117
+ parsedCommandLine = createParsedCommandLine(context.workspaces.ts, sys, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins);
118
118
  projectVersion++;
119
119
  typeRootVersion++;
120
120
  }
121
121
  if (_projectVersion !== projectVersion) {
122
- projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
122
+ projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
123
123
  }
124
124
  }
125
125
  function createLanguageServiceHost() {
126
126
  const token = {
127
127
  isCancellationRequested() {
128
- return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
128
+ return context.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
129
129
  },
130
130
  throwIfCancellationRequested() { },
131
131
  };
@@ -140,19 +140,19 @@ async function createProject(context) {
140
140
  readDirectory: sys.readDirectory,
141
141
  realpath: sys.realpath,
142
142
  fileExists: sys.fileExists,
143
- getCurrentDirectory: () => uriToFileName(context.rootUri.toString()),
143
+ getCurrentDirectory: () => uriToFileName(context.project.rootUri.toString()),
144
144
  getProjectReferences: () => parsedCommandLine.projectReferences,
145
145
  getCancellationToken: () => token,
146
146
  // custom
147
147
  getDefaultLibFileName: options => {
148
- if (context.workspace.workspaces.initOptions.typescript && context.workspace.workspaces.ts) {
148
+ if (context.workspaces.initOptions.typescript && context.workspaces.ts) {
149
149
  try {
150
- return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
150
+ return context.workspaces.ts.getDefaultLibFilePath(options);
151
151
  }
152
152
  catch {
153
153
  // web
154
- const tsdk = context.workspace.workspaces.initOptions.typescript.tsdk;
155
- return tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
154
+ const tsdk = context.workspaces.initOptions.typescript.tsdk;
155
+ return tsdk + '/' + context.workspaces.ts.getDefaultLibFileName(options);
156
156
  }
157
157
  }
158
158
  return '';
@@ -164,22 +164,22 @@ async function createProject(context) {
164
164
  getScriptVersion,
165
165
  getScriptSnapshot,
166
166
  getScriptLanguageId: (fileName) => {
167
- return context.workspace.workspaces.documents.data.pathGet(fileName)?.languageId;
167
+ return context.workspaces.documents.data.pathGet(fileName)?.languageId;
168
168
  },
169
169
  };
170
- if (context.workspace.workspaces.tsLocalized) {
171
- host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
170
+ if (context.workspaces.tsLocalized) {
171
+ host.getLocalizedDiagnosticMessages = () => context.workspaces.tsLocalized;
172
172
  }
173
173
  return host;
174
174
  function getScriptVersion(fileName) {
175
- const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
175
+ const doc = context.workspaces.documents.data.pathGet(fileName);
176
176
  if (doc) {
177
177
  return doc.version.toString();
178
178
  }
179
179
  return scripts.pathGet(fileName)?.version.toString() ?? '';
180
180
  }
181
181
  function getScriptSnapshot(fileName) {
182
- const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
182
+ const doc = context.workspaces.documents.data.pathGet(fileName);
183
183
  if (doc) {
184
184
  return doc.getSnapshot();
185
185
  }
@@ -187,17 +187,17 @@ async function createProject(context) {
187
187
  if (script && script.snapshotVersion === script.version) {
188
188
  return script.snapshot;
189
189
  }
190
- if (context.workspace.workspaces.ts && sys.fileExists(fileName)) {
191
- if (context.workspace.workspaces.initOptions.maxFileSize) {
190
+ if (context.workspaces.ts && sys.fileExists(fileName)) {
191
+ if (context.workspaces.initOptions.maxFileSize) {
192
192
  const fileSize = sys.getFileSize?.(fileName);
193
- if (fileSize !== undefined && fileSize > context.workspace.workspaces.initOptions.maxFileSize) {
194
- console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspace.workspaces.initOptions.maxFileSize}bytes)`);
195
- return context.workspace.workspaces.ts.ScriptSnapshot.fromString('');
193
+ if (fileSize !== undefined && fileSize > context.workspaces.initOptions.maxFileSize) {
194
+ console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspaces.initOptions.maxFileSize}bytes)`);
195
+ return context.workspaces.ts.ScriptSnapshot.fromString('');
196
196
  }
197
197
  }
198
198
  const text = sys.readFile(fileName, 'utf8');
199
199
  if (text !== undefined) {
200
- const snapshot = context.workspace.workspaces.ts.ScriptSnapshot.fromString(text);
200
+ const snapshot = context.workspaces.ts.ScriptSnapshot.fromString(text);
201
201
  if (script) {
202
202
  script.snapshot = snapshot;
203
203
  script.snapshotVersion = script.version;
@@ -1,8 +1,10 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
2
  import { InitializationOptions, LanguageServerPlugin, RuntimeEnvironment } from '../types';
3
3
  export interface ServerContext {
4
- connection: vscode.Connection;
5
- runtimeEnv: RuntimeEnvironment;
6
- plugins: LanguageServerPlugin[];
4
+ server: {
5
+ connection: vscode.Connection;
6
+ runtimeEnv: RuntimeEnvironment;
7
+ plugins: LanguageServerPlugin[];
8
+ };
7
9
  }
8
- export declare function startCommonLanguageServer(connection: vscode.Connection, getCtx: (initOptions: InitializationOptions) => ServerContext): void;
10
+ export declare function startCommonLanguageServer(connection: vscode.Connection, getCtx: (initOptions: InitializationOptions) => ServerContext['server']): void;
@@ -25,11 +25,11 @@ function startCommonLanguageServer(connection, getCtx) {
25
25
  connection.onInitialize(async (_params) => {
26
26
  initParams = _params;
27
27
  options = initParams.initializationOptions;
28
- context = getCtx(options);
29
- plugins = context.plugins.map(plugin => plugin(options, {
30
- typescript: options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined
28
+ context = { server: getCtx(options) };
29
+ plugins = context.server.plugins.map(plugin => plugin(options, {
30
+ typescript: options.typescript ? context.server.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined
31
31
  }));
32
- documents = (0, documents_1.createDocuments)(context.runtimeEnv, connection);
32
+ documents = (0, documents_1.createDocuments)(context.server.runtimeEnv, connection);
33
33
  if (options.l10n) {
34
34
  await l10n.config({ uri: options.l10n.location });
35
35
  }
@@ -121,29 +121,31 @@ function startCommonLanguageServer(connection, getCtx) {
121
121
  });
122
122
  connection.listen();
123
123
  async function createLanguageServiceHost() {
124
- const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
125
- fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.runtimeEnv, options) : undefined;
126
- const tsLocalized = options.typescript && initParams.locale ? await context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
124
+ const ts = options.typescript ? context.server.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
125
+ fsHost = ts ? context.server.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.server.runtimeEnv, options) : undefined;
126
+ const tsLocalized = options.typescript && initParams.locale ? await context.server.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
127
127
  const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
128
128
  projects = (0, workspaces_1.createWorkspaces)({
129
- server: context,
130
- fileSystemHost: fsHost,
131
- configurationHost,
132
- ts,
133
- tsLocalized,
134
- initParams,
135
- initOptions: options,
136
- documents,
137
- cancelTokenHost,
138
- plugins,
129
+ ...context,
130
+ workspaces: {
131
+ fileSystemHost: fsHost,
132
+ configurationHost,
133
+ ts,
134
+ tsLocalized,
135
+ initParams,
136
+ initOptions: options,
137
+ documents,
138
+ cancelTokenHost,
139
+ plugins,
140
+ },
139
141
  });
140
142
  for (const root of roots) {
141
143
  projects.add(root);
142
144
  }
143
- (await Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
144
- (await Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
145
+ (await Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.server.runtimeEnv);
146
+ (await Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.server.runtimeEnv, documents);
145
147
  for (const plugin of plugins) {
146
- plugin.onInitialized?.(getLanguageService, context.runtimeEnv);
148
+ plugin.onInitialized?.(getLanguageService, context.server.runtimeEnv);
147
149
  }
148
150
  async function getLanguageService(uri) {
149
151
  const project = (await projects.getProject(uri))?.project;
@@ -5,15 +5,16 @@ import * as vscode from 'vscode-languageserver';
5
5
  import { URI } from 'vscode-uri';
6
6
  import { WorkspacesContext } from './workspaces';
7
7
  export declare const rootTsConfigNames: string[];
8
- export interface WorkspaceContext {
9
- workspaces: WorkspacesContext;
10
- rootUri: URI;
8
+ export interface WorkspaceContext extends WorkspacesContext {
9
+ workspace: {
10
+ rootUri: URI;
11
+ };
11
12
  }
12
13
  export declare function createWorkspace(context: WorkspaceContext): Promise<{
13
14
  projects: {
14
15
  clear: () => void;
15
16
  values: () => IterableIterator<Promise<{
16
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
17
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
17
18
  scripts: {
18
19
  clear: () => void;
19
20
  values: () => IterableIterator<{
@@ -159,7 +160,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
159
160
  }>>;
160
161
  uriDelete: (_uri: string) => boolean;
161
162
  uriGet: (_uri: string) => Promise<{
162
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
163
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
163
164
  scripts: {
164
165
  clear: () => void;
165
166
  values: () => IterableIterator<{
@@ -305,7 +306,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
305
306
  }> | undefined;
306
307
  uriHas: (_uri: string) => boolean;
307
308
  uriSet: (_uri: string, item: Promise<{
308
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
309
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
309
310
  scripts: {
310
311
  clear: () => void;
311
312
  values: () => IterableIterator<{
@@ -451,7 +452,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
451
452
  }>) => void;
452
453
  pathDelete: (path: string) => boolean;
453
454
  pathGet: (path: string) => Promise<{
454
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
455
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
455
456
  scripts: {
456
457
  clear: () => void;
457
458
  values: () => IterableIterator<{
@@ -596,7 +597,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
596
597
  dispose: () => void;
597
598
  }> | undefined;
598
599
  pathHas: (path: string) => Promise<{
599
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
600
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
600
601
  scripts: {
601
602
  clear: () => void;
602
603
  values: () => IterableIterator<{
@@ -741,7 +742,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
741
742
  dispose: () => void;
742
743
  }> | undefined;
743
744
  pathSet: (path: string, item: Promise<{
744
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
745
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
745
746
  scripts: {
746
747
  clear: () => void;
747
748
  values: () => IterableIterator<{
@@ -890,7 +891,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
890
891
  getProjectAndTsConfig: (uri: string) => Promise<{
891
892
  tsconfig: string;
892
893
  project: {
893
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
894
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
894
895
  scripts: {
895
896
  clear: () => void;
896
897
  values: () => IterableIterator<{
@@ -1036,7 +1037,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
1036
1037
  } | undefined;
1037
1038
  } | undefined>;
1038
1039
  getInferredProject: () => Promise<{
1039
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1040
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
1040
1041
  scripts: {
1041
1042
  clear: () => void;
1042
1043
  values: () => IterableIterator<{
@@ -1181,7 +1182,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
1181
1182
  dispose: () => void;
1182
1183
  }>;
1183
1184
  getInferredProjectDontCreate: () => Promise<{
1184
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1185
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
1185
1186
  scripts: {
1186
1187
  clear: () => void;
1187
1188
  values: () => IterableIterator<{
@@ -10,11 +10,11 @@ const uriMap_1 = require("./utils/uriMap");
10
10
  const isFileInDir_1 = require("./utils/isFileInDir");
11
11
  exports.rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
12
12
  async function createWorkspace(context) {
13
- const fileNameToUri = context.workspaces.server.runtimeEnv.fileNameToUri;
14
- const uriToFileName = context.workspaces.server.runtimeEnv.uriToFileName;
13
+ const fileNameToUri = context.server.runtimeEnv.fileNameToUri;
14
+ const uriToFileName = context.server.runtimeEnv.uriToFileName;
15
15
  let inferredProject;
16
- const sys = context.workspaces.fileSystemHost?.getWorkspaceFileSystem(context.rootUri);
17
- const documentRegistry = sys ? context.workspaces.ts?.createDocumentRegistry(sys.useCaseSensitiveFileNames, uriToFileName(context.rootUri.toString())) : undefined;
16
+ const sys = context.workspaces.fileSystemHost?.getWorkspaceFileSystem(context.workspace.rootUri);
17
+ const documentRegistry = sys ? context.workspaces.ts?.createDocumentRegistry(sys.useCaseSensitiveFileNames, uriToFileName(context.workspace.rootUri.toString())) : undefined;
18
18
  const projects = (0, uriMap_1.createUriMap)(fileNameToUri);
19
19
  const rootTsConfigs = new Set();
20
20
  const searchedDirs = new Set();
@@ -22,7 +22,7 @@ async function createWorkspace(context) {
22
22
  for (const change of changes) {
23
23
  if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
24
24
  if (change.type === vscode.FileChangeType.Created) {
25
- if ((0, isFileInDir_1.isFileInDir)(uriToFileName(change.uri), uriToFileName(context.rootUri.toString()))) {
25
+ if ((0, isFileInDir_1.isFileInDir)(uriToFileName(change.uri), uriToFileName(context.workspace.rootUri.toString()))) {
26
26
  rootTsConfigs.add(uriToFileName(change.uri));
27
27
  }
28
28
  }
@@ -75,10 +75,12 @@ async function createWorkspace(context) {
75
75
  inferredProject = (async () => {
76
76
  const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context.workspaces.configurationHost);
77
77
  return (0, project_1.createProject)({
78
- workspace: context,
79
- rootUri: context.rootUri,
80
- tsConfig: inferOptions,
81
- documentRegistry,
78
+ ...context,
79
+ project: {
80
+ rootUri: context.workspace.rootUri,
81
+ tsConfig: inferOptions,
82
+ documentRegistry,
83
+ },
82
84
  });
83
85
  })();
84
86
  }
@@ -200,10 +202,12 @@ async function createWorkspace(context) {
200
202
  let project = projects.pathGet(tsConfig);
201
203
  if (!project && documentRegistry) {
202
204
  project = (0, project_1.createProject)({
203
- workspace: context,
204
- rootUri: vscode_uri_1.URI.parse(fileNameToUri(path.dirname(tsConfig))),
205
- tsConfig,
206
- documentRegistry,
205
+ ...context,
206
+ project: {
207
+ rootUri: vscode_uri_1.URI.parse(fileNameToUri(path.dirname(tsConfig))),
208
+ tsConfig,
209
+ documentRegistry,
210
+ },
207
211
  });
208
212
  projects.pathSet(tsConfig, project);
209
213
  }
@@ -7,17 +7,18 @@ import { CancellationTokenHost } from './cancellationPipe';
7
7
  import { createDocuments } from './documents';
8
8
  import { ServerContext } from './server';
9
9
  import * as path from 'typesafe-path';
10
- export interface WorkspacesContext {
11
- server: ServerContext;
12
- initParams: vscode.InitializeParams;
13
- initOptions: InitializationOptions;
14
- plugins: ReturnType<LanguageServerPlugin>[];
15
- ts: typeof import('typescript/lib/tsserverlibrary') | undefined;
16
- tsLocalized: ts.MapLike<string> | undefined;
17
- fileSystemHost: FileSystemHost | undefined;
18
- configurationHost: Pick<ServiceEnvironment, 'getConfiguration' | 'onDidChangeConfiguration'> | undefined;
19
- documents: ReturnType<typeof createDocuments>;
20
- cancelTokenHost: CancellationTokenHost;
10
+ export interface WorkspacesContext extends ServerContext {
11
+ workspaces: {
12
+ initParams: vscode.InitializeParams;
13
+ initOptions: InitializationOptions;
14
+ plugins: ReturnType<LanguageServerPlugin>[];
15
+ ts: typeof import('typescript/lib/tsserverlibrary') | undefined;
16
+ tsLocalized: ts.MapLike<string> | undefined;
17
+ fileSystemHost: FileSystemHost | undefined;
18
+ configurationHost: Pick<ServiceEnvironment, 'getConfiguration' | 'onDidChangeConfiguration'> | undefined;
19
+ documents: ReturnType<typeof createDocuments>;
20
+ cancelTokenHost: CancellationTokenHost;
21
+ };
21
22
  }
22
23
  export interface Workspaces extends ReturnType<typeof createWorkspaces> {
23
24
  }
@@ -26,7 +27,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
26
27
  projects: {
27
28
  clear: () => void;
28
29
  values: () => IterableIterator<Promise<{
29
- tsConfig: ts.CompilerOptions | path.PosixPath;
30
+ tsConfig: path.PosixPath | ts.CompilerOptions;
30
31
  scripts: {
31
32
  clear: () => void;
32
33
  values: () => IterableIterator<{
@@ -172,7 +173,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
172
173
  }>>;
173
174
  uriDelete: (_uri: string) => boolean;
174
175
  uriGet: (_uri: string) => Promise<{
175
- tsConfig: ts.CompilerOptions | path.PosixPath;
176
+ tsConfig: path.PosixPath | ts.CompilerOptions;
176
177
  scripts: {
177
178
  clear: () => void;
178
179
  values: () => IterableIterator<{
@@ -318,7 +319,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
318
319
  }> | undefined;
319
320
  uriHas: (_uri: string) => boolean;
320
321
  uriSet: (_uri: string, item: Promise<{
321
- tsConfig: ts.CompilerOptions | path.PosixPath;
322
+ tsConfig: path.PosixPath | ts.CompilerOptions;
322
323
  scripts: {
323
324
  clear: () => void;
324
325
  values: () => IterableIterator<{
@@ -464,7 +465,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
464
465
  }>) => void;
465
466
  pathDelete: (path: string) => boolean;
466
467
  pathGet: (path: string) => Promise<{
467
- tsConfig: ts.CompilerOptions | path.PosixPath;
468
+ tsConfig: path.PosixPath | ts.CompilerOptions;
468
469
  scripts: {
469
470
  clear: () => void;
470
471
  values: () => IterableIterator<{
@@ -609,7 +610,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
609
610
  dispose: () => void;
610
611
  }> | undefined;
611
612
  pathHas: (path: string) => Promise<{
612
- tsConfig: ts.CompilerOptions | path.PosixPath;
613
+ tsConfig: path.PosixPath | ts.CompilerOptions;
613
614
  scripts: {
614
615
  clear: () => void;
615
616
  values: () => IterableIterator<{
@@ -754,7 +755,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
754
755
  dispose: () => void;
755
756
  }> | undefined;
756
757
  pathSet: (path: string, item: Promise<{
757
- tsConfig: ts.CompilerOptions | path.PosixPath;
758
+ tsConfig: path.PosixPath | ts.CompilerOptions;
758
759
  scripts: {
759
760
  clear: () => void;
760
761
  values: () => IterableIterator<{
@@ -903,7 +904,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
903
904
  getProjectAndTsConfig: (uri: string) => Promise<{
904
905
  tsconfig: string;
905
906
  project: {
906
- tsConfig: ts.CompilerOptions | path.PosixPath;
907
+ tsConfig: path.PosixPath | ts.CompilerOptions;
907
908
  scripts: {
908
909
  clear: () => void;
909
910
  values: () => IterableIterator<{
@@ -1049,7 +1050,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1049
1050
  } | undefined;
1050
1051
  } | undefined>;
1051
1052
  getInferredProject: () => Promise<{
1052
- tsConfig: ts.CompilerOptions | path.PosixPath;
1053
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1053
1054
  scripts: {
1054
1055
  clear: () => void;
1055
1056
  values: () => IterableIterator<{
@@ -1194,7 +1195,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1194
1195
  dispose: () => void;
1195
1196
  }>;
1196
1197
  getInferredProjectDontCreate: () => Promise<{
1197
- tsConfig: ts.CompilerOptions | path.PosixPath;
1198
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1198
1199
  scripts: {
1199
1200
  clear: () => void;
1200
1201
  values: () => IterableIterator<{
@@ -1344,7 +1345,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1344
1345
  getProject: (uri: string) => Promise<{
1345
1346
  tsconfig: string;
1346
1347
  project: {
1347
- tsConfig: ts.CompilerOptions | path.PosixPath;
1348
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1348
1349
  scripts: {
1349
1350
  clear: () => void;
1350
1351
  values: () => IterableIterator<{
@@ -1491,7 +1492,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1491
1492
  } | {
1492
1493
  tsconfig: undefined;
1493
1494
  project: {
1494
- tsConfig: ts.CompilerOptions | path.PosixPath;
1495
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1495
1496
  scripts: {
1496
1497
  clear: () => void;
1497
1498
  values: () => IterableIterator<{
@@ -10,13 +10,13 @@ function createWorkspaces(context) {
10
10
  const workspaces = new Map();
11
11
  let semanticTokensReq = 0;
12
12
  let documentUpdatedReq = 0;
13
- context.documents.onDidChangeContent(({ textDocument }) => {
13
+ context.workspaces.documents.onDidChangeContent(({ textDocument }) => {
14
14
  updateDiagnostics(textDocument.uri);
15
15
  });
16
- context.documents.onDidClose(({ textDocument }) => {
16
+ context.workspaces.documents.onDidClose(({ textDocument }) => {
17
17
  context.server.connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
18
18
  });
19
- context.fileSystemHost?.onDidChangeWatchedFiles(({ changes }) => {
19
+ context.workspaces.fileSystemHost?.onDidChangeWatchedFiles(({ changes }) => {
20
20
  const tsConfigChanges = changes.filter(change => workspace_1.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
21
21
  if (tsConfigChanges.length) {
22
22
  reloadDiagnostics();
@@ -35,8 +35,10 @@ function createWorkspaces(context) {
35
35
  add: (rootUri) => {
36
36
  if (!workspaces.has(rootUri.toString())) {
37
37
  workspaces.set(rootUri.toString(), (0, workspace_1.createWorkspace)({
38
- workspaces: context,
39
- rootUri,
38
+ ...context,
39
+ workspace: {
40
+ rootUri,
41
+ },
40
42
  }));
41
43
  }
42
44
  },
@@ -49,14 +51,14 @@ function createWorkspaces(context) {
49
51
  },
50
52
  };
51
53
  async function reloadProject() {
52
- context.fileSystemHost?.reload();
54
+ context.workspaces.fileSystemHost?.reload();
53
55
  for (const [_, workspace] of workspaces) {
54
56
  (await workspace).reload();
55
57
  }
56
58
  reloadDiagnostics();
57
59
  }
58
60
  function reloadDiagnostics() {
59
- for (const doc of context.documents.data.values()) {
61
+ for (const doc of context.workspaces.documents.data.values()) {
60
62
  context.server.connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
61
63
  }
62
64
  updateDiagnosticsAndSemanticTokens();
@@ -67,27 +69,27 @@ function createWorkspaces(context) {
67
69
  const delay = 250;
68
70
  await sleep(delay);
69
71
  if (req === semanticTokensReq) {
70
- if (context.initParams.capabilities.textDocument?.semanticTokens) {
72
+ if (context.workspaces.initParams.capabilities.textDocument?.semanticTokens) {
71
73
  context.server.connection.languages.semanticTokens.refresh();
72
74
  }
73
- if (context.initParams.capabilities.textDocument?.inlayHint) {
75
+ if (context.workspaces.initParams.capabilities.textDocument?.inlayHint) {
74
76
  context.server.connection.languages.inlayHint.refresh();
75
77
  }
76
78
  }
77
79
  }
78
80
  async function updateDiagnostics(docUri) {
79
- if ((context.initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) !== types_1.DiagnosticModel.Push)
81
+ if ((context.workspaces.initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) !== types_1.DiagnosticModel.Push)
80
82
  return;
81
83
  const req = ++documentUpdatedReq;
82
84
  const delay = 250;
83
- const cancel = context.cancelTokenHost.createCancellationToken({
85
+ const cancel = context.workspaces.cancelTokenHost.createCancellationToken({
84
86
  get isCancellationRequested() {
85
87
  return req !== documentUpdatedReq;
86
88
  },
87
89
  onCancellationRequested: vscode.Event.None,
88
90
  });
89
- const changeDoc = docUri ? context.documents.data.uriGet(docUri) : undefined;
90
- const otherDocs = [...context.documents.data.values()].filter(doc => doc !== changeDoc);
91
+ const changeDoc = docUri ? context.workspaces.documents.data.uriGet(docUri) : undefined;
92
+ const otherDocs = [...context.workspaces.documents.data.values()].filter(doc => doc !== changeDoc);
91
93
  if (changeDoc) {
92
94
  await sleep(delay);
93
95
  if (cancel.isCancellationRequested) {
@@ -108,7 +110,7 @@ function createWorkspaces(context) {
108
110
  if (!project)
109
111
  return;
110
112
  // fix https://github.com/vuejs/language-tools/issues/2627
111
- if (context.initOptions.serverMode === types_1.ServerMode.Syntactic) {
113
+ if (context.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic) {
112
114
  return;
113
115
  }
114
116
  // const mode = context.initOptions.serverMode === ServerMode.PartialSemantic ? 'semantic' as const
@@ -124,7 +126,7 @@ function createWorkspaces(context) {
124
126
  let rootUris = [...workspaces.keys()]
125
127
  .filter(rootUri => (0, isFileInDir_1.isFileInDir)(uriToFileName(uri), uriToFileName(rootUri)))
126
128
  .sort((a, b) => (0, workspace_1.sortTsConfigs)(uriToFileName(uri), uriToFileName(a), uriToFileName(b)));
127
- if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
129
+ if (context.workspaces.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
128
130
  for (const rootUri of rootUris) {
129
131
  const workspace = await workspaces.get(rootUri);
130
132
  const projectAndTsConfig = await workspace?.getProjectAndTsConfig(uri);
package/out/types.d.ts CHANGED
@@ -29,18 +29,18 @@ export interface RuntimeEnvironment {
29
29
  setImmediate(callback: (...args: any[]) => void, ...args: any[]): vscode.Disposable;
30
30
  };
31
31
  }
32
+ interface LanguageServerPluginContext extends ProjectContext {
33
+ env: ServiceEnvironment;
34
+ host: embedded.LanguageServiceHost;
35
+ sys: FileSystem;
36
+ }
32
37
  export interface LanguageServerPlugin {
33
38
  (initOptions: InitializationOptions, modules: {
34
39
  typescript?: typeof import('typescript/lib/tsserverlibrary');
35
40
  }): {
36
41
  extraFileExtensions?: ts.FileExtensionInfo[];
37
42
  watchFileExtensions?: string[];
38
- resolveConfig?(config: Config, ctx: {
39
- env: ServiceEnvironment;
40
- project: ProjectContext;
41
- host: embedded.LanguageServiceHost;
42
- sys: FileSystem;
43
- } | undefined): Config;
43
+ resolveConfig?(config: Config, ctx: LanguageServerPluginContext | undefined): Config;
44
44
  onInitialized?(getLanguageService: (uri: string) => Promise<LanguageService | undefined>, env: RuntimeEnvironment): void;
45
45
  };
46
46
  }
@@ -98,3 +98,4 @@ export interface InitializationOptions {
98
98
  */
99
99
  semanticTokensLegend?: vscode.SemanticTokensLegend;
100
100
  }
101
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,8 +17,8 @@
17
17
  "directory": "packages/language-server"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "1.5.2",
21
- "@volar/language-service": "1.5.2",
20
+ "@volar/language-core": "1.5.3",
21
+ "@volar/language-service": "1.5.3",
22
22
  "@vscode/l10n": "^0.0.11",
23
23
  "request-light": "^0.7.0",
24
24
  "typesafe-path": "^0.2.2",
@@ -28,5 +28,5 @@
28
28
  "vscode-languageserver-textdocument": "^1.0.8",
29
29
  "vscode-uri": "^3.0.7"
30
30
  },
31
- "gitHead": "e58503bf9700e96557e583f95e38a21c8f7b4a0a"
31
+ "gitHead": "4d4849277f76523ad1f2719cc94e09abb8c7c77c"
32
32
  }