@volar/language-server 1.3.0-alpha.0 → 1.3.0-alpha.2

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.
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.createProject = void 0;
12
12
  const embeddedLS = require("@volar/language-service");
13
- const shared = require("@volar/shared");
14
13
  const path = require("typesafe-path");
15
14
  const vscode = require("vscode-languageserver");
16
15
  const vscode_uri_1 = require("vscode-uri");
@@ -19,6 +18,8 @@ const uriMap_1 = require("./utils/uriMap");
19
18
  function createProject(context) {
20
19
  var _a;
21
20
  return __awaiter(this, void 0, void 0, function* () {
21
+ const uriToFileName = context.workspace.workspaces.server.runtimeEnv.uriToFileName;
22
+ const fileNameToUri = context.workspace.workspaces.server.runtimeEnv.fileNameToUri;
22
23
  const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
23
24
  ? {
24
25
  newLine: '\n',
@@ -35,8 +36,8 @@ function createProject(context) {
35
36
  let projectVersion = 0;
36
37
  let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
37
38
  let languageService;
38
- let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
39
- const scripts = (0, uriMap_1.createUriMap)();
39
+ let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
40
+ const scripts = (0, uriMap_1.createUriMap)(fileNameToUri);
40
41
  const languageServiceHost = createLanguageServiceHost();
41
42
  const disposeWatchEvent = (_a = context.workspace.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(params => {
42
43
  onWorkspaceFilesChanged(params.changes);
@@ -69,31 +70,36 @@ function createProject(context) {
69
70
  plugins: Object.assign({}, (_b = context.serverConfig) === null || _b === void 0 ? void 0 : _b.plugins),
70
71
  lint: Object.assign(Object.assign({}, (_c = context.serverConfig) === null || _c === void 0 ? void 0 : _c.lint), { rules: Object.assign({}, (_e = (_d = context.serverConfig) === null || _d === void 0 ? void 0 : _d.lint) === null || _e === void 0 ? void 0 : _e.rules) }),
71
72
  };
72
- const env = {
73
+ const options = {
74
+ uriToFileName,
75
+ fileNameToUri,
73
76
  rootUri: context.rootUri,
77
+ host: languageServiceHost,
78
+ config,
74
79
  locale: context.workspace.workspaces.initParams.locale,
75
80
  configurationHost: context.workspace.workspaces.configurationHost,
76
81
  fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
77
- documentContext: getDocumentContext(context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
82
+ documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
78
83
  schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
84
+ var _g;
79
85
  const protocol = uri.substring(0, uri.indexOf(':'));
80
86
  const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
81
87
  if (builtInHandler) {
82
- return yield builtInHandler(uri);
88
+ return (_g = yield builtInHandler(uri)) !== null && _g !== void 0 ? _g : '';
83
89
  }
84
90
  return '';
85
91
  }),
86
92
  };
87
93
  const lsCtx = {
88
94
  project: context,
89
- env,
95
+ options,
90
96
  sys,
91
97
  host: languageServiceHost,
92
98
  };
93
99
  for (const plugin of context.workspace.workspaces.plugins) {
94
100
  (_f = plugin.resolveConfig) === null || _f === void 0 ? void 0 : _f.call(plugin, config, lsCtx);
95
101
  }
96
- languageService = embeddedLS.createLanguageService(languageServiceHost, config, env, context.documentRegistry);
102
+ languageService = embeddedLS.createLanguageService(options, context.documentRegistry);
97
103
  }
98
104
  return languageService;
99
105
  }
@@ -113,14 +119,16 @@ function createProject(context) {
113
119
  else if (script && change.type === vscode.FileChangeType.Deleted) {
114
120
  scripts.uriDelete(change.uri);
115
121
  }
116
- if (script) {
122
+ if (script
123
+ || change.uri.endsWith('.d.ts')
124
+ || change.uri.endsWith('/package.json')) {
117
125
  projectVersion++;
118
126
  }
119
127
  }
120
128
  const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
121
129
  const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
122
130
  if (creates.length || deletes.length) {
123
- parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
131
+ parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
124
132
  projectVersion++;
125
133
  typeRootVersion++;
126
134
  }
@@ -147,7 +155,7 @@ function createProject(context) {
147
155
  readDirectory: sys.readDirectory,
148
156
  realpath: sys.realpath,
149
157
  fileExists: sys.fileExists,
150
- getCurrentDirectory: () => shared.uriToFileName(context.rootUri.toString()),
158
+ getCurrentDirectory: () => uriToFileName(context.rootUri.toString()),
151
159
  getProjectReferences: () => parsedCommandLine.projectReferences,
152
160
  getCancellationToken: () => token,
153
161
  // custom
@@ -158,7 +166,8 @@ function createProject(context) {
158
166
  }
159
167
  catch (_a) {
160
168
  // web
161
- return context.workspace.workspaces.initOptions.typescript.tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
169
+ const tsdk = context.workspace.workspaces.initOptions.typescript.tsdk;
170
+ return tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
162
171
  }
163
172
  }
164
173
  return '';
@@ -256,7 +265,7 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
256
265
  // https://github.com/microsoft/TypeScript/issues/30457
257
266
  // patching ts server broke with outDir + rootDir + composite/incremental
258
267
  content.options.outDir = undefined;
259
- content.fileNames = content.fileNames.map(shared.normalizeFileName);
268
+ content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
260
269
  return content;
261
270
  }
262
271
  catch (_a) {
@@ -269,13 +278,13 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
269
278
  options: {},
270
279
  };
271
280
  }
272
- function getDocumentContext(ts, host, rootUri) {
281
+ function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
273
282
  const documentContext = {
274
283
  resolveReference: (ref, base) => {
275
284
  var _a, _b;
276
285
  if (ts && host) { // support tsconfig.json paths
277
286
  const isUri = base.indexOf('://') >= 0;
278
- const resolveResult = ts.resolveModuleName(ref, isUri ? shared.uriToFileName(base) : base, host.getCompilationSettings(), host);
287
+ const resolveResult = ts.resolveModuleName(ref, isUri ? uriToFileName(base) : base, host.getCompilationSettings(), host);
279
288
  const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
280
289
  const dirs = new Set();
281
290
  if (!failedLookupLocations) {
@@ -293,12 +302,12 @@ function getDocumentContext(ts, host, rootUri) {
293
302
  continue;
294
303
  }
295
304
  if (host.fileExists(failed)) {
296
- return isUri ? shared.fileNameToUri(failed) : failed;
305
+ return isUri ? fileNameToUri(failed) : failed;
297
306
  }
298
307
  }
299
308
  for (const dir of dirs) {
300
309
  if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
301
- return isUri ? shared.fileNameToUri(dir) : dir;
310
+ return isUri ? fileNameToUri(dir) : dir;
302
311
  }
303
312
  }
304
313
  }
@@ -1 +1 @@
1
- export default function handler(uri: string): Promise<string>;
1
+ export default function handler(uri: string): Promise<string | undefined>;
@@ -3,6 +3,9 @@ const request_light_1 = require("request-light");
3
3
  function handler(uri) {
4
4
  const headers = { 'Accept-Encoding': 'gzip, deflate' };
5
5
  return (0, request_light_1.xhr)({ url: uri, followRedirects: 5, headers }).then(response => {
6
+ if (response.status !== 200) {
7
+ return;
8
+ }
6
9
  return response.responseText;
7
10
  }, (error) => {
8
11
  return Promise.reject(error.responseText || (0, request_light_1.getErrorStatusDescription)(error.status) || error.toString());
@@ -1,8 +1,8 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
- import { LanguageServerPlugin, RuntimeEnvironment } from '../types';
2
+ import { LanguageServerInitializationOptions, LanguageServerPlugin, RuntimeEnvironment } from '../types';
3
3
  export interface ServerContext {
4
4
  connection: vscode.Connection;
5
5
  runtimeEnv: RuntimeEnvironment;
6
6
  plugins: LanguageServerPlugin[];
7
7
  }
8
- export declare function startCommonLanguageServer(context: ServerContext): void;
8
+ export declare function startCommonLanguageServer(connection: vscode.Connection, getCtx: (initOptions: LanguageServerInitializationOptions) => ServerContext): void;
@@ -18,7 +18,7 @@ const documents_1 = require("./documents");
18
18
  const registerFeatures_1 = require("./utils/registerFeatures");
19
19
  const workspaces_1 = require("./workspaces");
20
20
  const l10n = require("@vscode/l10n");
21
- function startCommonLanguageServer(context) {
21
+ function startCommonLanguageServer(connection, getCtx) {
22
22
  let initParams;
23
23
  let options;
24
24
  let roots = [];
@@ -26,12 +26,15 @@ function startCommonLanguageServer(context) {
26
26
  let projects;
27
27
  let configurationHost;
28
28
  let plugins;
29
- const documents = (0, documents_1.createDocuments)(context.connection);
30
- context.connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
29
+ let documents;
30
+ let context;
31
+ connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
31
32
  var _a, _b, _c, _d;
32
33
  initParams = _params;
33
34
  options = initParams.initializationOptions;
35
+ context = getCtx(options);
34
36
  plugins = context.plugins.map(plugin => plugin(options));
37
+ documents = (0, documents_1.createDocuments)(context.runtimeEnv, connection);
35
38
  if (options.l10n) {
36
39
  yield l10n.config({ uri: options.l10n.location });
37
40
  }
@@ -49,7 +52,7 @@ function startCommonLanguageServer(context) {
49
52
  textDocumentSync: (_b = options.textDocumentSync) !== null && _b !== void 0 ? _b : vscode.TextDocumentSyncKind.Incremental,
50
53
  },
51
54
  };
52
- configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams, context.connection) : undefined;
55
+ configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
53
56
  (0, registerFeatures_1.setupCapabilities)(initParams.capabilities, result.capabilities, options, plugins, getSemanticTokensLegend());
54
57
  yield createLanguageServiceHost();
55
58
  try {
@@ -62,16 +65,16 @@ function startCommonLanguageServer(context) {
62
65
  }
63
66
  catch (_e) { }
64
67
  for (const plugin of plugins) {
65
- (_d = plugin.onInitialize) === null || _d === void 0 ? void 0 : _d.call(plugin, result);
68
+ (_d = plugin.onInitialize) === null || _d === void 0 ? void 0 : _d.call(plugin, result, context.runtimeEnv);
66
69
  }
67
70
  return result;
68
71
  }));
69
- context.connection.onInitialized(() => {
72
+ connection.onInitialized(() => {
70
73
  var _a, _b, _c;
71
- fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(context.connection);
74
+ fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(connection);
72
75
  configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.ready();
73
76
  if ((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) {
74
- context.connection.workspace.onDidChangeWorkspaceFolders(e => {
77
+ connection.workspace.onDidChangeWorkspaceFolders(e => {
75
78
  for (const folder of e.added) {
76
79
  projects === null || projects === void 0 ? void 0 : projects.add(vscode_uri_1.URI.parse(folder.uri));
77
80
  }
@@ -85,7 +88,7 @@ function startCommonLanguageServer(context) {
85
88
  && ((_c = (_b = initParams.capabilities.workspace) === null || _b === void 0 ? void 0 : _b.didChangeWatchedFiles) === null || _c === void 0 ? void 0 : _c.dynamicRegistration)) {
86
89
  const exts = plugins.map(plugin => { var _a; return (_a = plugin.extensions.fileWatcher) !== null && _a !== void 0 ? _a : []; }).flat();
87
90
  if (exts.length) {
88
- context.connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
91
+ connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
89
92
  watchers: [
90
93
  {
91
94
  globPattern: `**/*.{${exts.join(',')}}`
@@ -95,19 +98,19 @@ function startCommonLanguageServer(context) {
95
98
  }
96
99
  }
97
100
  });
98
- context.connection.onShutdown(() => __awaiter(this, void 0, void 0, function* () {
101
+ connection.onShutdown(() => __awaiter(this, void 0, void 0, function* () {
99
102
  if (projects) {
100
103
  for (const workspace of projects.workspaces) {
101
104
  (yield workspace[1]).dispose();
102
105
  }
103
106
  }
104
107
  }));
105
- context.connection.listen();
108
+ connection.listen();
106
109
  function createLanguageServiceHost() {
107
110
  var _a;
108
111
  return __awaiter(this, void 0, void 0, function* () {
109
112
  const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
110
- fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities) : undefined;
113
+ fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.runtimeEnv, options) : undefined;
111
114
  const tsLocalized = options.typescript && initParams.locale ? yield context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
112
115
  const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
113
116
  const _projects = (0, workspaces_1.createWorkspaces)({
@@ -126,10 +129,10 @@ function startCommonLanguageServer(context) {
126
129
  for (const root of roots) {
127
130
  projects.add(root);
128
131
  }
129
- (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(context.connection, projects);
130
- (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
132
+ (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
133
+ (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
131
134
  for (const plugin of plugins) {
132
- (_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService);
135
+ (_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService, context.runtimeEnv);
133
136
  }
134
137
  function getLanguageService(uri) {
135
138
  var _a;
@@ -7,7 +7,7 @@ interface Options<T> {
7
7
  clear(): void;
8
8
  values(): IterableIterator<T>;
9
9
  }
10
- export declare function createUriMap<T>(map?: Options<T>): {
10
+ export declare function createUriMap<T>(fileNameToUri: (fileName: string) => string, map?: Options<T>): {
11
11
  clear: () => void;
12
12
  values: () => IterableIterator<T>;
13
13
  uriDelete: (_uri: string) => boolean;
@@ -1,9 +1,8 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.createUriMap = exports._ = void 0;
3
3
  const vscode_uri_1 = require("vscode-uri");
4
- const shared = require("@volar/shared");
5
4
  exports._ = require("vscode-uri");
6
- function createUriMap(map = new Map()) {
5
+ function createUriMap(fileNameToUri, map = new Map()) {
7
6
  const uriToUri = new Map();
8
7
  const pathToUri = new Map();
9
8
  return {
@@ -25,7 +24,7 @@ function createUriMap(map = new Map()) {
25
24
  }
26
25
  function getUriByPath(path) {
27
26
  if (!pathToUri.has(path)) {
28
- pathToUri.set(path, shared.fileNameToUri(path).toLowerCase());
27
+ pathToUri.set(path, fileNameToUri(path).toLowerCase());
29
28
  }
30
29
  return pathToUri.get(path);
31
30
  }
@@ -12,7 +12,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
12
12
  projects: {
13
13
  clear: () => void;
14
14
  values: () => IterableIterator<Promise<{
15
- tsConfig: ts.CompilerOptions | path.PosixPath;
15
+ tsConfig: path.PosixPath | ts.CompilerOptions;
16
16
  scripts: {
17
17
  clear: () => void;
18
18
  values: () => IterableIterator<{
@@ -162,7 +162,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
162
162
  }>>;
163
163
  uriDelete: (_uri: string) => boolean;
164
164
  uriGet: (_uri: string) => Promise<{
165
- tsConfig: ts.CompilerOptions | path.PosixPath;
165
+ tsConfig: path.PosixPath | ts.CompilerOptions;
166
166
  scripts: {
167
167
  clear: () => void;
168
168
  values: () => IterableIterator<{
@@ -312,7 +312,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
312
312
  }> | undefined;
313
313
  uriHas: (_uri: string) => boolean;
314
314
  uriSet: (_uri: string, item: Promise<{
315
- tsConfig: ts.CompilerOptions | path.PosixPath;
315
+ tsConfig: path.PosixPath | ts.CompilerOptions;
316
316
  scripts: {
317
317
  clear: () => void;
318
318
  values: () => IterableIterator<{
@@ -462,7 +462,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
462
462
  }>) => void;
463
463
  pathDelete: (path: string) => boolean;
464
464
  pathGet: (path: string) => Promise<{
465
- tsConfig: ts.CompilerOptions | path.PosixPath;
465
+ tsConfig: path.PosixPath | ts.CompilerOptions;
466
466
  scripts: {
467
467
  clear: () => void;
468
468
  values: () => IterableIterator<{
@@ -611,7 +611,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
611
611
  dispose: () => void;
612
612
  }> | undefined;
613
613
  pathHas: (path: string) => Promise<{
614
- tsConfig: ts.CompilerOptions | path.PosixPath;
614
+ tsConfig: path.PosixPath | ts.CompilerOptions;
615
615
  scripts: {
616
616
  clear: () => void;
617
617
  values: () => IterableIterator<{
@@ -760,7 +760,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
760
760
  dispose: () => void;
761
761
  }> | undefined;
762
762
  pathSet: (path: string, item: Promise<{
763
- tsConfig: ts.CompilerOptions | path.PosixPath;
763
+ tsConfig: path.PosixPath | ts.CompilerOptions;
764
764
  scripts: {
765
765
  clear: () => void;
766
766
  values: () => IterableIterator<{
@@ -913,7 +913,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
913
913
  getProjectAndTsConfig: (uri: string) => Promise<{
914
914
  tsconfig: string;
915
915
  project: {
916
- tsConfig: ts.CompilerOptions | path.PosixPath;
916
+ tsConfig: path.PosixPath | ts.CompilerOptions;
917
917
  scripts: {
918
918
  clear: () => void;
919
919
  values: () => IterableIterator<{
@@ -1063,7 +1063,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
1063
1063
  } | undefined;
1064
1064
  } | undefined>;
1065
1065
  getInferredProject: () => Promise<{
1066
- tsConfig: ts.CompilerOptions | path.PosixPath;
1066
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1067
1067
  scripts: {
1068
1068
  clear: () => void;
1069
1069
  values: () => IterableIterator<{
@@ -1212,7 +1212,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
1212
1212
  dispose: () => void;
1213
1213
  }>;
1214
1214
  getInferredProjectDontCreate: () => Promise<{
1215
- tsConfig: ts.CompilerOptions | path.PosixPath;
1215
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1216
1216
  scripts: {
1217
1217
  clear: () => void;
1218
1218
  values: () => IterableIterator<{
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.sortTsConfigs = exports.createWorkspace = exports.rootTsConfigNames = void 0;
12
- const shared = require("@volar/shared");
13
12
  const path = require("typesafe-path");
14
13
  const vscode = require("vscode-languageserver");
15
14
  const vscode_uri_1 = require("vscode-uri");
@@ -22,23 +21,25 @@ exports.rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
22
21
  function createWorkspace(context) {
23
22
  var _a, _b, _c;
24
23
  return __awaiter(this, void 0, void 0, function* () {
24
+ const fileNameToUri = context.workspaces.server.runtimeEnv.fileNameToUri;
25
+ const uriToFileName = context.workspaces.server.runtimeEnv.uriToFileName;
25
26
  let inferredProject;
26
- const serverConfig = (0, serverConfig_1.loadConfig)(shared.uriToFileName(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
27
+ const serverConfig = (0, serverConfig_1.loadConfig)(uriToFileName(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
27
28
  const sys = (_a = context.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.getWorkspaceFileSystem(context.rootUri);
28
- const documentRegistry = sys ? (_b = context.workspaces.ts) === null || _b === void 0 ? void 0 : _b.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.uriToFileName(context.rootUri.toString())) : undefined;
29
- const projects = (0, uriMap_1.createUriMap)();
30
- const rootTsConfigs = new Set(sys === null || sys === void 0 ? void 0 : sys.readDirectory(shared.uriToFileName(context.rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
29
+ const documentRegistry = sys ? (_b = context.workspaces.ts) === null || _b === void 0 ? void 0 : _b.createDocumentRegistry(sys.useCaseSensitiveFileNames, uriToFileName(context.rootUri.toString())) : undefined;
30
+ const projects = (0, uriMap_1.createUriMap)(fileNameToUri);
31
+ const rootTsConfigs = new Set(sys === null || sys === void 0 ? void 0 : sys.readDirectory(uriToFileName(context.rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => fileName.replace(/\\/g, '/')));
31
32
  const disposeTsConfigWatch = (_c = context.workspaces.fileSystemHost) === null || _c === void 0 ? void 0 : _c.onDidChangeWatchedFiles(({ changes }) => {
32
33
  for (const change of changes) {
33
34
  if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
34
35
  if (change.type === vscode.FileChangeType.Created) {
35
- if ((0, isFileInDir_1.isFileInDir)(shared.uriToFileName(change.uri), shared.uriToFileName(context.rootUri.toString()))) {
36
- rootTsConfigs.add(shared.uriToFileName(change.uri));
36
+ if ((0, isFileInDir_1.isFileInDir)(uriToFileName(change.uri), uriToFileName(context.rootUri.toString()))) {
37
+ rootTsConfigs.add(uriToFileName(change.uri));
37
38
  }
38
39
  }
39
40
  else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && projects.uriHas(change.uri)) {
40
41
  if (change.type === vscode.FileChangeType.Deleted) {
41
- rootTsConfigs.delete(shared.uriToFileName(change.uri));
42
+ rootTsConfigs.delete(uriToFileName(change.uri));
42
43
  }
43
44
  const project = projects.uriGet(change.uri);
44
45
  projects.uriDelete(change.uri);
@@ -107,11 +108,11 @@ function createWorkspace(context) {
107
108
  return __awaiter(this, void 0, void 0, function* () {
108
109
  let matches = [];
109
110
  for (const rootTsConfig of rootTsConfigs) {
110
- if ((0, isFileInDir_1.isFileInDir)(shared.uriToFileName(uri.toString()), path.dirname(rootTsConfig))) {
111
+ if ((0, isFileInDir_1.isFileInDir)(uriToFileName(uri.toString()), path.dirname(rootTsConfig))) {
111
112
  matches.push(rootTsConfig);
112
113
  }
113
114
  }
114
- matches = matches.sort((a, b) => sortTsConfigs(shared.uriToFileName(uri.toString()), a, b));
115
+ matches = matches.sort((a, b) => sortTsConfigs(uriToFileName(uri.toString()), a, b));
115
116
  if (matches.length) {
116
117
  yield getParsedCommandLine(matches[0]);
117
118
  }
@@ -120,7 +121,7 @@ function createWorkspace(context) {
120
121
  function findDirectIncludeTsconfig() {
121
122
  return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
122
123
  var _a;
123
- const map = (0, uriMap_1.createUriMap)();
124
+ const map = (0, uriMap_1.createUriMap)(fileNameToUri);
124
125
  const parsedCommandLine = yield getParsedCommandLine(tsconfig);
125
126
  for (const fileName of (_a = parsedCommandLine === null || parsedCommandLine === void 0 ? void 0 : parsedCommandLine.fileNames) !== null && _a !== void 0 ? _a : []) {
126
127
  map.pathSet(fileName, true);
@@ -133,14 +134,14 @@ function createWorkspace(context) {
133
134
  var _a, _b;
134
135
  const project = yield projects.pathGet(tsconfig);
135
136
  const ls = project === null || project === void 0 ? void 0 : project.getLanguageServiceDontCreate();
136
- const validDoc = (_b = (_a = ls === null || ls === void 0 ? void 0 : ls.context.typescript) === null || _a === void 0 ? void 0 : _a.languageService.getProgram()) === null || _b === void 0 ? void 0 : _b.getSourceFile(shared.uriToFileName(uri.toString()));
137
+ const validDoc = (_b = (_a = ls === null || ls === void 0 ? void 0 : ls.context.typescript) === null || _a === void 0 ? void 0 : _a.languageService.getProgram()) === null || _b === void 0 ? void 0 : _b.getSourceFile(uriToFileName(uri.toString()));
137
138
  return !!validDoc;
138
139
  }));
139
140
  }
140
141
  function findTsconfig(match) {
141
142
  return __awaiter(this, void 0, void 0, function* () {
142
143
  const checked = new Set();
143
- for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(shared.uriToFileName(uri.toString()), a, b))) {
144
+ for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(uriToFileName(uri.toString()), a, b))) {
144
145
  const project = yield projects.pathGet(rootTsConfig);
145
146
  if (project) {
146
147
  let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
@@ -209,13 +210,13 @@ function createWorkspace(context) {
209
210
  });
210
211
  }
211
212
  function getProjectByCreate(_tsConfig) {
212
- const tsConfig = shared.normalizeFileName(_tsConfig);
213
+ const tsConfig = _tsConfig.replace(/\\/g, '/');
213
214
  let project = projects.pathGet(tsConfig);
214
215
  if (!project && documentRegistry) {
215
216
  project = (0, project_1.createProject)({
216
217
  workspace: context,
217
218
  serverConfig,
218
- rootUri: vscode_uri_1.URI.parse(shared.fileNameToUri(path.dirname(tsConfig))),
219
+ rootUri: vscode_uri_1.URI.parse(fileNameToUri(path.dirname(tsConfig))),
219
220
  tsConfig,
220
221
  documentRegistry,
221
222
  });
@@ -1,4 +1,3 @@
1
- /// <reference types="typesafe-path" />
2
1
  import { ConfigurationHost } from '@volar/language-service';
3
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
3
  import * as vscode from 'vscode-languageserver';
@@ -7,6 +6,7 @@ import { FileSystemHost, LanguageServerInitializationOptions, LanguageServerPlug
7
6
  import { CancellationTokenHost } from './cancellationPipe';
8
7
  import { createDocuments } from './documents';
9
8
  import { ServerContext } from './server';
9
+ import * as path from 'typesafe-path';
10
10
  export interface WorkspacesContext {
11
11
  server: ServerContext;
12
12
  initParams: vscode.InitializeParams;
@@ -26,7 +26,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
26
26
  projects: {
27
27
  clear: () => void;
28
28
  values: () => IterableIterator<Promise<{
29
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
29
+ tsConfig: path.PosixPath | ts.CompilerOptions;
30
30
  scripts: {
31
31
  clear: () => void;
32
32
  values: () => IterableIterator<{
@@ -176,7 +176,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
176
176
  }>>;
177
177
  uriDelete: (_uri: string) => boolean;
178
178
  uriGet: (_uri: string) => Promise<{
179
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
179
+ tsConfig: path.PosixPath | ts.CompilerOptions;
180
180
  scripts: {
181
181
  clear: () => void;
182
182
  values: () => IterableIterator<{
@@ -326,7 +326,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
326
326
  }> | undefined;
327
327
  uriHas: (_uri: string) => boolean;
328
328
  uriSet: (_uri: string, item: Promise<{
329
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
329
+ tsConfig: path.PosixPath | ts.CompilerOptions;
330
330
  scripts: {
331
331
  clear: () => void;
332
332
  values: () => IterableIterator<{
@@ -476,7 +476,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
476
476
  }>) => void;
477
477
  pathDelete: (path: string) => boolean;
478
478
  pathGet: (path: string) => Promise<{
479
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
479
+ tsConfig: path.PosixPath | ts.CompilerOptions;
480
480
  scripts: {
481
481
  clear: () => void;
482
482
  values: () => IterableIterator<{
@@ -625,7 +625,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
625
625
  dispose: () => void;
626
626
  }> | undefined;
627
627
  pathHas: (path: string) => Promise<{
628
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
628
+ tsConfig: path.PosixPath | ts.CompilerOptions;
629
629
  scripts: {
630
630
  clear: () => void;
631
631
  values: () => IterableIterator<{
@@ -774,7 +774,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
774
774
  dispose: () => void;
775
775
  }> | undefined;
776
776
  pathSet: (path: string, item: Promise<{
777
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
777
+ tsConfig: path.PosixPath | ts.CompilerOptions;
778
778
  scripts: {
779
779
  clear: () => void;
780
780
  values: () => IterableIterator<{
@@ -927,7 +927,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
927
927
  getProjectAndTsConfig: (uri: string) => Promise<{
928
928
  tsconfig: string;
929
929
  project: {
930
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
930
+ tsConfig: path.PosixPath | ts.CompilerOptions;
931
931
  scripts: {
932
932
  clear: () => void;
933
933
  values: () => IterableIterator<{
@@ -1077,7 +1077,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1077
1077
  } | undefined;
1078
1078
  } | undefined>;
1079
1079
  getInferredProject: () => Promise<{
1080
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1080
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1081
1081
  scripts: {
1082
1082
  clear: () => void;
1083
1083
  values: () => IterableIterator<{
@@ -1226,7 +1226,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1226
1226
  dispose: () => void;
1227
1227
  }>;
1228
1228
  getInferredProjectDontCreate: () => Promise<{
1229
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1229
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1230
1230
  scripts: {
1231
1231
  clear: () => void;
1232
1232
  values: () => IterableIterator<{
@@ -1380,7 +1380,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1380
1380
  getProject: (uri: string) => Promise<{
1381
1381
  tsconfig: string;
1382
1382
  project: {
1383
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1383
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1384
1384
  scripts: {
1385
1385
  clear: () => void;
1386
1386
  values: () => IterableIterator<{
@@ -1531,7 +1531,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1531
1531
  } | {
1532
1532
  tsconfig: undefined;
1533
1533
  project: {
1534
- tsConfig: ts.CompilerOptions | import("typesafe-path").PosixPath;
1534
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1535
1535
  scripts: {
1536
1536
  clear: () => void;
1537
1537
  values: () => IterableIterator<{
@@ -16,6 +16,7 @@ const workspace_1 = require("./workspace");
16
16
  const isFileInDir_1 = require("./utils/isFileInDir");
17
17
  function createWorkspaces(context) {
18
18
  var _a, _b, _c;
19
+ const uriToFileName = context.server.runtimeEnv.uriToFileName;
19
20
  const workspaces = new Map();
20
21
  let semanticTokensReq = 0;
21
22
  let documentUpdatedReq = 0;
@@ -139,8 +140,8 @@ function createWorkspaces(context) {
139
140
  var _a;
140
141
  return __awaiter(this, void 0, void 0, function* () {
141
142
  let rootUris = [...workspaces.keys()]
142
- .filter(rootUri => (0, isFileInDir_1.isFileInDir)(shared.uriToFileName(uri), shared.uriToFileName(rootUri)))
143
- .sort((a, b) => (0, workspace_1.sortTsConfigs)(shared.uriToFileName(uri), shared.uriToFileName(a), shared.uriToFileName(b)));
143
+ .filter(rootUri => (0, isFileInDir_1.isFileInDir)(uriToFileName(uri), uriToFileName(rootUri)))
144
+ .sort((a, b) => (0, workspace_1.sortTsConfigs)(uriToFileName(uri), uriToFileName(a), uriToFileName(b)));
144
145
  if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
145
146
  for (const rootUri of rootUris) {
146
147
  const workspace = yield workspaces.get(rootUri);
@@ -155,7 +156,7 @@ function createWorkspaces(context) {
155
156
  }
156
157
  if (rootUris.length) {
157
158
  const project = yield ((_a = (yield workspaces.get(rootUris[0]))) === null || _a === void 0 ? void 0 : _a.getInferredProject());
158
- project === null || project === void 0 ? void 0 : project.tryAddFile(shared.uriToFileName(uri));
159
+ project === null || project === void 0 ? void 0 : project.tryAddFile(uriToFileName(uri));
159
160
  return {
160
161
  tsconfig: undefined,
161
162
  project,
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
- import { FileSystemHost } from '../types';
3
- export declare function createNodeFileSystemHost(ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities): FileSystemHost;
2
+ import { FileSystemHost, LanguageServerInitializationOptions, RuntimeEnvironment } from '../types';
3
+ export declare function createNodeFileSystemHost(ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities, env: RuntimeEnvironment, _initOptions: LanguageServerInitializationOptions): FileSystemHost;