@volar/language-server 1.0.17 → 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,17 +3,17 @@ 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<{
16
+ export declare function createProject(context: ProjectContext): Promise<{
17
17
  tsConfig: ts.CompilerOptions | path.PosixPath;
18
18
  scripts: {
19
19
  clear: () => void;
@@ -15,77 +15,76 @@ 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++;
46
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
50
47
  }
51
48
  },
52
49
  dispose,
53
50
  };
54
51
  function getLanguageService() {
55
- if (!vueLs) {
56
- 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();
57
54
  const languageContext = embedded.createLanguageContext(languageServiceHost, languageModules);
58
55
  const languageServiceContext = embeddedLS.createLanguageServiceContext({
59
56
  host: languageServiceHost,
60
57
  context: languageContext,
61
58
  getPlugins() {
59
+ var _a, _b;
62
60
  return [
63
- ...params.workspacePlugins,
64
- ...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(),
65
63
  ];
66
64
  },
67
65
  env: {
68
- rootUri,
69
- configurationHost: configurationHost,
70
- fileSystemProvider: runtimeEnv.fileSystemProvide,
71
- 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),
72
70
  schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
73
71
  const protocol = uri.substring(0, uri.indexOf(':'));
74
- const builtInHandler = runtimeEnv.schemaRequestHandlers[protocol];
72
+ const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
75
73
  if (builtInHandler) {
76
74
  return yield builtInHandler(uri);
77
75
  }
78
76
  return '';
79
77
  }),
80
78
  },
81
- documentRegistry,
79
+ documentRegistry: context.documentRegistry,
82
80
  });
83
- vueLs = embeddedLS.createLanguageService(languageServiceContext);
81
+ languageService = embeddedLS.createLanguageService(languageServiceContext);
84
82
  }
85
- return vueLs;
83
+ return languageService;
86
84
  }
87
85
  function onWorkspaceFilesChanged(changes) {
88
86
  return __awaiter(this, void 0, void 0, function* () {
87
+ const _projectVersion = projectVersion;
89
88
  for (const change of changes) {
90
89
  const script = scripts.uriGet(change.uri);
91
90
  if (script && (change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Created)) {
@@ -106,17 +105,20 @@ function createProject(params) {
106
105
  const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
107
106
  const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
108
107
  if (creates.length || deletes.length) {
109
- 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);
110
109
  projectVersion++;
111
110
  typeRootVersion++;
112
111
  }
112
+ if (_projectVersion !== projectVersion) {
113
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
114
+ }
113
115
  });
114
116
  }
115
117
  function createLanguageServiceHost() {
116
118
  var _a;
117
119
  const token = {
118
120
  isCancellationRequested() {
119
- return cancelTokenHost.getMtime() !== projectVersionUpdateTime;
121
+ return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
120
122
  },
121
123
  throwIfCancellationRequested() { },
122
124
  };
@@ -131,17 +133,17 @@ function createProject(params) {
131
133
  readDirectory: sys.readDirectory,
132
134
  realpath: sys.realpath,
133
135
  fileExists: sys.fileExists,
134
- getCurrentDirectory: () => shared.getPathOfUri(rootUri.toString()),
136
+ getCurrentDirectory: () => shared.getPathOfUri(context.rootUri.toString()),
135
137
  getProjectReferences: () => parsedCommandLine.projectReferences,
136
138
  getCancellationToken: () => token,
137
139
  // custom
138
140
  getDefaultLibFileName: options => {
139
141
  try {
140
- return ts.getDefaultLibFilePath(options);
142
+ return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
141
143
  }
142
144
  catch (_a) {
143
145
  // web
144
- return initOptions.typescript.tsdk + '/' + ts.getDefaultLibFileName(options);
146
+ return context.workspace.workspaces.initOptions.typescript.tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
145
147
  }
146
148
  },
147
149
  getProjectVersion: () => projectVersion.toString(),
@@ -150,24 +152,24 @@ function createProject(params) {
150
152
  getCompilationSettings: () => parsedCommandLine.options,
151
153
  getScriptVersion,
152
154
  getScriptSnapshot,
153
- getTypeScriptModule: () => ts,
155
+ getTypeScriptModule: () => context.workspace.workspaces.ts,
154
156
  };
155
- if (initOptions.noProjectReferences) {
157
+ if (context.workspace.workspaces.initOptions.noProjectReferences) {
156
158
  host.getProjectReferences = undefined;
157
159
  host.getCompilationSettings = () => (Object.assign(Object.assign({}, parsedCommandLine.options), { rootDir: undefined, composite: false }));
158
160
  }
159
- if (tsLocalized) {
160
- host.getLocalizedDiagnosticMessages = () => tsLocalized;
161
+ if (context.workspace.workspaces.tsLocalized) {
162
+ host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
161
163
  }
162
- for (const plugin of plugins) {
164
+ for (const plugin of context.workspace.workspaces.plugins) {
163
165
  if ((_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.resolveLanguageServiceHost) {
164
- host = plugin.semanticService.resolveLanguageServiceHost(ts, sys, tsConfig, host);
166
+ host = plugin.semanticService.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
165
167
  }
166
168
  }
167
169
  return host;
168
170
  function getScriptVersion(fileName) {
169
171
  var _a, _b;
170
- const doc = documents.data.pathGet(fileName);
172
+ const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
171
173
  if (doc) {
172
174
  return doc.version.toString();
173
175
  }
@@ -175,7 +177,7 @@ function createProject(params) {
175
177
  }
176
178
  function getScriptSnapshot(fileName) {
177
179
  var _a;
178
- const doc = documents.data.pathGet(fileName);
180
+ const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
179
181
  if (doc) {
180
182
  return doc.getSnapshot();
181
183
  }
@@ -184,16 +186,16 @@ function createProject(params) {
184
186
  return script.snapshot;
185
187
  }
186
188
  if (sys.fileExists(fileName)) {
187
- if (initOptions.maxFileSize) {
189
+ if (context.workspace.workspaces.initOptions.maxFileSize) {
188
190
  const fileSize = (_a = sys.getFileSize) === null || _a === void 0 ? void 0 : _a.call(sys, fileName);
189
- if (fileSize !== undefined && fileSize > initOptions.maxFileSize) {
190
- console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${initOptions.maxFileSize}bytes)`);
191
- 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('');
192
194
  }
193
195
  }
194
196
  const text = sys.readFile(fileName, 'utf8');
195
197
  if (text !== undefined) {
196
- const snapshot = ts.ScriptSnapshot.fromString(text);
198
+ const snapshot = context.workspace.workspaces.ts.ScriptSnapshot.fromString(text);
197
199
  if (script) {
198
200
  script.snapshot = snapshot;
199
201
  script.snapshotVersion = script.version;
@@ -212,7 +214,7 @@ function createProject(params) {
212
214
  }
213
215
  }
214
216
  function dispose() {
215
- vueLs === null || vueLs === void 0 ? void 0 : vueLs.dispose();
217
+ languageService === null || languageService === void 0 ? void 0 : languageService.dispose();
216
218
  scripts.clear();
217
219
  disposeWatchEvent();
218
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,9 +85,8 @@ 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
- ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ globPattern: `**/*.${ext.extension}` }))).flat(),
92
90
  {
93
91
  globPattern: `**/*.{${[
94
92
  'js',
@@ -107,30 +105,30 @@ function createCommonLanguageServer(params) {
107
105
  });
108
106
  }
109
107
  });
110
- connection.listen();
108
+ context.connection.listen();
111
109
  function _createDocumentServiceHost() {
112
110
  var _a, _b;
113
111
  return __awaiter(this, void 0, void 0, function* () {
114
- const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
115
- 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);
116
114
  for (const root of roots) {
117
115
  documentServiceHost.add(root);
118
116
  }
119
- (yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(connection, documents, documentServiceHost);
117
+ (yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(context.connection, documents, documentServiceHost);
120
118
  for (const plugin of plugins) {
121
- (_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);
122
120
  }
123
121
  });
124
122
  }
125
123
  function createLanguageServiceHost() {
126
124
  var _a, _b;
127
125
  return __awaiter(this, void 0, void 0, function* () {
128
- const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
129
- fsHost = runtimeEnv.createFileSystemHost(ts, initParams.capabilities);
130
- 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;
131
129
  const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
132
130
  const _projects = (0, workspaces_1.createWorkspaces)({
133
- server: params,
131
+ server: context,
134
132
  fileSystemHost: fsHost,
135
133
  configurationHost,
136
134
  ts,
@@ -145,10 +143,10 @@ function createCommonLanguageServer(params) {
145
143
  for (const root of roots) {
146
144
  projects.add(root);
147
145
  }
148
- (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects);
149
- (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());
150
148
  for (const plugin of plugins) {
151
- (_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);
152
150
  }
153
151
  function getLanguageService(uri) {
154
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,13 +2,13 @@ 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<{
@@ -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,7 +21,7 @@ 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;
@@ -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.17",
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.17",
21
- "@volar/language-service": "1.0.17",
22
- "@volar/shared": "1.0.17",
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": "b66b64f579b5cafee9b8d70aa9f9303f39b6df49"
31
+ "gitHead": "02267fe83a5567b1cae7025e834cf084c8248546"
32
32
  }