@volar/language-server 1.6.9 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +1,87 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createProject = void 0;
4
- const embeddedLS = require("@volar/language-service");
5
- const path = require("typesafe-path");
4
+ const language_service_1 = require("@volar/language-service");
5
+ const path = require("typesafe-path/posix");
6
6
  const vscode = require("vscode-languageserver");
7
- const vscode_uri_1 = require("vscode-uri");
8
- const types_1 = require("../types");
9
7
  const serverConfig_1 = require("./utils/serverConfig");
10
8
  const uriMap_1 = require("./utils/uriMap");
9
+ const typescript_1 = require("@volar/typescript");
11
10
  async function createProject(context) {
12
- const uriToFileName = context.server.runtimeEnv.uriToFileName;
13
- const fileNameToUri = context.server.runtimeEnv.fileNameToUri;
14
- const sys = context.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspaces.fileSystemHost
15
- ? {
16
- args: [],
17
- newLine: '\n',
18
- useCaseSensitiveFileNames: false,
19
- fileExists: () => false,
20
- readFile: () => undefined,
21
- readDirectory: () => [],
22
- getCurrentDirectory: () => '',
23
- resolvePath: () => '',
24
- write: () => { },
25
- writeFile: () => { },
26
- createDirectory: () => { },
27
- realpath: path => path,
28
- directoryExists: () => true,
29
- exit: () => { },
30
- getDirectories: () => [],
31
- getExecutingFilePath: () => '/__fake__.js',
32
- }
33
- : context.workspaces.fileSystemHost.getWorkspaceFileSystem(context.project.rootUri);
34
- let typeRootVersion = 0;
35
11
  let projectVersion = 0;
36
12
  let projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
37
13
  let languageService;
38
- let parsedCommandLine = createParsedCommandLine(context.workspaces.ts, sys, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins);
39
- const scripts = (0, uriMap_1.createUriMap)(fileNameToUri);
40
- const languageServiceHost = createLanguageServiceHost();
41
- const disposeWatchEvent = context.workspaces.fileSystemHost?.onDidChangeWatchedFiles(params => {
42
- onWorkspaceFilesChanged(params.changes);
43
- });
44
- const disposeDocChange = context.workspaces.documents.onDidChangeContent(() => {
14
+ const { uriToFileName, fileNameToUri, fs } = context.server.runtimeEnv;
15
+ const env = {
16
+ uriToFileName,
17
+ fileNameToUri,
18
+ fs,
19
+ locale: context.workspaces.initParams.locale,
20
+ rootUri: context.project.rootUri,
21
+ clientCapabilities: context.workspaces.initParams.capabilities,
22
+ getConfiguration: context.server.configurationHost?.getConfiguration,
23
+ onDidChangeConfiguration: context.server.configurationHost?.onDidChangeConfiguration,
24
+ onDidChangeWatchedFiles: context.server.onDidChangeWatchedFiles,
25
+ };
26
+ const fsScriptsCache = (0, uriMap_1.createUriMap)(fileNameToUri);
27
+ const askedFiles = (0, uriMap_1.createUriMap)(fileNameToUri);
28
+ const token = {
29
+ isCancellationRequested() {
30
+ return context.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
31
+ },
32
+ throwIfCancellationRequested() { },
33
+ };
34
+ const languageHost = {
35
+ getProjectVersion: () => projectVersion,
36
+ getScriptFileNames: () => parsedCommandLine.fileNames,
37
+ getScriptSnapshot: (fileName) => {
38
+ askedFiles.pathSet(fileName, true);
39
+ const doc = context.workspaces.documents.data.pathGet(fileName);
40
+ if (doc) {
41
+ return doc.getSnapshot();
42
+ }
43
+ const fsSnapshot = fsScriptsCache.pathGet(fileName);
44
+ if (fsSnapshot) {
45
+ return fsSnapshot;
46
+ }
47
+ },
48
+ getLanguageId: (fileName) => context.workspaces.documents.data.pathGet(fileName)?.languageId,
49
+ getCancellationToken: () => token,
50
+ getCompilationSettings: () => parsedCommandLine.options,
51
+ getLocalizedDiagnosticMessages: context.workspaces.tsLocalized ? () => context.workspaces.tsLocalized : undefined,
52
+ getCurrentDirectory: () => uriToFileName(context.project.rootUri.toString()),
53
+ getProjectReferences: () => parsedCommandLine.projectReferences,
54
+ };
55
+ const docChangeWatcher = context.workspaces.documents.onDidChangeContent(() => {
45
56
  projectVersion++;
46
57
  projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
47
58
  });
59
+ const fileWatch = env.onDidChangeWatchedFiles?.(params => {
60
+ onWorkspaceFilesChanged(params.changes);
61
+ });
62
+ let existingOptions;
63
+ for (const plugin of context.workspaces.plugins) {
64
+ if (plugin.resolveExistingOptions) {
65
+ existingOptions = plugin.resolveExistingOptions(existingOptions);
66
+ }
67
+ }
68
+ let parsedCommandLine = await createParsedCommandLine(context.workspaces.ts, env, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins, existingOptions);
69
+ let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.server.runtimeEnv.uriToFileName(context.workspace.rootUri.toString()), context.workspaces.initOptions.configFilePath) : {}) ?? {};
70
+ for (const plugin of context.workspaces.plugins) {
71
+ if (plugin.resolveConfig) {
72
+ config = await plugin.resolveConfig(config, {
73
+ ...context,
74
+ env,
75
+ host: languageHost,
76
+ });
77
+ }
78
+ }
79
+ await syncRootScriptSnapshots();
48
80
  return {
81
+ context,
49
82
  tsConfig: context.project.tsConfig,
50
- scripts,
51
- languageServiceHost,
83
+ scripts: fsScriptsCache,
84
+ languageHost,
52
85
  getLanguageService,
53
86
  getLanguageServiceDontCreate: () => languageService,
54
87
  getParsedCommandLine: () => parsedCommandLine,
@@ -59,199 +92,101 @@ async function createProject(context) {
59
92
  projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
60
93
  }
61
94
  },
95
+ askedFiles,
62
96
  dispose,
63
97
  };
64
98
  function getLanguageService() {
65
99
  if (!languageService) {
66
- const env = {
67
- uriToFileName,
68
- fileNameToUri,
69
- locale: context.workspaces.initParams.locale,
70
- rootUri: context.project.rootUri,
71
- clientCapabilities: context.workspaces.initParams.capabilities,
72
- getConfiguration: context.workspaces.configurationHost?.getConfiguration,
73
- onDidChangeConfiguration: context.workspaces.configurationHost?.onDidChangeConfiguration,
74
- fileSystemProvider: context.server.runtimeEnv.fileSystemProvide,
75
- onDidChangeWatchedFiles: context.workspaces.fileSystemHost?.onDidChangeWatchedFiles,
76
- documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspaces.ts, languageServiceHost, context.project.rootUri.toString()),
77
- schemaRequestService: async (uri) => {
78
- const protocol = uri.substring(0, uri.indexOf(':'));
79
- const builtInHandler = context.server.runtimeEnv.schemaRequestHandlers[protocol];
80
- if (builtInHandler) {
81
- return await builtInHandler(uri) ?? '';
82
- }
83
- return '';
84
- },
85
- };
86
- let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.server.runtimeEnv.uriToFileName(context.workspace.rootUri.toString()), context.workspaces.initOptions.configFilePath) : {}) ?? {};
87
- for (const plugin of context.workspaces.plugins) {
88
- if (plugin.resolveConfig) {
89
- config = plugin.resolveConfig(config, {
90
- ...context,
91
- env,
92
- sys,
93
- host: languageServiceHost,
94
- });
95
- }
96
- }
97
- languageService = embeddedLS.createLanguageService({ typescript: context.workspaces.ts }, env, config, languageServiceHost, sys, context.project.documentRegistry);
100
+ languageService = (0, language_service_1.createLanguageService)({ typescript: context.workspaces.ts }, env, config, languageHost);
98
101
  }
99
102
  return languageService;
100
103
  }
101
- async function onWorkspaceFilesChanged(changes) {
102
- const _projectVersion = projectVersion;
103
- for (const change of changes) {
104
- const script = scripts.uriGet(change.uri);
105
- if (script && (change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Created)) {
106
- if (script.version >= 0) {
107
- script.version = -1;
108
- }
109
- else {
110
- script.version--;
111
- }
112
- }
113
- else if (script && change.type === vscode.FileChangeType.Deleted) {
114
- scripts.uriDelete(change.uri);
115
- }
116
- if (script
117
- || change.uri.endsWith('.d.ts')
118
- || change.uri.endsWith('/package.json')) {
119
- projectVersion++;
104
+ async function syncRootScriptSnapshots() {
105
+ const promises = [];
106
+ let dirty = false;
107
+ for (const fileName of parsedCommandLine.fileNames) {
108
+ const uri = fileNameToUri(fileName);
109
+ if (!fsScriptsCache.uriHas(uri)) {
110
+ dirty = true;
111
+ promises.push(updateRootScriptSnapshot(uri));
120
112
  }
121
113
  }
122
- const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
123
- const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
124
- if (creates.length || deletes.length) {
125
- parsedCommandLine = createParsedCommandLine(context.workspaces.ts, sys, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins);
126
- projectVersion++;
127
- typeRootVersion++;
128
- }
129
- if (_projectVersion !== projectVersion) {
130
- projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
131
- }
114
+ await Promise.all(promises);
115
+ return dirty;
132
116
  }
133
- function createLanguageServiceHost() {
134
- const token = {
135
- isCancellationRequested() {
136
- return context.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
137
- },
138
- throwIfCancellationRequested() { },
139
- };
140
- let host = {
141
- // ts
142
- getNewLine: () => sys.newLine,
143
- useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
144
- readFile: sys.readFile,
145
- writeFile: sys.writeFile,
146
- directoryExists: sys.directoryExists,
147
- getDirectories: sys.getDirectories,
148
- readDirectory: sys.readDirectory,
149
- realpath: sys.realpath,
150
- fileExists: sys.fileExists,
151
- getCurrentDirectory: () => uriToFileName(context.project.rootUri.toString()),
152
- getProjectReferences: () => parsedCommandLine.projectReferences,
153
- getCancellationToken: () => token,
154
- // custom
155
- getDefaultLibFileName: options => {
156
- if (context.workspaces.initOptions.typescript && context.workspaces.ts) {
157
- try {
158
- return context.workspaces.ts.getDefaultLibFilePath(options);
159
- }
160
- catch {
161
- // web
162
- const tsdk = context.workspaces.initOptions.typescript.tsdk;
163
- return tsdk + '/' + context.workspaces.ts.getDefaultLibFileName(options);
164
- }
165
- }
166
- return '';
167
- },
168
- getProjectVersion: () => projectVersion.toString(),
169
- getTypeRootsVersion: () => typeRootVersion,
170
- getScriptFileNames: () => parsedCommandLine.fileNames,
171
- getCompilationSettings: () => parsedCommandLine.options,
172
- getScriptVersion,
173
- getScriptSnapshot,
174
- getScriptLanguageId: (fileName) => {
175
- return context.workspaces.documents.data.pathGet(fileName)?.languageId;
176
- },
177
- };
178
- if (context.workspaces.tsLocalized) {
179
- host.getLocalizedDiagnosticMessages = () => context.workspaces.tsLocalized;
180
- }
181
- return host;
182
- function getScriptVersion(fileName) {
183
- const doc = context.workspaces.documents.data.pathGet(fileName);
184
- if (doc) {
185
- return doc.version.toString();
117
+ async function updateRootScriptSnapshot(uri) {
118
+ const text = await context.server.runtimeEnv.fs.readFile(uri);
119
+ fsScriptsCache.uriSet(uri, text !== undefined ? {
120
+ getText: (start, end) => text.substring(start, end),
121
+ getLength: () => text.length,
122
+ getChangeRange: () => undefined,
123
+ } : undefined);
124
+ }
125
+ async function onWorkspaceFilesChanged(changes) {
126
+ const oldProjectVersion = projectVersion;
127
+ const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
128
+ if (creates.length) {
129
+ parsedCommandLine = await createParsedCommandLine(context.workspaces.ts, env, uriToFileName(context.project.rootUri.toString()), context.project.tsConfig, context.workspaces.plugins, existingOptions);
130
+ if (await syncRootScriptSnapshots()) {
131
+ projectVersion++;
186
132
  }
187
- return scripts.pathGet(fileName)?.version.toString() ?? '';
188
133
  }
189
- function getScriptSnapshot(fileName) {
190
- const doc = context.workspaces.documents.data.pathGet(fileName);
191
- if (doc) {
192
- return doc.getSnapshot();
193
- }
194
- const script = scripts.pathGet(fileName);
195
- if (script && script.snapshotVersion === script.version) {
196
- return script.snapshot;
197
- }
198
- if (context.workspaces.ts && sys.fileExists(fileName)) {
199
- if (context.workspaces.initOptions.maxFileSize) {
200
- const fileSize = sys.getFileSize?.(fileName);
201
- if (fileSize !== undefined && fileSize > context.workspaces.initOptions.maxFileSize) {
202
- console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspaces.initOptions.maxFileSize}bytes)`);
203
- return context.workspaces.ts.ScriptSnapshot.fromString('');
204
- }
134
+ for (const change of changes) {
135
+ const oldSnapshot = fsScriptsCache.uriGet(change.uri);
136
+ if (oldSnapshot) {
137
+ if (change.type === vscode.FileChangeType.Changed) {
138
+ updateRootScriptSnapshot(change.uri);
205
139
  }
206
- const text = sys.readFile(fileName, 'utf8');
207
- if (text !== undefined) {
208
- const snapshot = context.workspaces.ts.ScriptSnapshot.fromString(text);
209
- if (script) {
210
- script.snapshot = snapshot;
211
- script.snapshotVersion = script.version;
212
- }
213
- else {
214
- scripts.pathSet(fileName, {
215
- version: -1,
216
- fileName: fileName,
217
- snapshot: snapshot,
218
- snapshotVersion: -1,
219
- });
220
- }
221
- return snapshot;
140
+ else if (change.type === vscode.FileChangeType.Deleted) {
141
+ fsScriptsCache.uriSet(change.uri, undefined);
222
142
  }
143
+ projectVersion++;
223
144
  }
224
145
  }
146
+ if (oldProjectVersion !== projectVersion) {
147
+ projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
148
+ }
225
149
  }
226
150
  function dispose() {
227
151
  languageService?.dispose();
228
- scripts.clear();
229
- disposeWatchEvent?.();
230
- disposeDocChange();
152
+ fileWatch?.dispose();
153
+ docChangeWatcher.dispose();
231
154
  }
232
155
  }
233
156
  exports.createProject = createProject;
234
- function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
157
+ async function createParsedCommandLine(ts, env, rootPath, tsConfig, plugins, existingOptions) {
235
158
  const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions ?? []).flat();
236
159
  if (ts) {
237
- try {
238
- let content;
239
- if (typeof tsConfig === 'string') {
240
- const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
241
- content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), {}, tsConfig, undefined, extraFileExtensions);
160
+ const sys = (0, typescript_1.createSys)(undefined, ts, {
161
+ ...env,
162
+ onDidChangeWatchedFiles: undefined,
163
+ });
164
+ let content;
165
+ let sysVersion;
166
+ let newSysVersion = await sys.sync();
167
+ while (sysVersion !== newSysVersion) {
168
+ sysVersion = newSysVersion;
169
+ try {
170
+ if (typeof tsConfig === 'string') {
171
+ const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
172
+ content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), existingOptions, tsConfig, undefined, extraFileExtensions);
173
+ }
174
+ else {
175
+ content = ts.parseJsonConfigFileContent({ files: [] }, sys, rootPath, { ...tsConfig, ...existingOptions }, rootPath + '/jsconfig.json', undefined, extraFileExtensions);
176
+ }
177
+ // fix https://github.com/johnsoncodehk/volar/issues/1786
178
+ // https://github.com/microsoft/TypeScript/issues/30457
179
+ // patching ts server broke with outDir + rootDir + composite/incremental
180
+ content.options.outDir = undefined;
181
+ content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
242
182
  }
243
- else {
244
- content = ts.parseJsonConfigFileContent({ files: [] }, sys, rootPath, tsConfig, path.join(rootPath, 'jsconfig.json'), undefined, extraFileExtensions);
183
+ catch {
184
+ // will be failed if web fs host first result not ready
245
185
  }
246
- // fix https://github.com/johnsoncodehk/volar/issues/1786
247
- // https://github.com/microsoft/TypeScript/issues/30457
248
- // patching ts server broke with outDir + rootDir + composite/incremental
249
- content.options.outDir = undefined;
250
- content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
251
- return content;
186
+ newSysVersion = await sys.sync();
252
187
  }
253
- catch {
254
- // will be failed if web fs host first result not ready
188
+ if (content) {
189
+ return content;
255
190
  }
256
191
  }
257
192
  return {
@@ -260,51 +195,4 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
260
195
  options: {},
261
196
  };
262
197
  }
263
- function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
264
- const documentContext = {
265
- resolveReference: (ref, base) => {
266
- if (ts && host) { // support tsconfig.json paths
267
- const isUri = base.indexOf('://') >= 0;
268
- const resolveResult = ts.resolveModuleName(ref, isUri ? uriToFileName(base) : base, host.getCompilationSettings(), host);
269
- const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
270
- const dirs = new Set();
271
- if (!failedLookupLocations) {
272
- console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
273
- }
274
- for (let failed of failedLookupLocations ?? []) {
275
- const fileName = path.basename(failed);
276
- if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
277
- dirs.add(path.dirname(failed));
278
- }
279
- if (failed.endsWith('.d.ts')) {
280
- failed = failed.substring(0, failed.length - '.d.ts'.length);
281
- }
282
- else {
283
- continue;
284
- }
285
- if (host.fileExists(failed)) {
286
- return isUri ? fileNameToUri(failed) : failed;
287
- }
288
- }
289
- for (const dir of dirs) {
290
- if (host.directoryExists?.(dir) ?? true) {
291
- return isUri ? fileNameToUri(dir) : dir;
292
- }
293
- }
294
- }
295
- // original html resolveReference
296
- if (ref.match(/^\w[\w\d+.-]*:/)) {
297
- // starts with a schema
298
- return ref;
299
- }
300
- if (ref[0] === '/') { // resolve absolute path against the current workspace folder
301
- return rootUri + ref;
302
- }
303
- const baseUri = vscode_uri_1.URI.parse(base);
304
- const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
305
- return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
306
- },
307
- };
308
- return documentContext;
309
- }
310
198
  //# sourceMappingURL=project.js.map
@@ -1,10 +1,14 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
2
  import { InitializationOptions, LanguageServerPlugin, RuntimeEnvironment } from '../types';
3
+ import { createConfigurationHost } from './configurationHost';
3
4
  export interface ServerContext {
4
5
  server: {
6
+ initializeParams: vscode.InitializeParams;
5
7
  connection: vscode.Connection;
6
8
  runtimeEnv: RuntimeEnvironment;
7
9
  plugins: LanguageServerPlugin[];
10
+ onDidChangeWatchedFiles: vscode.Connection['onDidChangeWatchedFiles'];
11
+ configurationHost: ReturnType<typeof createConfigurationHost> | undefined;
8
12
  };
9
13
  }
10
- export declare function startCommonLanguageServer(connection: vscode.Connection, getCtx: (initOptions: InitializationOptions) => ServerContext['server']): void;
14
+ export declare function startCommonLanguageServer(connection: vscode.Connection, _plugins: LanguageServerPlugin[], getRuntimeEnv: (params: vscode.InitializeParams, options: InitializationOptions) => RuntimeEnvironment): Promise<void>;
@@ -12,20 +12,40 @@ const documents_1 = require("./documents");
12
12
  const registerFeatures_1 = require("./utils/registerFeatures");
13
13
  const serverConfig_1 = require("./utils/serverConfig");
14
14
  const workspaces_1 = require("./workspaces");
15
- function startCommonLanguageServer(connection, getCtx) {
15
+ const request_light_1 = require("request-light");
16
+ async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
16
17
  let initParams;
17
18
  let options;
18
19
  let roots = [];
19
- let fsHost;
20
20
  let projects;
21
- let configurationHost;
22
21
  let plugins;
23
22
  let documents;
24
23
  let context;
24
+ const didChangeWatchedFilesCallbacks = new Set();
25
25
  connection.onInitialize(async (_params) => {
26
26
  initParams = _params;
27
27
  options = initParams.initializationOptions;
28
- context = { server: getCtx(options) };
28
+ const env = getRuntimeEnv(initParams, options);
29
+ context = {
30
+ server: {
31
+ initializeParams: initParams,
32
+ connection,
33
+ runtimeEnv: {
34
+ ...env,
35
+ fs: createFsWithCache(env.fs),
36
+ },
37
+ plugins: _plugins,
38
+ configurationHost: initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined,
39
+ onDidChangeWatchedFiles: cb => {
40
+ didChangeWatchedFilesCallbacks.add(cb);
41
+ return {
42
+ dispose: () => {
43
+ didChangeWatchedFilesCallbacks.delete(cb);
44
+ },
45
+ };
46
+ },
47
+ },
48
+ };
29
49
  plugins = context.server.plugins.map(plugin => plugin(options, {
30
50
  typescript: options.typescript ? context.server.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined
31
51
  }));
@@ -54,14 +74,13 @@ function startCommonLanguageServer(connection, getCtx) {
54
74
  },
55
75
  },
56
76
  };
57
- configurationHost = initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
58
77
  let services = {};
59
78
  for (const root of roots) {
60
79
  if (root.scheme === 'file') {
61
80
  let config = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath) ?? {};
62
81
  for (const plugin of plugins) {
63
82
  if (plugin.resolveConfig) {
64
- config = plugin.resolveConfig(config, undefined);
83
+ config = await plugin.resolveConfig(config, undefined);
65
84
  }
66
85
  }
67
86
  if (config.services) {
@@ -85,9 +104,10 @@ function startCommonLanguageServer(connection, getCtx) {
85
104
  catch { }
86
105
  return result;
87
106
  });
88
- connection.onInitialized(() => {
89
- fsHost?.ready(connection);
90
- configurationHost?.ready();
107
+ connection.onInitialized(async () => {
108
+ context.server.configurationHost?.ready();
109
+ context.server.configurationHost?.onDidChangeConfiguration?.(updateHttpSettings);
110
+ updateHttpSettings();
91
111
  if (initParams.capabilities.workspace?.workspaceFolders) {
92
112
  connection.workspace.onDidChangeWorkspaceFolders(e => {
93
113
  for (const folder of e.added) {
@@ -109,8 +129,17 @@ function startCommonLanguageServer(connection, getCtx) {
109
129
  },
110
130
  ]
111
131
  });
132
+ connection.onDidChangeWatchedFiles(e => {
133
+ for (const cb of didChangeWatchedFilesCallbacks) {
134
+ cb(e);
135
+ }
136
+ });
112
137
  }
113
138
  }
139
+ async function updateHttpSettings() {
140
+ const httpSettings = await context.server.configurationHost?.getConfiguration?.('http');
141
+ (0, request_light_1.configure)(httpSettings?.proxy, httpSettings?.proxyStrictSSL ?? false);
142
+ }
114
143
  });
115
144
  connection.onShutdown(async () => {
116
145
  if (projects) {
@@ -120,16 +149,58 @@ function startCommonLanguageServer(connection, getCtx) {
120
149
  }
121
150
  });
122
151
  connection.listen();
152
+ function createFsWithCache(fs) {
153
+ const readFileCache = new Map();
154
+ const statCache = new Map();
155
+ const readDirectoryCache = new Map();
156
+ didChangeWatchedFilesCallbacks.add(({ changes }) => {
157
+ for (const change of changes) {
158
+ if (change.type === vscode.FileChangeType.Deleted) {
159
+ readFileCache.set(change.uri, undefined);
160
+ statCache.set(change.uri, undefined);
161
+ const dir = change.uri.substring(0, change.uri.lastIndexOf('/'));
162
+ readDirectoryCache.delete(dir);
163
+ }
164
+ else if (change.type === vscode.FileChangeType.Changed) {
165
+ readFileCache.delete(change.uri);
166
+ statCache.delete(change.uri);
167
+ }
168
+ else if (change.type === vscode.FileChangeType.Created) {
169
+ readFileCache.delete(change.uri);
170
+ statCache.delete(change.uri);
171
+ const dir = change.uri.substring(0, change.uri.lastIndexOf('/'));
172
+ readDirectoryCache.delete(dir);
173
+ }
174
+ }
175
+ });
176
+ return {
177
+ readFile: uri => {
178
+ if (!readFileCache.has(uri)) {
179
+ readFileCache.set(uri, fs.readFile(uri));
180
+ }
181
+ return readFileCache.get(uri);
182
+ },
183
+ stat: uri => {
184
+ if (!statCache.has(uri)) {
185
+ statCache.set(uri, fs.stat(uri));
186
+ }
187
+ return statCache.get(uri);
188
+ },
189
+ readDirectory: uri => {
190
+ if (!readDirectoryCache.has(uri)) {
191
+ readDirectoryCache.set(uri, fs.readDirectory(uri));
192
+ }
193
+ return readDirectoryCache.get(uri);
194
+ },
195
+ };
196
+ }
123
197
  async function createLanguageServiceHost() {
124
198
  const ts = options.typescript ? context.server.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
125
- fsHost = ts ? context.server.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.server.runtimeEnv, options) : undefined;
126
199
  const tsLocalized = options.typescript && initParams.locale ? await context.server.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
127
200
  const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
128
201
  projects = (0, workspaces_1.createWorkspaces)({
129
202
  ...context,
130
203
  workspaces: {
131
- fileSystemHost: fsHost,
132
- configurationHost,
133
204
  ts,
134
205
  tsLocalized,
135
206
  initParams,