@volar/language-server 1.0.18 → 1.0.19

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.
@@ -3,18 +3,18 @@ import * as embeddedLS from '@volar/language-service';
3
3
  import * as path from 'typesafe-path';
4
4
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
5
  import { URI } from 'vscode-uri';
6
- import { WorkspaceParams } from './workspace';
7
- import { LanguageServicePlugin } from '@volar/language-service';
8
- export interface ProjectParams {
9
- workspace: WorkspaceParams;
6
+ import { WorkspaceContext } from './workspace';
7
+ import { ServerConfig } from './utils/serverConfig';
8
+ export interface ProjectContext {
9
+ workspace: WorkspaceContext;
10
10
  rootUri: URI;
11
11
  tsConfig: path.PosixPath | ts.CompilerOptions;
12
12
  documentRegistry: ts.DocumentRegistry;
13
- workspacePlugins: LanguageServicePlugin[];
13
+ serverConfig: ServerConfig | undefined;
14
14
  }
15
15
  export type Project = ReturnType<typeof createProject>;
16
- export declare function createProject(params: ProjectParams): Promise<{
17
- tsConfig: path.PosixPath | ts.CompilerOptions;
16
+ export declare function createProject(context: ProjectContext): Promise<{
17
+ tsConfig: ts.CompilerOptions | path.PosixPath;
18
18
  scripts: {
19
19
  clear: () => void;
20
20
  values: () => IterableIterator<{
@@ -15,75 +15,72 @@ const shared = require("@volar/shared");
15
15
  const path = require("typesafe-path");
16
16
  const vscode = require("vscode-languageserver");
17
17
  const uriMap_1 = require("./utils/uriMap");
18
- function createProject(params) {
18
+ function createProject(context) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const { tsConfig, documentRegistry, rootUri } = params;
21
- const { ts, fileSystemHost, documents, cancelTokenHost, tsLocalized, initOptions, configurationHost } = params.workspace.workspaces;
22
- const { plugins } = params.workspace.workspaces;
23
- const { runtimeEnv } = params.workspace.workspaces.server;
24
- const sys = fileSystemHost.getWorkspaceFileSystem(rootUri);
20
+ const sys = context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
25
21
  let typeRootVersion = 0;
26
22
  let projectVersion = 0;
27
- let projectVersionUpdateTime = cancelTokenHost.getMtime();
28
- let vueLs;
29
- let parsedCommandLine = createParsedCommandLine(ts, sys, shared.getPathOfUri(rootUri.toString()), tsConfig, plugins);
23
+ let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
24
+ let languageService;
25
+ let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.getPathOfUri(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
30
26
  const scripts = (0, uriMap_1.createUriMap)();
31
27
  const languageServiceHost = createLanguageServiceHost();
32
- const disposeWatchEvent = fileSystemHost.onDidChangeWatchedFiles(params => {
28
+ const disposeWatchEvent = context.workspace.workspaces.fileSystemHost.onDidChangeWatchedFiles(params => {
33
29
  onWorkspaceFilesChanged(params.changes);
34
30
  });
35
- const disposeDocChange = documents.onDidChangeContent(() => {
31
+ const disposeDocChange = context.workspace.workspaces.documents.onDidChangeContent(() => {
36
32
  projectVersion++;
37
- projectVersionUpdateTime = cancelTokenHost.getMtime();
33
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
38
34
  });
39
35
  return {
40
- tsConfig,
36
+ tsConfig: context.tsConfig,
41
37
  scripts,
42
38
  languageServiceHost,
43
39
  getLanguageService,
44
- getLanguageServiceDontCreate: () => vueLs,
40
+ getLanguageServiceDontCreate: () => languageService,
45
41
  getParsedCommandLine: () => parsedCommandLine,
46
42
  tryAddFile: (fileName) => {
47
43
  if (!parsedCommandLine.fileNames.includes(fileName)) {
48
44
  parsedCommandLine.fileNames.push(fileName);
49
45
  projectVersion++;
50
- projectVersionUpdateTime = cancelTokenHost.getMtime();
46
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
51
47
  }
52
48
  },
53
49
  dispose,
54
50
  };
55
51
  function getLanguageService() {
56
- if (!vueLs) {
57
- const languageModules = plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.getLanguageModules) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost)) !== null && _c !== void 0 ? _c : []; }).flat();
52
+ if (!languageService) {
53
+ const languageModules = context.workspace.workspaces.plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.getLanguageModules) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost)) !== null && _c !== void 0 ? _c : []; }).flat();
58
54
  const languageContext = embedded.createLanguageContext(languageServiceHost, languageModules);
59
55
  const languageServiceContext = embeddedLS.createLanguageServiceContext({
60
56
  host: languageServiceHost,
61
57
  context: languageContext,
62
58
  getPlugins() {
59
+ var _a, _b;
63
60
  return [
64
- ...params.workspacePlugins,
65
- ...plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.getServicePlugins) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost, vueLs)) !== null && _c !== void 0 ? _c : []; }).flat(),
61
+ ...(_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : [],
62
+ ...context.workspace.workspaces.plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.getServicePlugins) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost, languageService)) !== null && _c !== void 0 ? _c : []; }).flat(),
66
63
  ];
67
64
  },
68
65
  env: {
69
- rootUri,
70
- configurationHost: configurationHost,
71
- fileSystemProvider: runtimeEnv.fileSystemProvide,
72
- documentContext: getHTMLDocumentContext(ts, languageServiceHost),
66
+ rootUri: context.rootUri,
67
+ configurationHost: context.workspace.workspaces.configurationHost,
68
+ fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
69
+ documentContext: getHTMLDocumentContext(context.workspace.workspaces.ts, languageServiceHost),
73
70
  schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
74
71
  const protocol = uri.substring(0, uri.indexOf(':'));
75
- const builtInHandler = runtimeEnv.schemaRequestHandlers[protocol];
72
+ const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
76
73
  if (builtInHandler) {
77
74
  return yield builtInHandler(uri);
78
75
  }
79
76
  return '';
80
77
  }),
81
78
  },
82
- documentRegistry,
79
+ documentRegistry: context.documentRegistry,
83
80
  });
84
- vueLs = embeddedLS.createLanguageService(languageServiceContext);
81
+ languageService = embeddedLS.createLanguageService(languageServiceContext);
85
82
  }
86
- return vueLs;
83
+ return languageService;
87
84
  }
88
85
  function onWorkspaceFilesChanged(changes) {
89
86
  return __awaiter(this, void 0, void 0, function* () {
@@ -108,12 +105,12 @@ function createProject(params) {
108
105
  const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
109
106
  const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
110
107
  if (creates.length || deletes.length) {
111
- parsedCommandLine = createParsedCommandLine(ts, sys, shared.getPathOfUri(rootUri.toString()), tsConfig, plugins);
108
+ parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.getPathOfUri(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
112
109
  projectVersion++;
113
110
  typeRootVersion++;
114
111
  }
115
112
  if (_projectVersion !== projectVersion) {
116
- projectVersionUpdateTime = cancelTokenHost.getMtime();
113
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
117
114
  }
118
115
  });
119
116
  }
@@ -121,7 +118,7 @@ function createProject(params) {
121
118
  var _a;
122
119
  const token = {
123
120
  isCancellationRequested() {
124
- return cancelTokenHost.getMtime() !== projectVersionUpdateTime;
121
+ return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
125
122
  },
126
123
  throwIfCancellationRequested() { },
127
124
  };
@@ -136,17 +133,17 @@ function createProject(params) {
136
133
  readDirectory: sys.readDirectory,
137
134
  realpath: sys.realpath,
138
135
  fileExists: sys.fileExists,
139
- getCurrentDirectory: () => shared.getPathOfUri(rootUri.toString()),
136
+ getCurrentDirectory: () => shared.getPathOfUri(context.rootUri.toString()),
140
137
  getProjectReferences: () => parsedCommandLine.projectReferences,
141
138
  getCancellationToken: () => token,
142
139
  // custom
143
140
  getDefaultLibFileName: options => {
144
141
  try {
145
- return ts.getDefaultLibFilePath(options);
142
+ return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
146
143
  }
147
144
  catch (_a) {
148
145
  // web
149
- return initOptions.typescript.tsdk + '/' + ts.getDefaultLibFileName(options);
146
+ return context.workspace.workspaces.initOptions.typescript.tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
150
147
  }
151
148
  },
152
149
  getProjectVersion: () => projectVersion.toString(),
@@ -155,24 +152,24 @@ function createProject(params) {
155
152
  getCompilationSettings: () => parsedCommandLine.options,
156
153
  getScriptVersion,
157
154
  getScriptSnapshot,
158
- getTypeScriptModule: () => ts,
155
+ getTypeScriptModule: () => context.workspace.workspaces.ts,
159
156
  };
160
- if (initOptions.noProjectReferences) {
157
+ if (context.workspace.workspaces.initOptions.noProjectReferences) {
161
158
  host.getProjectReferences = undefined;
162
159
  host.getCompilationSettings = () => (Object.assign(Object.assign({}, parsedCommandLine.options), { rootDir: undefined, composite: false }));
163
160
  }
164
- if (tsLocalized) {
165
- host.getLocalizedDiagnosticMessages = () => tsLocalized;
161
+ if (context.workspace.workspaces.tsLocalized) {
162
+ host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
166
163
  }
167
- for (const plugin of plugins) {
164
+ for (const plugin of context.workspace.workspaces.plugins) {
168
165
  if ((_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.resolveLanguageServiceHost) {
169
- host = plugin.semanticService.resolveLanguageServiceHost(ts, sys, tsConfig, host);
166
+ host = plugin.semanticService.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
170
167
  }
171
168
  }
172
169
  return host;
173
170
  function getScriptVersion(fileName) {
174
171
  var _a, _b;
175
- const doc = documents.data.pathGet(fileName);
172
+ const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
176
173
  if (doc) {
177
174
  return doc.version.toString();
178
175
  }
@@ -180,7 +177,7 @@ function createProject(params) {
180
177
  }
181
178
  function getScriptSnapshot(fileName) {
182
179
  var _a;
183
- const doc = documents.data.pathGet(fileName);
180
+ const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
184
181
  if (doc) {
185
182
  return doc.getSnapshot();
186
183
  }
@@ -189,16 +186,16 @@ function createProject(params) {
189
186
  return script.snapshot;
190
187
  }
191
188
  if (sys.fileExists(fileName)) {
192
- if (initOptions.maxFileSize) {
189
+ if (context.workspace.workspaces.initOptions.maxFileSize) {
193
190
  const fileSize = (_a = sys.getFileSize) === null || _a === void 0 ? void 0 : _a.call(sys, fileName);
194
- if (fileSize !== undefined && fileSize > initOptions.maxFileSize) {
195
- console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${initOptions.maxFileSize}bytes)`);
196
- return ts.ScriptSnapshot.fromString('');
191
+ if (fileSize !== undefined && fileSize > context.workspace.workspaces.initOptions.maxFileSize) {
192
+ console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspace.workspaces.initOptions.maxFileSize}bytes)`);
193
+ return context.workspace.workspaces.ts.ScriptSnapshot.fromString('');
197
194
  }
198
195
  }
199
196
  const text = sys.readFile(fileName, 'utf8');
200
197
  if (text !== undefined) {
201
- const snapshot = ts.ScriptSnapshot.fromString(text);
198
+ const snapshot = context.workspace.workspaces.ts.ScriptSnapshot.fromString(text);
202
199
  if (script) {
203
200
  script.snapshot = snapshot;
204
201
  script.snapshotVersion = script.version;
@@ -217,7 +214,7 @@ function createProject(params) {
217
214
  }
218
215
  }
219
216
  function dispose() {
220
- vueLs === null || vueLs === void 0 ? void 0 : vueLs.dispose();
217
+ languageService === null || languageService === void 0 ? void 0 : languageService.dispose();
221
218
  scripts.clear();
222
219
  disposeWatchEvent();
223
220
  disposeDocChange();
@@ -1,8 +1,8 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
2
  import { LanguageServerPlugin, RuntimeEnvironment } from '../types';
3
- export interface ServerParams {
3
+ export interface ServerContext {
4
4
  connection: vscode.Connection;
5
5
  runtimeEnv: RuntimeEnvironment;
6
6
  plugins: LanguageServerPlugin[];
7
7
  }
8
- export declare function createCommonLanguageServer(params: ServerParams): void;
8
+ export declare function createCommonLanguageServer(context: ServerContext): void;
@@ -18,8 +18,7 @@ const documents_1 = require("./documents");
18
18
  const syntaxServicesHost_1 = require("./syntaxServicesHost");
19
19
  const registerFeatures_1 = require("./utils/registerFeatures");
20
20
  const workspaces_1 = require("./workspaces");
21
- function createCommonLanguageServer(params) {
22
- const { connection, runtimeEnv, plugins: _plugins } = params;
21
+ function createCommonLanguageServer(context) {
23
22
  let initParams;
24
23
  let options;
25
24
  let roots = [];
@@ -28,12 +27,12 @@ function createCommonLanguageServer(params) {
28
27
  let documentServiceHost;
29
28
  let configurationHost;
30
29
  let plugins;
31
- const documents = (0, documents_1.createDocuments)(connection);
32
- connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
30
+ const documents = (0, documents_1.createDocuments)(context.connection);
31
+ context.connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
33
32
  var _a, _b, _c, _d;
34
33
  initParams = _params;
35
34
  options = initParams.initializationOptions;
36
- plugins = _plugins.map(plugin => plugin(options));
35
+ plugins = context.plugins.map(plugin => plugin(options));
37
36
  if (((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) && initParams.workspaceFolders) {
38
37
  roots = initParams.workspaceFolders.map(folder => vscode_uri_1.URI.parse(folder.uri));
39
38
  }
@@ -48,7 +47,7 @@ function createCommonLanguageServer(params) {
48
47
  textDocumentSync: (_b = options.textDocumentSync) !== null && _b !== void 0 ? _b : vscode.TextDocumentSyncKind.Incremental,
49
48
  },
50
49
  };
51
- configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
50
+ configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams, context.connection) : undefined;
52
51
  const serverMode = (_d = options.serverMode) !== null && _d !== void 0 ? _d : types_1.ServerMode.Semantic;
53
52
  (0, registerFeatures_1.setupSyntacticCapabilities)(initParams.capabilities, result.capabilities, options);
54
53
  yield _createDocumentServiceHost();
@@ -67,12 +66,12 @@ function createCommonLanguageServer(params) {
67
66
  catch (_e) { }
68
67
  return result;
69
68
  }));
70
- connection.onInitialized(() => {
69
+ context.connection.onInitialized(() => {
71
70
  var _a, _b, _c;
72
- fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(connection);
71
+ fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(context.connection);
73
72
  configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.ready();
74
73
  if ((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) {
75
- connection.workspace.onDidChangeWorkspaceFolders(e => {
74
+ context.connection.workspace.onDidChangeWorkspaceFolders(e => {
76
75
  for (const folder of e.added) {
77
76
  documentServiceHost === null || documentServiceHost === void 0 ? void 0 : documentServiceHost.add(vscode_uri_1.URI.parse(folder.uri));
78
77
  projects === null || projects === void 0 ? void 0 : projects.add(vscode_uri_1.URI.parse(folder.uri));
@@ -86,7 +85,7 @@ function createCommonLanguageServer(params) {
86
85
  if (options.serverMode !== types_1.ServerMode.Syntactic
87
86
  && !options.disableFileWatcher
88
87
  && ((_c = (_b = initParams.capabilities.workspace) === null || _b === void 0 ? void 0 : _b.didChangeWatchedFiles) === null || _c === void 0 ? void 0 : _c.dynamicRegistration)) {
89
- connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
88
+ context.connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
90
89
  watchers: [
91
90
  {
92
91
  globPattern: `**/*.{${[
@@ -106,30 +105,30 @@ function createCommonLanguageServer(params) {
106
105
  });
107
106
  }
108
107
  });
109
- connection.listen();
108
+ context.connection.listen();
110
109
  function _createDocumentServiceHost() {
111
110
  var _a, _b;
112
111
  return __awaiter(this, void 0, void 0, function* () {
113
- const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
114
- documentServiceHost = (0, syntaxServicesHost_1.createSyntaxServicesHost)(runtimeEnv, plugins, ts, configurationHost, options);
112
+ const ts = context.runtimeEnv.loadTypescript(options.typescript.tsdk);
113
+ documentServiceHost = (0, syntaxServicesHost_1.createSyntaxServicesHost)(context.runtimeEnv, plugins, ts, configurationHost, options);
115
114
  for (const root of roots) {
116
115
  documentServiceHost.add(root);
117
116
  }
118
- (yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(connection, documents, documentServiceHost);
117
+ (yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(context.connection, documents, documentServiceHost);
119
118
  for (const plugin of plugins) {
120
- (_b = (_a = plugin.syntacticService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, connection);
119
+ (_b = (_a = plugin.syntacticService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, context.connection);
121
120
  }
122
121
  });
123
122
  }
124
123
  function createLanguageServiceHost() {
125
124
  var _a, _b;
126
125
  return __awaiter(this, void 0, void 0, function* () {
127
- const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
128
- fsHost = runtimeEnv.createFileSystemHost(ts, initParams.capabilities);
129
- const tsLocalized = initParams.locale ? yield runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
126
+ const ts = context.runtimeEnv.loadTypescript(options.typescript.tsdk);
127
+ fsHost = context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities);
128
+ const tsLocalized = initParams.locale ? yield context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
130
129
  const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
131
130
  const _projects = (0, workspaces_1.createWorkspaces)({
132
- server: params,
131
+ server: context,
133
132
  fileSystemHost: fsHost,
134
133
  configurationHost,
135
134
  ts,
@@ -144,10 +143,10 @@ function createCommonLanguageServer(params) {
144
143
  for (const root of roots) {
145
144
  projects.add(root);
146
145
  }
147
- (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects);
148
- (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend());
146
+ (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(context.connection, projects);
147
+ (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend());
149
148
  for (const plugin of plugins) {
150
- (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, connection, getLanguageService);
149
+ (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, context.connection, getLanguageService);
151
150
  }
152
151
  function getLanguageService(uri) {
153
152
  var _a;
@@ -31,6 +31,7 @@ function createSyntaxServicesHost(runtimeEnv, plugins, ts, configHost, initOptio
31
31
  configurationHost: configHost,
32
32
  fileSystemProvider: runtimeEnv.fileSystemProvide,
33
33
  };
34
+ const serverConfig = (0, serverConfig_1.loadServerConfig)(rootUri.fsPath, initOptions.configFilePath);
34
35
  const serviceContext = embedded.createDocumentServiceContext({
35
36
  ts,
36
37
  env,
@@ -38,8 +39,9 @@ function createSyntaxServicesHost(runtimeEnv, plugins, ts, configHost, initOptio
38
39
  return plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.syntacticService) === null || _a === void 0 ? void 0 : _a.getLanguageModules) === null || _b === void 0 ? void 0 : _b.call(_a, ts, env)) !== null && _c !== void 0 ? _c : []; }).flat();
39
40
  },
40
41
  getPlugins() {
42
+ var _a;
41
43
  return [
42
- ...(0, serverConfig_1.loadCustomPlugins)(rootUri.fsPath, initOptions.configFilePath),
44
+ ...(_a = serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.plugins) !== null && _a !== void 0 ? _a : [],
43
45
  ...plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.syntacticService) === null || _a === void 0 ? void 0 : _a.getServicePlugins) === null || _b === void 0 ? void 0 : _b.call(_a, serviceContext)) !== null && _c !== void 0 ? _c : []; }).flat(),
44
46
  ];
45
47
  },
@@ -1,2 +1,5 @@
1
1
  import { LanguageServicePlugin } from '@volar/language-service';
2
- export declare function loadCustomPlugins(dir: string, configFile: string | undefined): LanguageServicePlugin[];
2
+ export interface ServerConfig {
3
+ plugins?: LanguageServicePlugin[];
4
+ }
5
+ export declare function loadServerConfig(dir: string, configFile: string | undefined): ServerConfig | undefined;
@@ -1,23 +1,21 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.loadCustomPlugins = void 0;
3
- function loadCustomPlugins(dir, configFile) {
4
- var _a;
2
+ exports.loadServerConfig = void 0;
3
+ function loadServerConfig(dir, configFile) {
5
4
  let configPath;
6
5
  try {
7
6
  configPath = require.resolve(configFile !== null && configFile !== void 0 ? configFile : './volar.config.js', { paths: [dir] });
8
7
  }
9
- catch (_b) { }
8
+ catch (_a) { }
10
9
  try {
11
10
  if (configPath) {
12
11
  const config = require(configPath);
13
12
  delete require.cache[configPath];
14
- return (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
13
+ return config;
15
14
  }
16
15
  }
17
16
  catch (err) {
18
17
  console.log(err);
19
18
  }
20
- return [];
21
19
  }
22
- exports.loadCustomPlugins = loadCustomPlugins;
20
+ exports.loadServerConfig = loadServerConfig;
23
21
  //# sourceMappingURL=serverConfig.js.map
@@ -2,17 +2,17 @@ import * as path from 'typesafe-path';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
3
  import * as vscode from 'vscode-languageserver';
4
4
  import { URI } from 'vscode-uri';
5
- import { WorkspacesParams } from './workspaces';
5
+ import { WorkspacesContext } from './workspaces';
6
6
  export declare const rootTsConfigNames: string[];
7
- export interface WorkspaceParams {
8
- workspaces: WorkspacesParams;
7
+ export interface WorkspaceContext {
8
+ workspaces: WorkspacesContext;
9
9
  rootUri: URI;
10
10
  }
11
- export declare function createWorkspace(params: WorkspaceParams): Promise<{
11
+ export declare function createWorkspace(context: WorkspaceContext): Promise<{
12
12
  projects: {
13
13
  clear: () => void;
14
14
  values: () => IterableIterator<Promise<{
15
- tsConfig: path.PosixPath | ts.CompilerOptions;
15
+ tsConfig: ts.CompilerOptions | path.PosixPath;
16
16
  scripts: {
17
17
  clear: () => void;
18
18
  values: () => IterableIterator<{
@@ -142,7 +142,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
142
142
  }>>;
143
143
  uriDelete: (_uri: string) => boolean;
144
144
  uriGet: (_uri: string) => Promise<{
145
- tsConfig: path.PosixPath | ts.CompilerOptions;
145
+ tsConfig: ts.CompilerOptions | path.PosixPath;
146
146
  scripts: {
147
147
  clear: () => void;
148
148
  values: () => IterableIterator<{
@@ -272,7 +272,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
272
272
  }> | undefined;
273
273
  uriHas: (_uri: string) => boolean;
274
274
  uriSet: (_uri: string, item: Promise<{
275
- tsConfig: path.PosixPath | ts.CompilerOptions;
275
+ tsConfig: ts.CompilerOptions | path.PosixPath;
276
276
  scripts: {
277
277
  clear: () => void;
278
278
  values: () => IterableIterator<{
@@ -402,7 +402,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
402
402
  }>) => void;
403
403
  pathDelete: (path: string) => boolean;
404
404
  pathGet: (path: string) => Promise<{
405
- tsConfig: path.PosixPath | ts.CompilerOptions;
405
+ tsConfig: ts.CompilerOptions | path.PosixPath;
406
406
  scripts: {
407
407
  clear: () => void;
408
408
  values: () => IterableIterator<{
@@ -531,7 +531,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
531
531
  dispose: () => void;
532
532
  }> | undefined;
533
533
  pathHas: (path: string) => Promise<{
534
- tsConfig: path.PosixPath | ts.CompilerOptions;
534
+ tsConfig: ts.CompilerOptions | path.PosixPath;
535
535
  scripts: {
536
536
  clear: () => void;
537
537
  values: () => IterableIterator<{
@@ -660,7 +660,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
660
660
  dispose: () => void;
661
661
  }> | undefined;
662
662
  pathSet: (path: string, item: Promise<{
663
- tsConfig: path.PosixPath | ts.CompilerOptions;
663
+ tsConfig: ts.CompilerOptions | path.PosixPath;
664
664
  scripts: {
665
665
  clear: () => void;
666
666
  values: () => IterableIterator<{
@@ -793,7 +793,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
793
793
  getProjectAndTsConfig: (uri: string) => Promise<{
794
794
  tsconfig: string;
795
795
  project: {
796
- tsConfig: path.PosixPath | ts.CompilerOptions;
796
+ tsConfig: ts.CompilerOptions | path.PosixPath;
797
797
  scripts: {
798
798
  clear: () => void;
799
799
  values: () => IterableIterator<{
@@ -923,7 +923,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
923
923
  };
924
924
  } | undefined>;
925
925
  getInferredProject: () => Promise<{
926
- tsConfig: path.PosixPath | ts.CompilerOptions;
926
+ tsConfig: ts.CompilerOptions | path.PosixPath;
927
927
  scripts: {
928
928
  clear: () => void;
929
929
  values: () => IterableIterator<{
@@ -1052,7 +1052,7 @@ export declare function createWorkspace(params: WorkspaceParams): Promise<{
1052
1052
  dispose: () => void;
1053
1053
  }>;
1054
1054
  getInferredProjectDontCreate: () => Promise<{
1055
- tsConfig: path.PosixPath | ts.CompilerOptions;
1055
+ tsConfig: ts.CompilerOptions | path.PosixPath;
1056
1056
  scripts: {
1057
1057
  clear: () => void;
1058
1058
  values: () => IterableIterator<{
@@ -18,22 +18,19 @@ const inferredCompilerOptions_1 = require("./utils/inferredCompilerOptions");
18
18
  const serverConfig_1 = require("./utils/serverConfig");
19
19
  const uriMap_1 = require("./utils/uriMap");
20
20
  exports.rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
21
- function createWorkspace(params) {
21
+ function createWorkspace(context) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
- const { rootUri } = params;
24
- const { ts, fileSystemHost, initOptions, configurationHost } = params.workspaces;
25
23
  let inferredProject;
26
- const workspacePlugins = (0, serverConfig_1.loadCustomPlugins)(shared.getPathOfUri(rootUri.toString()), initOptions.configFilePath);
27
- const sys = fileSystemHost.getWorkspaceFileSystem(rootUri);
28
- const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.getPathOfUri(rootUri.toString()));
24
+ const serverConfig = (0, serverConfig_1.loadServerConfig)(shared.getPathOfUri(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
25
+ const sys = context.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
26
+ const documentRegistry = context.workspaces.ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.getPathOfUri(context.rootUri.toString()));
29
27
  const projects = (0, uriMap_1.createUriMap)();
30
- const rootTsConfigs = new Set(sys.readDirectory(shared.getPathOfUri(rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
31
- const disposeWatch = fileSystemHost.onDidChangeWatchedFiles((params) => __awaiter(this, void 0, void 0, function* () {
32
- const disposes = [];
33
- for (const change of params.changes) {
28
+ const rootTsConfigs = new Set(sys.readDirectory(shared.getPathOfUri(context.rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
29
+ const disposeTsConfigWatch = context.workspaces.fileSystemHost.onDidChangeWatchedFiles(({ changes }) => {
30
+ for (const change of changes) {
34
31
  if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
35
32
  if (change.type === vscode.FileChangeType.Created) {
36
- if (shared.isFileInDir(shared.getPathOfUri(change.uri), shared.getPathOfUri(rootUri.toString()))) {
33
+ if (shared.isFileInDir(shared.getPathOfUri(change.uri), shared.getPathOfUri(context.rootUri.toString()))) {
37
34
  rootTsConfigs.add(shared.getPathOfUri(change.uri));
38
35
  }
39
36
  }
@@ -41,17 +38,13 @@ function createWorkspace(params) {
41
38
  if (change.type === vscode.FileChangeType.Deleted) {
42
39
  rootTsConfigs.delete(shared.getPathOfUri(change.uri));
43
40
  }
44
- const _project = projects.uriGet(change.uri);
41
+ const project = projects.uriGet(change.uri);
45
42
  projects.uriDelete(change.uri);
46
- disposes.push((() => __awaiter(this, void 0, void 0, function* () {
47
- var _a;
48
- (_a = (yield _project)) === null || _a === void 0 ? void 0 : _a.dispose();
49
- }))());
43
+ project === null || project === void 0 ? void 0 : project.then(project => project.dispose());
50
44
  }
51
45
  }
52
46
  }
53
- return Promise.all(disposes);
54
- }));
47
+ });
55
48
  return {
56
49
  projects,
57
50
  documentRegistry,
@@ -61,7 +54,7 @@ function createWorkspace(params) {
61
54
  reload: clearProjects,
62
55
  dispose() {
63
56
  clearProjects();
64
- disposeWatch();
57
+ disposeTsConfigWatch();
65
58
  },
66
59
  };
67
60
  function clearProjects() {
@@ -91,13 +84,13 @@ function createWorkspace(params) {
91
84
  function getInferredProject() {
92
85
  if (!inferredProject) {
93
86
  inferredProject = (() => __awaiter(this, void 0, void 0, function* () {
94
- const inferOptions = yield (0, inferredCompilerOptions_1.getInferredCompilerOptions)(ts, configurationHost);
87
+ const inferOptions = yield (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context.workspaces.ts, context.workspaces.configurationHost);
95
88
  return (0, project_1.createProject)({
96
- workspace: params,
97
- workspacePlugins,
98
- rootUri,
89
+ workspace: context,
90
+ rootUri: context.rootUri,
99
91
  tsConfig: inferOptions,
100
92
  documentRegistry,
93
+ serverConfig,
101
94
  });
102
95
  }))();
103
96
  }
@@ -148,7 +141,7 @@ function createWorkspace(params) {
148
141
  const project = yield projects.pathGet(rootTsConfig);
149
142
  if (project) {
150
143
  let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
151
- if (initOptions.reverseConfigFilePriority) {
144
+ if (context.workspaces.initOptions.reverseConfigFilePriority) {
152
145
  chains = chains.reverse();
153
146
  }
154
147
  for (const chain of chains) {
@@ -215,8 +208,8 @@ function createWorkspace(params) {
215
208
  let project = projects.pathGet(tsConfig);
216
209
  if (!project) {
217
210
  project = (0, project_1.createProject)({
218
- workspace: params,
219
- workspacePlugins,
211
+ workspace: context,
212
+ serverConfig,
220
213
  rootUri: vscode_uri_1.URI.parse(shared.getUriByPath(path.dirname(tsConfig))),
221
214
  tsConfig,
222
215
  documentRegistry,
@@ -1,3 +1,4 @@
1
+ /// <reference types="typesafe-path" />
1
2
  import { ConfigurationHost } from '@volar/language-service';
2
3
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
4
  import * as vscode from 'vscode-languageserver';
@@ -5,9 +6,9 @@ import { URI } from 'vscode-uri';
5
6
  import { FileSystemHost, LanguageServerInitializationOptions, LanguageServerPlugin } from '../types';
6
7
  import { CancellationTokenHost } from './cancellationPipe';
7
8
  import { createDocuments } from './documents';
8
- import { ServerParams } from './server';
9
- export interface WorkspacesParams {
10
- server: ServerParams;
9
+ import { ServerContext } from './server';
10
+ export interface WorkspacesContext {
11
+ server: ServerContext;
11
12
  initParams: vscode.InitializeParams;
12
13
  initOptions: LanguageServerInitializationOptions;
13
14
  plugins: ReturnType<LanguageServerPlugin>[];
@@ -20,12 +21,12 @@ export interface WorkspacesParams {
20
21
  }
21
22
  export interface Workspaces extends ReturnType<typeof createWorkspaces> {
22
23
  }
23
- export declare function createWorkspaces(params: WorkspacesParams): {
24
+ export declare function createWorkspaces(context: WorkspacesContext): {
24
25
  workspaces: Map<string, Promise<{
25
26
  projects: {
26
27
  clear: () => void;
27
28
  values: () => IterableIterator<Promise<{
28
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
29
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
29
30
  scripts: {
30
31
  clear: () => void;
31
32
  values: () => IterableIterator<{
@@ -155,7 +156,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
155
156
  }>>;
156
157
  uriDelete: (_uri: string) => boolean;
157
158
  uriGet: (_uri: string) => Promise<{
158
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
159
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
159
160
  scripts: {
160
161
  clear: () => void;
161
162
  values: () => IterableIterator<{
@@ -285,7 +286,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
285
286
  }> | undefined;
286
287
  uriHas: (_uri: string) => boolean;
287
288
  uriSet: (_uri: string, item: Promise<{
288
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
289
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
289
290
  scripts: {
290
291
  clear: () => void;
291
292
  values: () => IterableIterator<{
@@ -415,7 +416,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
415
416
  }>) => void;
416
417
  pathDelete: (path: string) => boolean;
417
418
  pathGet: (path: string) => Promise<{
418
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
419
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
419
420
  scripts: {
420
421
  clear: () => void;
421
422
  values: () => IterableIterator<{
@@ -544,7 +545,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
544
545
  dispose: () => void;
545
546
  }> | undefined;
546
547
  pathHas: (path: string) => Promise<{
547
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
548
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
548
549
  scripts: {
549
550
  clear: () => void;
550
551
  values: () => IterableIterator<{
@@ -673,7 +674,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
673
674
  dispose: () => void;
674
675
  }> | undefined;
675
676
  pathSet: (path: string, item: Promise<{
676
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
677
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
677
678
  scripts: {
678
679
  clear: () => void;
679
680
  values: () => IterableIterator<{
@@ -806,7 +807,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
806
807
  getProjectAndTsConfig: (uri: string) => Promise<{
807
808
  tsconfig: string;
808
809
  project: {
809
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
810
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
810
811
  scripts: {
811
812
  clear: () => void;
812
813
  values: () => IterableIterator<{
@@ -936,7 +937,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
936
937
  };
937
938
  } | undefined>;
938
939
  getInferredProject: () => Promise<{
939
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
940
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
940
941
  scripts: {
941
942
  clear: () => void;
942
943
  values: () => IterableIterator<{
@@ -1065,7 +1066,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
1065
1066
  dispose: () => void;
1066
1067
  }>;
1067
1068
  getInferredProjectDontCreate: () => Promise<{
1068
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
1069
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1069
1070
  scripts: {
1070
1071
  clear: () => void;
1071
1072
  values: () => IterableIterator<{
@@ -1199,7 +1200,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
1199
1200
  getProject: (uri: string) => Promise<{
1200
1201
  tsconfig: string;
1201
1202
  project: {
1202
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
1203
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1203
1204
  scripts: {
1204
1205
  clear: () => void;
1205
1206
  values: () => IterableIterator<{
@@ -1330,7 +1331,7 @@ export declare function createWorkspaces(params: WorkspacesParams): {
1330
1331
  } | {
1331
1332
  tsconfig: undefined;
1332
1333
  project: {
1333
- tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
1334
+ tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1334
1335
  scripts: {
1335
1336
  clear: () => void;
1336
1337
  values: () => IterableIterator<{
@@ -13,39 +13,37 @@ const shared = require("@volar/shared");
13
13
  const vscode = require("vscode-languageserver");
14
14
  const types_1 = require("../types");
15
15
  const workspace_1 = require("./workspace");
16
- function createWorkspaces(params) {
17
- var _a;
18
- const { fileSystemHost, configurationHost, initParams, initOptions, documents, cancelTokenHost } = params;
19
- const { connection, runtimeEnv } = params.server;
16
+ function createWorkspaces(context) {
17
+ var _a, _b;
18
+ const workspaces = new Map();
20
19
  let semanticTokensReq = 0;
21
20
  let documentUpdatedReq = 0;
22
- const workspaces = new Map();
23
- documents.onDidChangeContent(params => {
24
- updateDiagnostics(params.textDocument.uri);
21
+ context.documents.onDidChangeContent(({ textDocument }) => {
22
+ updateDiagnostics(textDocument.uri);
25
23
  });
26
- documents.onDidClose(params => {
27
- connection.sendDiagnostics({ uri: params.textDocument.uri, diagnostics: [] });
24
+ context.documents.onDidClose(({ textDocument }) => {
25
+ context.server.connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
28
26
  });
29
- fileSystemHost.onDidChangeWatchedFiles(params => {
30
- const tsConfigChanges = params.changes.filter(change => workspace_1.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
27
+ context.fileSystemHost.onDidChangeWatchedFiles(({ changes }) => {
28
+ const tsConfigChanges = changes.filter(change => workspace_1.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
31
29
  if (tsConfigChanges.length) {
32
30
  reloadDiagnostics();
33
31
  }
34
32
  else {
35
- onDriveFileUpdated();
33
+ updateDiagnosticsAndSemanticTokens();
36
34
  }
37
35
  });
38
- (_a = runtimeEnv.onDidChangeConfiguration) === null || _a === void 0 ? void 0 : _a.call(runtimeEnv, () => __awaiter(this, void 0, void 0, function* () {
39
- onDriveFileUpdated();
36
+ (_b = (_a = context.server.runtimeEnv).onDidChangeConfiguration) === null || _b === void 0 ? void 0 : _b.call(_a, () => __awaiter(this, void 0, void 0, function* () {
37
+ updateDiagnosticsAndSemanticTokens();
40
38
  }));
41
39
  return {
42
40
  workspaces,
43
- getProject,
41
+ getProject: getProjectAndTsConfig,
44
42
  reloadProject,
45
43
  add: (rootUri) => {
46
44
  if (!workspaces.has(rootUri.toString())) {
47
45
  workspaces.set(rootUri.toString(), (0, workspace_1.createWorkspace)({
48
- workspaces: params,
46
+ workspaces: context,
49
47
  rootUri,
50
48
  }));
51
49
  }
@@ -61,7 +59,7 @@ function createWorkspaces(params) {
61
59
  };
62
60
  function reloadProject() {
63
61
  return __awaiter(this, void 0, void 0, function* () {
64
- fileSystemHost.reload();
62
+ context.fileSystemHost.reload();
65
63
  for (const [_, workspace] of workspaces) {
66
64
  (yield workspace).reload();
67
65
  }
@@ -69,79 +67,82 @@ function createWorkspaces(params) {
69
67
  });
70
68
  }
71
69
  function reloadDiagnostics() {
72
- for (const doc of documents.data.values()) {
73
- connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
70
+ for (const doc of context.documents.data.values()) {
71
+ context.server.connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
74
72
  }
75
- onDriveFileUpdated();
73
+ updateDiagnosticsAndSemanticTokens();
76
74
  }
77
- function onDriveFileUpdated() {
78
- var _a, _b;
75
+ function updateDiagnosticsAndSemanticTokens() {
76
+ var _a, _b, _c, _d;
79
77
  return __awaiter(this, void 0, void 0, function* () {
80
78
  const req = ++semanticTokensReq;
81
79
  yield updateDiagnostics();
80
+ const delay = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.diagnostics.delay'))) !== null && _b !== void 0 ? _b : 200;
81
+ yield shared.sleep(delay);
82
82
  if (req === semanticTokensReq) {
83
- if ((_a = initParams.capabilities.textDocument) === null || _a === void 0 ? void 0 : _a.semanticTokens) {
84
- connection.languages.semanticTokens.refresh();
83
+ if ((_c = context.initParams.capabilities.textDocument) === null || _c === void 0 ? void 0 : _c.semanticTokens) {
84
+ context.server.connection.languages.semanticTokens.refresh();
85
85
  }
86
- if ((_b = initParams.capabilities.textDocument) === null || _b === void 0 ? void 0 : _b.inlayHint) {
87
- connection.languages.inlayHint.refresh();
86
+ if ((_d = context.initParams.capabilities.textDocument) === null || _d === void 0 ? void 0 : _d.inlayHint) {
87
+ context.server.connection.languages.inlayHint.refresh();
88
88
  }
89
89
  }
90
90
  });
91
91
  }
92
92
  function updateDiagnostics(docUri) {
93
- var _a, _b;
93
+ var _a, _b, _c;
94
94
  return __awaiter(this, void 0, void 0, function* () {
95
- if (((_a = initOptions.diagnosticModel) !== null && _a !== void 0 ? _a : types_1.DiagnosticModel.Push) !== types_1.DiagnosticModel.Push)
95
+ if (((_a = context.initOptions.diagnosticModel) !== null && _a !== void 0 ? _a : types_1.DiagnosticModel.Push) !== types_1.DiagnosticModel.Push)
96
96
  return;
97
97
  const req = ++documentUpdatedReq;
98
- const delay = (_b = yield (configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.getConfiguration('volar.diagnostics.delay'))) !== null && _b !== void 0 ? _b : 200;
99
- const cancel = cancelTokenHost.createCancellationToken({
98
+ const delay = (_c = yield ((_b = context.configurationHost) === null || _b === void 0 ? void 0 : _b.getConfiguration('volar.diagnostics.delay'))) !== null && _c !== void 0 ? _c : 200;
99
+ const cancel = context.cancelTokenHost.createCancellationToken({
100
100
  get isCancellationRequested() {
101
101
  return req !== documentUpdatedReq;
102
102
  },
103
103
  onCancellationRequested: vscode.Event.None,
104
104
  });
105
- const changeDoc = docUri ? documents.data.uriGet(docUri) : undefined;
106
- const otherDocs = [...documents.data.values()].filter(doc => doc !== changeDoc);
105
+ const changeDoc = docUri ? context.documents.data.uriGet(docUri) : undefined;
106
+ const otherDocs = [...context.documents.data.values()].filter(doc => doc !== changeDoc);
107
107
  if (changeDoc) {
108
108
  yield shared.sleep(delay);
109
+ if (cancel.isCancellationRequested) {
110
+ return;
111
+ }
109
112
  yield sendDocumentDiagnostics(changeDoc.uri, changeDoc.version, cancel);
110
113
  }
111
114
  for (const doc of otherDocs) {
112
115
  yield shared.sleep(delay);
113
- yield sendDocumentDiagnostics(doc.uri, doc.version, cancel);
114
116
  if (cancel.isCancellationRequested) {
115
117
  break;
116
118
  }
119
+ yield sendDocumentDiagnostics(doc.uri, doc.version, cancel);
117
120
  }
118
- function sendDocumentDiagnostics(uri, version, cancel) {
119
- var _a;
120
- return __awaiter(this, void 0, void 0, function* () {
121
- if (cancel.isCancellationRequested)
122
- return;
123
- const project = (_a = (yield getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
124
- if (!project)
125
- return;
126
- const languageService = project.getLanguageService();
127
- const errors = yield languageService.doValidation(uri, cancel, result => {
128
- connection.sendDiagnostics({ uri: uri, diagnostics: result.map(addVersion), version });
129
- });
130
- connection.sendDiagnostics({ uri: uri, diagnostics: errors.map(addVersion), version });
131
- function addVersion(error) {
132
- if (error.data === undefined) {
133
- error.data = { version };
134
- }
135
- else if (typeof error.data === 'object') {
136
- error.data.version = version;
137
- }
138
- return error;
139
- }
140
- });
121
+ });
122
+ }
123
+ function sendDocumentDiagnostics(uri, version, cancel) {
124
+ var _a;
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const project = (_a = (yield getProjectAndTsConfig(uri))) === null || _a === void 0 ? void 0 : _a.project;
127
+ if (!project)
128
+ return;
129
+ const languageService = project.getLanguageService();
130
+ const errors = yield languageService.doValidation(uri, cancel, result => {
131
+ context.server.connection.sendDiagnostics({ uri: uri, diagnostics: result.map(addVersion), version });
132
+ });
133
+ context.server.connection.sendDiagnostics({ uri: uri, diagnostics: errors.map(addVersion), version });
134
+ function addVersion(error) {
135
+ if (error.data === undefined) {
136
+ error.data = { version };
137
+ }
138
+ else if (typeof error.data === 'object') {
139
+ error.data.version = version;
140
+ }
141
+ return error;
141
142
  }
142
143
  });
143
144
  }
144
- function getProject(uri) {
145
+ function getProjectAndTsConfig(uri) {
145
146
  var _a;
146
147
  return __awaiter(this, void 0, void 0, function* () {
147
148
  const rootUris = [...workspaces.keys()]
@@ -149,9 +150,9 @@ function createWorkspaces(params) {
149
150
  .sort((a, b) => (0, workspace_1.sortTsConfigs)(shared.getPathOfUri(uri), shared.getPathOfUri(a), shared.getPathOfUri(b)));
150
151
  for (const rootUri of rootUris) {
151
152
  const workspace = yield workspaces.get(rootUri);
152
- const project = yield (workspace === null || workspace === void 0 ? void 0 : workspace.getProjectAndTsConfig(uri));
153
- if (project) {
154
- return project;
153
+ const projectAndTsConfig = yield (workspace === null || workspace === void 0 ? void 0 : workspace.getProjectAndTsConfig(uri));
154
+ if (projectAndTsConfig) {
155
+ return projectAndTsConfig;
155
156
  }
156
157
  }
157
158
  if (rootUris.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,9 +17,9 @@
17
17
  "directory": "packages/language-server"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "1.0.18",
21
- "@volar/language-service": "1.0.18",
22
- "@volar/shared": "1.0.18",
20
+ "@volar/language-core": "1.0.19",
21
+ "@volar/language-service": "1.0.19",
22
+ "@volar/shared": "1.0.19",
23
23
  "request-light": "^0.6.0",
24
24
  "typesafe-path": "^0.2.2",
25
25
  "vscode-html-languageservice": "^5.0.3",
@@ -28,5 +28,5 @@
28
28
  "vscode-languageserver-textdocument": "^1.0.8",
29
29
  "vscode-uri": "^3.0.7"
30
30
  },
31
- "gitHead": "f102ee7bfc96792c63746a5dcb9742e3346d5cc7"
31
+ "gitHead": "02267fe83a5567b1cae7025e834cf084c8248546"
32
32
  }