@volar/language-server 1.0.11 → 1.0.13

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.
package/out/browser.js CHANGED
@@ -12,6 +12,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
12
12
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
13
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
14
  };
15
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
17
+ return new (P || (P = Promise))(function (resolve, reject) {
18
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
19
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
22
+ });
23
+ };
15
24
  Object.defineProperty(exports, "__esModule", { value: true });
16
25
  exports.createLanguageServer = void 0;
17
26
  const request_light_1 = require("request-light");
@@ -20,16 +29,24 @@ const vscode = require("vscode-languageserver/browser");
20
29
  const server_1 = require("./server");
21
30
  const http_1 = require("./schemaRequestHandlers/http");
22
31
  const webFileSystemHost_1 = require("./utils/webFileSystemHost");
32
+ const shared = require("@volar/shared");
23
33
  function createLanguageServer(plugins) {
24
34
  const messageReader = new vscode.BrowserMessageReader(self);
25
35
  const messageWriter = new vscode.BrowserMessageWriter(self);
26
36
  const connection = vscode.createConnection(messageReader, messageWriter);
27
37
  (0, server_1.createCommonLanguageServer)(connection, {
28
- loadTypescript(options) {
38
+ loadTypescript() {
29
39
  return ts; // not support load by user config in web
30
40
  },
31
- loadTypescriptLocalized(options) {
32
- // TODO
41
+ loadTypescriptLocalized(tsdk, locale) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ try {
44
+ const uri = shared.getUriByPath(`${tsdk}/${locale}/diagnosticMessages.generated.json`);
45
+ const json = yield (0, http_1.default)(uri);
46
+ return JSON.parse(json);
47
+ }
48
+ catch (_a) { }
49
+ });
33
50
  },
34
51
  schemaRequestHandlers: {
35
52
  http: http_1.default,
@@ -68,10 +68,8 @@ function register(connection, projects) {
68
68
  }));
69
69
  connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
70
70
  const project = (yield projects.getProject(params.uri));
71
- if (project) {
72
- return {
73
- fileName: project.tsconfig,
74
- };
71
+ if (project === null || project === void 0 ? void 0 : project.tsconfig) {
72
+ return { uri: shared.getUriByPath(project.tsconfig) };
75
73
  }
76
74
  }));
77
75
  connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
@@ -103,9 +101,9 @@ function register(connection, projects) {
103
101
  }
104
102
  }
105
103
  }));
106
- connection.onNotification(protocol_1.ReloadProjectNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
104
+ connection.onNotification(protocol_1.ReloadProjectNotification.type, () => {
107
105
  projects.reloadProject();
108
- }));
106
+ });
109
107
  connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
110
108
  var _s;
111
109
  const fs = yield Promise.resolve().then(() => require('fs'));
@@ -196,7 +196,7 @@ function register(connection, projects, initParams, cancelHost) {
196
196
  return buildTokens(result);
197
197
  }))) !== null && _l !== void 0 ? _l : buildTokens([]);
198
198
  }));
199
- connection.languages.diagnostics.on((params, token, workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
199
+ connection.languages.diagnostics.on((params, token, _workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
200
200
  token = cancelHost.createCancellationToken(token);
201
201
  const result = yield worker(params.textDocument.uri, vueLs => {
202
202
  return vueLs.doValidation(params.textDocument.uri, token, errors => {
package/out/node.js CHANGED
@@ -12,6 +12,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
12
12
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
13
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
14
  };
15
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
17
+ return new (P || (P = Promise))(function (resolve, reject) {
18
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
19
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
22
+ });
23
+ };
15
24
  Object.defineProperty(exports, "__esModule", { value: true });
16
25
  exports.createLanguageServer = void 0;
17
26
  const shared = require("@volar/shared");
@@ -36,11 +45,13 @@ function createLanguageServer(plugins) {
36
45
  }
37
46
  },
38
47
  loadTypescriptLocalized(tsdk, locale) {
39
- try {
40
- const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
41
- return require(path);
42
- }
43
- catch (_a) { }
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ try {
50
+ const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
51
+ return require(path);
52
+ }
53
+ catch (_a) { }
54
+ });
44
55
  },
45
56
  schemaRequestHandlers: {
46
57
  file: file_1.default,
package/out/protocol.d.ts CHANGED
@@ -9,6 +9,15 @@ export declare namespace ShowReferencesNotification {
9
9
  };
10
10
  const type: vscode.NotificationType<ResponseType>;
11
11
  }
12
+ export declare namespace FsStatRequest {
13
+ const type: vscode.RequestType<string, html.FileStat | null | undefined, unknown>;
14
+ }
15
+ export declare namespace FsReadFileRequest {
16
+ const type: vscode.RequestType<string, string | null | undefined, unknown>;
17
+ }
18
+ export declare namespace FsReadDirectoryRequest {
19
+ const type: vscode.RequestType<string, [string, html.FileType][], unknown>;
20
+ }
12
21
  /**
13
22
  * Client request server
14
23
  */
@@ -23,7 +32,7 @@ export declare namespace FindFileReferenceRequest {
23
32
  export declare namespace GetMatchTsConfigRequest {
24
33
  type ParamsType = vscode.TextDocumentIdentifier;
25
34
  type ResponseType = {
26
- fileName: string;
35
+ uri: string;
27
36
  } | null | undefined;
28
37
  type ErrorType = never;
29
38
  const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
@@ -77,15 +86,3 @@ export declare namespace GetVirtualFileRequest {
77
86
  export declare namespace ReportStats {
78
87
  const type: vscode.NotificationType0;
79
88
  }
80
- /**
81
- * FS request for browser
82
- */
83
- export declare namespace FsStatRequest {
84
- const type: vscode.RequestType<string, html.FileStat | undefined, unknown>;
85
- }
86
- export declare namespace FsReadFileRequest {
87
- const type: vscode.RequestType<string, string | undefined, unknown>;
88
- }
89
- export declare namespace FsReadDirectoryRequest {
90
- const type: vscode.RequestType<string, [string, html.FileType][], unknown>;
91
- }
package/out/protocol.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.ReportStats = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.ShowReferencesNotification = void 0;
2
+ exports.ReportStats = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.ShowReferencesNotification = void 0;
3
3
  const vscode = require("vscode-languageserver-protocol");
4
4
  /**
5
5
  * Server request client
@@ -8,6 +8,18 @@ var ShowReferencesNotification;
8
8
  (function (ShowReferencesNotification) {
9
9
  ShowReferencesNotification.type = new vscode.NotificationType('vue.findReferences');
10
10
  })(ShowReferencesNotification = exports.ShowReferencesNotification || (exports.ShowReferencesNotification = {}));
11
+ var FsStatRequest;
12
+ (function (FsStatRequest) {
13
+ FsStatRequest.type = new vscode.RequestType('fs/stat');
14
+ })(FsStatRequest = exports.FsStatRequest || (exports.FsStatRequest = {}));
15
+ var FsReadFileRequest;
16
+ (function (FsReadFileRequest) {
17
+ FsReadFileRequest.type = new vscode.RequestType('fs/readFile');
18
+ })(FsReadFileRequest = exports.FsReadFileRequest || (exports.FsReadFileRequest = {}));
19
+ var FsReadDirectoryRequest;
20
+ (function (FsReadDirectoryRequest) {
21
+ FsReadDirectoryRequest.type = new vscode.RequestType('fs/readDirectory');
22
+ })(FsReadDirectoryRequest = exports.FsReadDirectoryRequest || (exports.FsReadDirectoryRequest = {}));
11
23
  /**
12
24
  * Client request server
13
25
  */
@@ -47,19 +59,4 @@ var ReportStats;
47
59
  (function (ReportStats) {
48
60
  ReportStats.type = new vscode.NotificationType0('vue/stats');
49
61
  })(ReportStats = exports.ReportStats || (exports.ReportStats = {}));
50
- /**
51
- * FS request for browser
52
- */
53
- var FsStatRequest;
54
- (function (FsStatRequest) {
55
- FsStatRequest.type = new vscode.RequestType('fs/stat');
56
- })(FsStatRequest = exports.FsStatRequest || (exports.FsStatRequest = {}));
57
- var FsReadFileRequest;
58
- (function (FsReadFileRequest) {
59
- FsReadFileRequest.type = new vscode.RequestType('fs/readFile');
60
- })(FsReadFileRequest = exports.FsReadFileRequest || (exports.FsReadFileRequest = {}));
61
- var FsReadDirectoryRequest;
62
- (function (FsReadDirectoryRequest) {
63
- FsReadDirectoryRequest.type = new vscode.RequestType('fs/readDirectory');
64
- })(FsReadDirectoryRequest = exports.FsReadDirectoryRequest || (exports.FsReadDirectoryRequest = {}));
65
62
  //# sourceMappingURL=protocol.js.map
package/out/server.js CHANGED
@@ -126,7 +126,7 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
126
126
  return __awaiter(this, void 0, void 0, function* () {
127
127
  const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
128
128
  fsHost = runtimeEnv.createFileSystemHost(ts, params.capabilities);
129
- const tsLocalized = params.locale ? runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, params.locale) : undefined;
129
+ const tsLocalized = params.locale ? yield runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, params.locale) : undefined;
130
130
  const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
131
131
  const _projects = (0, workspaces_1.createWorkspaces)(runtimeEnv, plugins, fsHost, configHost, ts, tsLocalized, params.capabilities, options, documents, connection, cancelTokenHost);
132
132
  projects = _projects;
package/out/types.d.ts CHANGED
@@ -11,12 +11,12 @@ export type FileSystemHost = {
11
11
  ready(connection: vscode.Connection): void;
12
12
  clearCache(): void;
13
13
  getWorkspaceFileSystem(rootUri: URI): FileSystem;
14
- onDidChangeWatchedFiles(cb: (params: vscode.DidChangeWatchedFilesParams, reason: 'lsp' | 'web-cache-updated') => void): () => void;
14
+ onDidChangeWatchedFiles(cb: (params: vscode.DidChangeWatchedFilesParams) => void): () => void;
15
15
  };
16
16
  export type FileSystem = Pick<ts.System, 'newLine' | 'useCaseSensitiveFileNames' | 'fileExists' | 'readFile' | 'readDirectory' | 'getCurrentDirectory' | 'realpath' | 'resolvePath'> & Partial<ts.System>;
17
17
  export interface RuntimeEnvironment {
18
18
  loadTypescript: (tsdk: string) => typeof import('typescript/lib/tsserverlibrary');
19
- loadTypescriptLocalized: (tsdk: string, locale: string) => any;
19
+ loadTypescriptLocalized: (tsdk: string, locale: string) => Promise<{} | undefined>;
20
20
  schemaRequestHandlers: {
21
21
  [schema: string]: (uri: string, encoding?: BufferEncoding) => Promise<string>;
22
22
  };
@@ -10,6 +10,7 @@ function loadCustomPlugins(dir) {
10
10
  try {
11
11
  if (configPath) {
12
12
  const config = require(configPath);
13
+ delete require.cache[configPath];
13
14
  return (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
14
15
  }
15
16
  }
@@ -12,6 +12,7 @@ exports.createNodeFileSystemHost = void 0;
12
12
  const vscode = require("vscode-languageserver");
13
13
  const iterableWeakSet_1 = require("./iterableWeakSet");
14
14
  const uriMap_1 = require("./uriMap");
15
+ const shared = require("@volar/shared");
15
16
  let currentCwd = '';
16
17
  function createNodeFileSystemHost(ts, capabilities) {
17
18
  const instances = (0, uriMap_1.createUriMap)();
@@ -27,7 +28,7 @@ function createNodeFileSystemHost(ts, capabilities) {
27
28
  }
28
29
  for (const cb of [...onDidChangeWatchedFilesCb]) {
29
30
  if (onDidChangeWatchedFilesCb.has(cb)) {
30
- yield cb(params, 'lsp');
31
+ yield cb(params);
31
32
  }
32
33
  }
33
34
  }));
@@ -52,15 +53,16 @@ function createNodeFileSystemHost(ts, capabilities) {
52
53
  };
53
54
  function createWorkspaceFileSystem(rootUri) {
54
55
  var _a;
56
+ const rootPath = shared.getPathOfUri(rootUri.toString());
55
57
  const workspaceSys = new Proxy(ts.sys, {
56
58
  get(target, prop) {
57
59
  const fn = target[prop];
58
60
  if (typeof fn === 'function') {
59
61
  return new Proxy(fn, {
60
62
  apply(target, thisArg, args) {
61
- if (currentCwd !== rootUri.fsPath) {
62
- process.chdir(rootUri.fsPath);
63
- currentCwd = rootUri.fsPath;
63
+ if (currentCwd !== rootPath) {
64
+ process.chdir(rootPath);
65
+ currentCwd = rootPath;
64
66
  }
65
67
  return target.apply(thisArg, args);
66
68
  }
@@ -1,4 +1,3 @@
1
- import * as shared from '@volar/shared';
2
1
  import * as embeddedLS from '@volar/language-service';
3
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
3
  import * as vscode from 'vscode-languageserver';
@@ -11,7 +10,7 @@ import { CancellationTokenHost } from './cancellationPipe';
11
10
  export interface Project extends ReturnType<typeof createProject> {
12
11
  }
13
12
  export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost, ts: typeof import('typescript/lib/tsserverlibrary'), rootUri: URI, tsConfig: path.PosixPath | ts.CompilerOptions, tsLocalized: ts.MapLike<string> | undefined, documents: ReturnType<typeof createSnapshots>, configHost: ConfigurationHost | undefined, documentRegistry: ts.DocumentRegistry | undefined, cancelTokenHost: CancellationTokenHost, serverOptions: LanguageServerInitializationOptions): Promise<{
14
- tsConfig: ts.CompilerOptions | path.PosixPath;
13
+ tsConfig: path.PosixPath | ts.CompilerOptions;
15
14
  scripts: {
16
15
  clear: () => void;
17
16
  values: () => IterableIterator<{
@@ -34,20 +33,20 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
34
33
  snapshot: ts.IScriptSnapshot | undefined;
35
34
  snapshotVersion: number | undefined;
36
35
  }) => void;
37
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
38
- pathGet: (rootUri: shared._2.URI, path: string) => {
36
+ pathDelete: (path: string) => boolean;
37
+ pathGet: (path: string) => {
39
38
  version: number;
40
39
  fileName: string;
41
40
  snapshot: ts.IScriptSnapshot | undefined;
42
41
  snapshotVersion: number | undefined;
43
42
  } | undefined;
44
- pathHas: (rootUri: shared._2.URI, path: string) => {
43
+ pathHas: (path: string) => {
45
44
  version: number;
46
45
  fileName: string;
47
46
  snapshot: ts.IScriptSnapshot | undefined;
48
47
  snapshotVersion: number | undefined;
49
48
  } | undefined;
50
- pathSet: (rootUri: shared._2.URI, path: string, item: {
49
+ pathSet: (path: string, item: {
51
50
  version: number;
52
51
  fileName: string;
53
52
  snapshot: ts.IScriptSnapshot | undefined;
@@ -13,7 +13,6 @@ const shared = require("@volar/shared");
13
13
  const embeddedLS = require("@volar/language-service");
14
14
  const embedded = require("@volar/language-core");
15
15
  const vscode = require("vscode-languageserver");
16
- const vscode_uri_1 = require("vscode-uri");
17
16
  const config_1 = require("./config");
18
17
  const path = require("typesafe-path");
19
18
  const uriMap_1 = require("./uriMap");
@@ -30,7 +29,7 @@ function createProject(runtimeEnv, plugins, fsHost, ts, rootUri, tsConfig, tsLoc
30
29
  const disposeWatchEvent = fsHost.onDidChangeWatchedFiles(params => {
31
30
  onWorkspaceFilesChanged(params.changes);
32
31
  });
33
- const disposeDocChange = documents.onDidChangeContent(params => {
32
+ const disposeDocChange = documents.onDidChangeContent(() => {
34
33
  projectVersion++;
35
34
  projectVersionUpdateTime = cancelTokenHost.getMtime();
36
35
  });
@@ -138,7 +137,8 @@ function createProject(runtimeEnv, plugins, fsHost, ts, rootUri, tsConfig, tsLoc
138
137
  return ts.getDefaultLibFilePath(options);
139
138
  }
140
139
  catch (_a) {
141
- return sys.resolvePath('node_modules/typescript/lib/' + ts.getDefaultLibFileName(options)); // web
140
+ // web
141
+ return serverOptions.typescript.tsdk + '/' + ts.getDefaultLibFileName(options);
142
142
  }
143
143
  },
144
144
  getProjectVersion: () => projectVersion.toString(),
@@ -164,18 +164,18 @@ function createProject(runtimeEnv, plugins, fsHost, ts, rootUri, tsConfig, tsLoc
164
164
  return host;
165
165
  function getScriptVersion(fileName) {
166
166
  var _a, _b;
167
- const doc = documents.data.pathGet(rootUri, fileName);
167
+ const doc = documents.data.pathGet(fileName);
168
168
  if (doc) {
169
169
  return doc.version.toString();
170
170
  }
171
- return (_b = (_a = scripts.pathGet(rootUri, fileName)) === null || _a === void 0 ? void 0 : _a.version.toString()) !== null && _b !== void 0 ? _b : '';
171
+ return (_b = (_a = scripts.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.version.toString()) !== null && _b !== void 0 ? _b : '';
172
172
  }
173
173
  function getScriptSnapshot(fileName) {
174
- const doc = documents.data.pathGet(rootUri, fileName);
174
+ const doc = documents.data.pathGet(fileName);
175
175
  if (doc) {
176
176
  return doc.getSnapshot();
177
177
  }
178
- const script = scripts.pathGet(rootUri, fileName);
178
+ const script = scripts.pathGet(fileName);
179
179
  if (script && script.snapshotVersion === script.version) {
180
180
  return script.snapshot;
181
181
  }
@@ -188,7 +188,7 @@ function createProject(runtimeEnv, plugins, fsHost, ts, rootUri, tsConfig, tsLoc
188
188
  script.snapshotVersion = script.version;
189
189
  }
190
190
  else {
191
- scripts.pathSet(rootUri, fileName, {
191
+ scripts.pathSet(fileName, {
192
192
  version: -1,
193
193
  fileName: fileName,
194
194
  snapshot: snapshot,
@@ -256,12 +256,12 @@ function getHTMLDocumentContext(ts, host) {
256
256
  continue;
257
257
  }
258
258
  if (host.fileExists(failed)) {
259
- return isUri ? shared.getUriByPath(vscode_uri_1.URI.parse(base), failed) : failed;
259
+ return isUri ? shared.getUriByPath(failed) : failed;
260
260
  }
261
261
  }
262
262
  for (const dir of dirs) {
263
263
  if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
264
- return isUri ? shared.getUriByPath(vscode_uri_1.URI.parse(base), dir) : dir;
264
+ return isUri ? shared.getUriByPath(dir) : dir;
265
265
  }
266
266
  }
267
267
  return undefined;
@@ -1,6 +1,5 @@
1
1
  import { TextDocument } from 'vscode-languageserver-textdocument';
2
2
  import * as vscode from 'vscode-languageserver';
3
- import * as shared from '@volar/shared';
4
3
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
4
  interface IncrementalScriptSnapshotChange {
6
5
  applied: boolean;
@@ -22,7 +21,7 @@ declare class IncrementalScriptSnapshot {
22
21
  getSnapshot(): ts.IScriptSnapshot;
23
22
  getDocument(): TextDocument;
24
23
  clearUnReferenceVersions(): void;
25
- applyVersionToRootDocument(version: number, removeBeforeVersions: boolean): void;
24
+ applyVersionChanges(version: number, removeBeforeVersions: boolean): void;
26
25
  }
27
26
  export declare function combineContinuousChangeRanges(...changeRanges: ts.TextChangeRange[]): ts.TextChangeRange;
28
27
  export declare function createSnapshots(connection: vscode.Connection): {
@@ -33,10 +32,10 @@ export declare function createSnapshots(connection: vscode.Connection): {
33
32
  uriGet: (_uri: string) => IncrementalScriptSnapshot | undefined;
34
33
  uriHas: (_uri: string) => boolean;
35
34
  uriSet: (_uri: string, item: IncrementalScriptSnapshot) => void;
36
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
37
- pathGet: (rootUri: shared._2.URI, path: string) => IncrementalScriptSnapshot | undefined;
38
- pathHas: (rootUri: shared._2.URI, path: string) => IncrementalScriptSnapshot | undefined;
39
- pathSet: (rootUri: shared._2.URI, path: string, item: IncrementalScriptSnapshot) => void;
35
+ pathDelete: (path: string) => boolean;
36
+ pathGet: (path: string) => IncrementalScriptSnapshot | undefined;
37
+ pathHas: (path: string) => IncrementalScriptSnapshot | undefined;
38
+ pathSet: (path: string, item: IncrementalScriptSnapshot) => void;
40
39
  };
41
40
  onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => () => boolean;
42
41
  onDidClose: (cb: (params: vscode.DidCloseTextDocumentParams) => void) => () => boolean;
@@ -2,7 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.createSnapshots = exports.combineContinuousChangeRanges = void 0;
3
3
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
4
4
  const vscode = require("vscode-languageserver");
5
- const shared = require("@volar/shared");
6
5
  const uriMap_1 = require("./uriMap");
7
6
  class IncrementalScriptSnapshot {
8
7
  constructor(uri, languageId, version, text) {
@@ -37,7 +36,7 @@ class IncrementalScriptSnapshot {
37
36
  this.clearUnReferenceVersions();
38
37
  const lastChange = this.changes[this.changes.length - 1];
39
38
  if (!lastChange.snapshot) {
40
- this.applyVersionToRootDocument(lastChange.version, false);
39
+ this.applyVersionChanges(lastChange.version, false);
41
40
  const text = this.document.getText();
42
41
  const cache = new WeakMap();
43
42
  const snapshot = {
@@ -45,10 +44,11 @@ class IncrementalScriptSnapshot {
45
44
  getLength: () => text.length,
46
45
  getChangeRange: (oldSnapshot) => {
47
46
  if (!cache.has(oldSnapshot)) {
48
- const start = this.changes.findIndex(change => { var _a; return ((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref()) === oldSnapshot; }) + 1;
49
- const end = this.changes.indexOf(lastChange) + 1;
50
- if (start >= 0 && end >= 0) {
51
- const changeRanges = this.changes.slice(start, end).map(change => change.changeRange).filter(shared.notEmpty);
47
+ const oldIndex = this.changes.findIndex(change => { var _a; return ((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref()) === oldSnapshot; });
48
+ if (oldIndex >= 0) {
49
+ const start = oldIndex + 1;
50
+ const end = this.changes.indexOf(lastChange) + 1;
51
+ const changeRanges = this.changes.slice(start, end).map(change => change.changeRange);
52
52
  const result = combineContinuousChangeRanges.apply(null, changeRanges);
53
53
  cache.set(oldSnapshot, result);
54
54
  }
@@ -67,28 +67,30 @@ class IncrementalScriptSnapshot {
67
67
  this.clearUnReferenceVersions();
68
68
  const lastChange = this.changes[this.changes.length - 1];
69
69
  if (!lastChange.applied) {
70
- this.applyVersionToRootDocument(lastChange.version, false);
70
+ this.applyVersionChanges(lastChange.version, false);
71
71
  }
72
72
  return this.document;
73
73
  }
74
74
  clearUnReferenceVersions() {
75
75
  var _a;
76
76
  let versionToApply;
77
- const lastVersion = this.changes[this.changes.length - 1].version;
78
77
  for (let i = 0; i <= this.changes.length - 2; i++) {
79
78
  const change = this.changes[i];
80
- if (change.version !== lastVersion && !((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref())) {
81
- versionToApply = change.version;
79
+ const nextChange = this.changes[i + 1];
80
+ if (!((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref())) {
81
+ if (change.version !== nextChange.version) {
82
+ versionToApply = change.version;
83
+ }
82
84
  }
83
85
  else {
84
86
  break;
85
87
  }
86
88
  }
87
89
  if (versionToApply !== undefined) {
88
- this.applyVersionToRootDocument(versionToApply, true);
90
+ this.applyVersionChanges(versionToApply, true);
89
91
  }
90
92
  }
91
- applyVersionToRootDocument(version, removeBeforeVersions) {
93
+ applyVersionChanges(version, removeBeforeVersions) {
92
94
  let removeEnd = -1;
93
95
  for (let i = 0; i < this.changes.length; i++) {
94
96
  const change = this.changes[i];
@@ -1,4 +1,3 @@
1
- import { URI } from 'vscode-uri';
2
1
  export * as _ from 'vscode-uri';
3
2
  interface Options<T> {
4
3
  delete(key: string): boolean;
@@ -15,8 +14,8 @@ export declare function createUriMap<T>(map?: Options<T>): {
15
14
  uriGet: (_uri: string) => T | undefined;
16
15
  uriHas: (_uri: string) => boolean;
17
16
  uriSet: (_uri: string, item: T) => void;
18
- pathDelete: (rootUri: URI, path: string) => boolean;
19
- pathGet: (rootUri: URI, path: string) => T | undefined;
20
- pathHas: (rootUri: URI, path: string) => T | undefined;
21
- pathSet: (rootUri: URI, path: string, item: T) => void;
17
+ pathDelete: (path: string) => boolean;
18
+ pathGet: (path: string) => T | undefined;
19
+ pathHas: (path: string) => T | undefined;
20
+ pathSet: (path: string, item: T) => void;
22
21
  };
@@ -4,8 +4,8 @@ const vscode_uri_1 = require("vscode-uri");
4
4
  const shared = require("@volar/shared");
5
5
  exports._ = require("vscode-uri");
6
6
  function createUriMap(map = new Map()) {
7
- const uriToUriKeys = new Map();
8
- const pathToUriKeys = new WeakMap();
7
+ const uriToUri = new Map();
8
+ const pathToUri = new Map();
9
9
  return {
10
10
  clear,
11
11
  values,
@@ -19,20 +19,15 @@ function createUriMap(map = new Map()) {
19
19
  pathSet,
20
20
  };
21
21
  function getUriByUri(uri) {
22
- if (!uriToUriKeys.has(uri))
23
- uriToUriKeys.set(uri, normalizeUri(uri).toLowerCase());
24
- return uriToUriKeys.get(uri);
22
+ if (!uriToUri.has(uri))
23
+ uriToUri.set(uri, normalizeUri(uri).toLowerCase());
24
+ return uriToUri.get(uri);
25
25
  }
26
- function getUriByPath(rootUri, path) {
27
- let map = pathToUriKeys.get(rootUri);
28
- if (!map) {
29
- map = new Map();
30
- pathToUriKeys.set(rootUri, map);
26
+ function getUriByPath(path) {
27
+ if (!pathToUri.has(path)) {
28
+ pathToUri.set(path, shared.getUriByPath(path).toLowerCase());
31
29
  }
32
- if (!map.has(path)) {
33
- map.set(path, shared.getUriByPath(rootUri, path).toLowerCase());
34
- }
35
- return map.get(path);
30
+ return pathToUri.get(path);
36
31
  }
37
32
  function clear() {
38
33
  return map.clear();
@@ -52,17 +47,17 @@ function createUriMap(map = new Map()) {
52
47
  function uriSet(_uri, item) {
53
48
  return map.set(getUriByUri(_uri), item);
54
49
  }
55
- function pathDelete(rootUri, path) {
56
- return uriDelete(getUriByPath(rootUri, path));
50
+ function pathDelete(path) {
51
+ return uriDelete(getUriByPath(path));
57
52
  }
58
- function pathGet(rootUri, path) {
59
- return uriGet(getUriByPath(rootUri, path));
53
+ function pathGet(path) {
54
+ return uriGet(getUriByPath(path));
60
55
  }
61
- function pathHas(rootUri, path) {
62
- return uriGet(getUriByPath(rootUri, path));
56
+ function pathHas(path) {
57
+ return uriGet(getUriByPath(path));
63
58
  }
64
- function pathSet(rootUri, path, item) {
65
- return uriSet(getUriByPath(rootUri, path), item);
59
+ function pathSet(path, item) {
60
+ return uriSet(getUriByPath(path), item);
66
61
  }
67
62
  }
68
63
  exports.createUriMap = createUriMap;
@@ -16,6 +16,7 @@ const vscode_uri_1 = require("vscode-uri");
16
16
  const protocol_1 = require("../protocol");
17
17
  const utilities_1 = require("./ts/utilities");
18
18
  const uriMap_1 = require("./uriMap");
19
+ const shared = require("@volar/shared");
19
20
  let currentCwd = '/';
20
21
  function createWebFileSystemHost() {
21
22
  const instances = (0, uriMap_1.createUriMap)();
@@ -26,17 +27,17 @@ function createWebFileSystemHost() {
26
27
  fileTypes: new Map(),
27
28
  searched: false,
28
29
  };
29
- const pendings = new Set();
30
+ const pendings = [];
30
31
  const changes = [];
31
32
  const onReadys = [];
32
- let checking = false;
33
+ let loading = false;
33
34
  let connection;
34
35
  return {
35
36
  ready(_connection) {
36
37
  connection = _connection;
37
38
  connection.onDidChangeWatchedFiles(params => {
38
39
  for (const change of params.changes) {
39
- const fsPath = vscode_uri_1.URI.parse(change.uri).fsPath;
40
+ const fsPath = shared.getPathOfUri(change.uri);
40
41
  const dir = getDir(path.dirname(fsPath));
41
42
  const name = path.basename(fsPath);
42
43
  if (change.type === vscode.FileChangeType.Created) {
@@ -50,7 +51,7 @@ function createWebFileSystemHost() {
50
51
  dir.fileTexts.delete(name);
51
52
  }
52
53
  }
53
- fireChanges(params, 'lsp');
54
+ fireChanges(params);
54
55
  });
55
56
  for (const cb of onReadys) {
56
57
  cb(connection);
@@ -77,10 +78,11 @@ function createWebFileSystemHost() {
77
78
  },
78
79
  };
79
80
  function createWorkspaceFileSystem(rootUri) {
81
+ const rootPath = shared.getPathOfUri(rootUri.toString());
80
82
  return {
81
83
  newLine: '\n',
82
84
  useCaseSensitiveFileNames: false,
83
- getCurrentDirectory: () => rootUri.fsPath,
85
+ getCurrentDirectory: () => shared.getPathOfUri(rootUri.toString()),
84
86
  fileExists,
85
87
  readFile,
86
88
  readDirectory,
@@ -89,9 +91,9 @@ function createWebFileSystemHost() {
89
91
  realpath: path => path, // TODO: cannot implement with vscode
90
92
  };
91
93
  function resolvePath(fsPath) {
92
- if (currentCwd !== rootUri.fsPath) {
93
- process.chdir(rootUri.fsPath);
94
- currentCwd = rootUri.fsPath;
94
+ if (currentCwd !== rootPath) {
95
+ process.chdir(rootPath);
96
+ currentCwd = rootPath;
95
97
  }
96
98
  return path.resolve(fsPath);
97
99
  }
@@ -104,10 +106,10 @@ function createWebFileSystemHost() {
104
106
  }
105
107
  dir.fileTypes.set(name, undefined);
106
108
  if (connection) {
107
- addPending(statAsync(connection, fsPath, dir));
109
+ addPending('Stat', fsPath, statAsync(connection, fsPath, dir));
108
110
  }
109
111
  else {
110
- onReadys.push((connection) => addPending(statAsync(connection, fsPath, dir)));
112
+ onReadys.push((connection) => addPending('Stat', fsPath, statAsync(connection, fsPath, dir)));
111
113
  }
112
114
  return false;
113
115
  }
@@ -120,16 +122,16 @@ function createWebFileSystemHost() {
120
122
  }
121
123
  dir.fileTexts.set(name, '');
122
124
  if (connection) {
123
- addPending(readFileAsync(connection, fsPath, dir));
125
+ addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir));
124
126
  }
125
127
  else {
126
- onReadys.push((connection) => addPending(readFileAsync(connection, fsPath, dir)));
128
+ onReadys.push((connection) => addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir)));
127
129
  }
128
130
  return '';
129
131
  }
130
132
  function readDirectory(fsPath, extensions, exclude, include, depth) {
131
133
  fsPath = resolvePath(fsPath);
132
- return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootUri.fsPath, depth, _dirPath => {
134
+ return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootPath, depth, _dirPath => {
133
135
  let dirPath = _dirPath;
134
136
  dirPath = resolvePath(dirPath);
135
137
  const dir = getDir(dirPath);
@@ -137,10 +139,10 @@ function createWebFileSystemHost() {
137
139
  if (!dir.searched) {
138
140
  dir.searched = true;
139
141
  if (connection) {
140
- addPending(readDirectoryAsync(connection, dirPath, dir));
142
+ addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir));
141
143
  }
142
144
  else {
143
- onReadys.push((connection) => addPending(readDirectoryAsync(connection, dirPath, dir)));
145
+ onReadys.push((connection) => addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir)));
144
146
  }
145
147
  }
146
148
  return {
@@ -157,56 +159,91 @@ function createWebFileSystemHost() {
157
159
  if (!dir.searched) {
158
160
  dir.searched = true;
159
161
  if (connection) {
160
- addPending(readDirectoryAsync(connection, fsPath, dir));
162
+ addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir));
161
163
  }
162
164
  else {
163
- onReadys.push((connection) => addPending(readDirectoryAsync(connection, fsPath, dir)));
165
+ onReadys.push((connection) => addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir)));
164
166
  }
165
167
  }
166
168
  return files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]);
167
169
  }
168
- function getFsPathUri(fsPath) {
169
- return vscode_uri_1.URI.file(fsPath).with({
170
- scheme: rootUri.scheme,
171
- authority: rootUri.authority,
172
- });
173
- }
174
170
  function statAsync(connection, fsPath, dir) {
175
171
  return __awaiter(this, void 0, void 0, function* () {
176
- const uri = getFsPathUri(fsPath);
177
- const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri.toString());
178
- if ((result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.File || (result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.SymbolicLink) {
179
- const name = path.basename(fsPath);
180
- dir.fileTypes.set(name, result.type);
181
- changes.push({
182
- uri: uri.toString(),
183
- type: vscode.FileChangeType.Created,
184
- });
172
+ const uri = shared.getUriByPath(fsPath);
173
+ if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) { // stat request always response file type for jsdelivr
174
+ const text = yield readJsdelivrFile(connection, uri);
175
+ if (text !== undefined) {
176
+ const name = path.basename(fsPath);
177
+ dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File);
178
+ dir.fileTexts.set(name, text);
179
+ changes.push({
180
+ uri: uri,
181
+ type: vscode.FileChangeType.Created,
182
+ });
183
+ }
184
+ }
185
+ else {
186
+ const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri);
187
+ if ((result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.File || (result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.SymbolicLink) {
188
+ const name = path.basename(fsPath);
189
+ dir.fileTypes.set(name, result.type);
190
+ changes.push({
191
+ uri: uri,
192
+ type: vscode.FileChangeType.Created,
193
+ });
194
+ }
185
195
  }
186
196
  });
187
197
  }
188
198
  function readFileAsync(connection, fsPath, dir) {
189
199
  return __awaiter(this, void 0, void 0, function* () {
190
- const uri = getFsPathUri(fsPath);
191
- const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri.toString());
192
- if (text) {
193
- const name = path.basename(fsPath);
194
- dir.fileTexts.set(name, text);
195
- changes.push({
196
- uri: uri.toString(),
197
- type: vscode.FileChangeType.Changed,
198
- });
200
+ const uri = shared.getUriByPath(fsPath);
201
+ if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) {
202
+ const text = yield readJsdelivrFile(connection, uri);
203
+ if (text !== undefined) {
204
+ const name = path.basename(fsPath);
205
+ dir.fileTexts.set(name, text);
206
+ changes.push({
207
+ uri: uri,
208
+ type: vscode.FileChangeType.Changed,
209
+ });
210
+ }
211
+ }
212
+ else {
213
+ const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri);
214
+ if (text) {
215
+ const name = path.basename(fsPath);
216
+ dir.fileTexts.set(name, text);
217
+ changes.push({
218
+ uri: uri,
219
+ type: vscode.FileChangeType.Changed,
220
+ });
221
+ }
222
+ }
223
+ });
224
+ }
225
+ function readJsdelivrFile(connection, uri) {
226
+ var _a;
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ // ignore .js because it's no help for intellisense
229
+ if (uri.endsWith('.d.ts') || uri.endsWith('.json')) {
230
+ const text = (_a = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri)) !== null && _a !== void 0 ? _a : undefined;
231
+ if (text !== undefined
232
+ // ignore https://cdn.jsdelivr.net/npm/@vue/runtime-dom
233
+ && text.indexOf('Minified by jsDelivr') === -1) {
234
+ return text;
235
+ }
199
236
  }
200
237
  });
201
238
  }
202
239
  function readDirectoryAsync(connection, fsPath, dir) {
203
240
  return __awaiter(this, void 0, void 0, function* () {
204
- const uri = getFsPathUri(fsPath);
205
- const result = yield connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, uri.toString());
241
+ const uri = shared.getUriByPath(fsPath);
242
+ const result = yield connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, uri);
206
243
  for (const [name, fileType] of result) {
207
244
  if (dir.fileTypes.get(name) !== fileType && (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink)) {
208
245
  changes.push({
209
- uri: getFsPathUri(path.join(fsPath, name)).toString(),
246
+ uri: shared.getUriByPath(path.join(fsPath, name)),
210
247
  type: vscode.FileChangeType.Created,
211
248
  });
212
249
  }
@@ -215,29 +252,34 @@ function createWebFileSystemHost() {
215
252
  });
216
253
  }
217
254
  }
218
- function addPending(p) {
255
+ function addPending(action, fileName, p) {
219
256
  return __awaiter(this, void 0, void 0, function* () {
220
- pendings.add(p);
221
- if (checking === false) {
222
- checking = true;
223
- while (pendings.size > 0) {
224
- const _pendings = [...pendings];
225
- pendings.clear();
226
- yield Promise.all(_pendings);
257
+ pendings.push([action, fileName, p]);
258
+ if (loading === false) {
259
+ loading = true;
260
+ const progress = yield (connection === null || connection === void 0 ? void 0 : connection.window.createWorkDoneProgress());
261
+ progress === null || progress === void 0 ? void 0 : progress.begin(action);
262
+ let i = 0;
263
+ while (pendings.length) {
264
+ const current = pendings.shift();
265
+ progress === null || progress === void 0 ? void 0 : progress.report(i / pendings.length, vscode_uri_1.URI.parse(shared.getUriByPath(current[1])).fsPath);
266
+ yield current;
267
+ i++;
227
268
  }
269
+ progress === null || progress === void 0 ? void 0 : progress.done();
228
270
  if (changes.length) {
229
- fireChanges({ changes: [...changes] }, 'web-cache-updated');
271
+ fireChanges({ changes: [...changes] });
230
272
  changes.length = 0;
231
273
  }
232
- checking = false;
274
+ loading = false;
233
275
  }
234
276
  });
235
277
  }
236
- function fireChanges(params, reason) {
278
+ function fireChanges(params) {
237
279
  return __awaiter(this, void 0, void 0, function* () {
238
280
  for (const cb of [...onDidChangeWatchedFilesCb]) {
239
281
  if (onDidChangeWatchedFilesCb.has(cb)) {
240
- yield cb(params, reason);
282
+ yield cb(params);
241
283
  }
242
284
  }
243
285
  });
@@ -1,4 +1,3 @@
1
- import * as shared from '@volar/shared';
2
1
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
2
  import * as path from 'typesafe-path';
4
3
  import * as vscode from 'vscode-languageserver';
@@ -17,16 +16,16 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
17
16
  uriGet: (_uri: string) => Project | undefined;
18
17
  uriHas: (_uri: string) => boolean;
19
18
  uriSet: (_uri: string, item: Project) => void;
20
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
21
- pathGet: (rootUri: shared._2.URI, path: string) => Project | undefined;
22
- pathHas: (rootUri: shared._2.URI, path: string) => Project | undefined;
23
- pathSet: (rootUri: shared._2.URI, path: string, item: Project) => void;
19
+ pathDelete: (path: string) => boolean;
20
+ pathGet: (path: string) => Project | undefined;
21
+ pathHas: (path: string) => Project | undefined;
22
+ pathSet: (path: string, item: Project) => void;
24
23
  };
25
24
  documentRegistry: ts.DocumentRegistry;
26
25
  getProjectAndTsConfig: (uri: string) => Promise<{
27
26
  tsconfig: string;
28
27
  project: {
29
- tsConfig: ts.CompilerOptions | path.PosixPath;
28
+ tsConfig: path.PosixPath | ts.CompilerOptions;
30
29
  scripts: {
31
30
  clear: () => void;
32
31
  values: () => IterableIterator<{
@@ -49,20 +48,20 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
49
48
  snapshot: ts.IScriptSnapshot | undefined;
50
49
  snapshotVersion: number | undefined;
51
50
  }) => void;
52
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
53
- pathGet: (rootUri: shared._2.URI, path: string) => {
51
+ pathDelete: (path: string) => boolean;
52
+ pathGet: (path: string) => {
54
53
  version: number;
55
54
  fileName: string;
56
55
  snapshot: ts.IScriptSnapshot | undefined;
57
56
  snapshotVersion: number | undefined;
58
57
  } | undefined;
59
- pathHas: (rootUri: shared._2.URI, path: string) => {
58
+ pathHas: (path: string) => {
60
59
  version: number;
61
60
  fileName: string;
62
61
  snapshot: ts.IScriptSnapshot | undefined;
63
62
  snapshotVersion: number | undefined;
64
63
  } | undefined;
65
- pathSet: (rootUri: shared._2.URI, path: string, item: {
64
+ pathSet: (path: string, item: {
66
65
  version: number;
67
66
  fileName: string;
68
67
  snapshot: ts.IScriptSnapshot | undefined;
@@ -160,4 +159,4 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
160
159
  reload: () => void;
161
160
  dispose(): void;
162
161
  }>;
163
- export declare function sortTsConfigs(fsPath: path.OsPath, a: path.OsPath, b: path.OsPath): number;
162
+ export declare function sortTsConfigs(file: path.PosixPath, a: path.PosixPath, b: path.PosixPath): number;
@@ -21,21 +21,21 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  let inferredProject;
23
23
  const sys = fsHost.getWorkspaceFileSystem(rootUri);
24
- const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.normalizeFileName(rootUri.fsPath));
24
+ const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.getPathOfUri(rootUri.toString()));
25
25
  const projects = (0, uriMap_1.createUriMap)();
26
- const rootTsConfigs = new Set(sys.readDirectory(rootUri.fsPath, exports.rootTsConfigNames, undefined, ['**/*']));
27
- const disposeWatch = fsHost.onDidChangeWatchedFiles((params, reason) => __awaiter(this, void 0, void 0, function* () {
26
+ const rootTsConfigs = new Set(sys.readDirectory(shared.getPathOfUri(rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
27
+ const disposeWatch = fsHost.onDidChangeWatchedFiles((params) => __awaiter(this, void 0, void 0, function* () {
28
28
  const disposes = [];
29
29
  for (const change of params.changes) {
30
30
  if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
31
31
  if (change.type === vscode.FileChangeType.Created) {
32
- if (shared.isFileInDir(vscode_uri_1.URI.parse(change.uri).fsPath, rootUri.fsPath)) {
33
- rootTsConfigs.add(vscode_uri_1.URI.parse(change.uri).fsPath);
32
+ if (shared.isFileInDir(shared.getPathOfUri(change.uri), shared.getPathOfUri(rootUri.toString()))) {
33
+ rootTsConfigs.add(shared.getPathOfUri(change.uri));
34
34
  }
35
35
  }
36
36
  else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && projects.uriHas(change.uri)) {
37
37
  if (change.type === vscode.FileChangeType.Deleted) {
38
- rootTsConfigs.delete(vscode_uri_1.URI.parse(change.uri).fsPath);
38
+ rootTsConfigs.delete(shared.getPathOfUri(change.uri));
39
39
  }
40
40
  const _project = projects.uriGet(change.uri);
41
41
  projects.uriDelete(change.uri);
@@ -46,9 +46,6 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
46
46
  }
47
47
  }
48
48
  }
49
- if (reason === 'web-cache-updated' && params.changes.some(change => change.uri.indexOf('/node_modules/') >= 0)) {
50
- clearProjects();
51
- }
52
49
  return Promise.all(disposes);
53
50
  }));
54
51
  return {
@@ -105,11 +102,11 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
105
102
  return __awaiter(this, void 0, void 0, function* () {
106
103
  let matches = [];
107
104
  for (const rootTsConfig of rootTsConfigs) {
108
- if (shared.isFileInDir(uri.fsPath, path.dirname(rootTsConfig))) {
105
+ if (shared.isFileInDir(shared.getPathOfUri(uri.toString()), path.dirname(rootTsConfig))) {
109
106
  matches.push(rootTsConfig);
110
107
  }
111
108
  }
112
- matches = matches.sort((a, b) => sortTsConfigs(uri.fsPath, a, b));
109
+ matches = matches.sort((a, b) => sortTsConfigs(shared.getPathOfUri(uri.toString()), a, b));
113
110
  if (matches.length) {
114
111
  yield getParsedCommandLine(matches[0]);
115
112
  }
@@ -117,16 +114,18 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
117
114
  }
118
115
  function findDirectIncludeTsconfig() {
119
116
  return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
117
+ const map = (0, uriMap_1.createUriMap)();
120
118
  const parsedCommandLine = yield getParsedCommandLine(tsconfig);
121
- // use toLowerCase to fix https://github.com/johnsoncodehk/volar/issues/1125
122
- const fileNames = new Set(parsedCommandLine.fileNames.map(fileName => shared.normalizeFileName(fileName.toLowerCase())));
123
- return fileNames.has(shared.normalizeFileName(uri.fsPath.toLowerCase()));
119
+ for (const fileName of parsedCommandLine.fileNames) {
120
+ map.pathSet(fileName, true);
121
+ }
122
+ return map.uriHas(uri.toString());
124
123
  }));
125
124
  }
126
125
  function findIndirectReferenceTsconfig() {
127
126
  return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
128
127
  var _a;
129
- const project = yield projects.pathGet(rootUri, tsconfig);
128
+ const project = yield projects.pathGet(tsconfig);
130
129
  const ls = project === null || project === void 0 ? void 0 : project.getLanguageServiceDontCreate();
131
130
  const validDoc = (_a = ls === null || ls === void 0 ? void 0 : ls.context.typescriptLanguageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(shared.getPathOfUri(uri.toString()));
132
131
  return !!validDoc;
@@ -135,8 +134,8 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
135
134
  function findTsconfig(match) {
136
135
  return __awaiter(this, void 0, void 0, function* () {
137
136
  const checked = new Set();
138
- for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(uri.fsPath, a, b))) {
139
- const project = yield projects.pathGet(rootUri, rootTsConfig);
137
+ for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(shared.getPathOfUri(uri.toString()), a, b))) {
138
+ const project = yield projects.pathGet(rootTsConfig);
140
139
  if (project) {
141
140
  let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
142
141
  if (serverOptions.reverseConfigFilePriority) {
@@ -203,26 +202,26 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
203
202
  }
204
203
  function getProjectByCreate(_tsConfig) {
205
204
  const tsConfig = shared.normalizeFileName(_tsConfig);
206
- let project = projects.pathGet(rootUri, tsConfig);
205
+ let project = projects.pathGet(tsConfig);
207
206
  if (!project) {
208
- project = (0, project_1.createProject)(runtimeEnv, plugins, fsHost, ts, vscode_uri_1.URI.parse(shared.getUriByPath(rootUri, path.dirname(tsConfig))), tsConfig, tsLocalized, documents, configHost, documentRegistry, cancelTokenHost, serverOptions);
209
- projects.pathSet(rootUri, tsConfig, project);
207
+ project = (0, project_1.createProject)(runtimeEnv, plugins, fsHost, ts, vscode_uri_1.URI.parse(shared.getUriByPath(path.dirname(tsConfig))), tsConfig, tsLocalized, documents, configHost, documentRegistry, cancelTokenHost, serverOptions);
208
+ projects.pathSet(tsConfig, project);
210
209
  }
211
210
  return project;
212
211
  }
213
212
  });
214
213
  }
215
214
  exports.createWorkspaceProjects = createWorkspaceProjects;
216
- function sortTsConfigs(fsPath, a, b) {
217
- const inA = shared.isFileInDir(fsPath, path.dirname(a));
218
- const inB = shared.isFileInDir(fsPath, path.dirname(b));
215
+ function sortTsConfigs(file, a, b) {
216
+ const inA = shared.isFileInDir(file, path.dirname(a));
217
+ const inB = shared.isFileInDir(file, path.dirname(b));
219
218
  if (inA !== inB) {
220
219
  const aWeight = inA ? 1 : 0;
221
220
  const bWeight = inB ? 1 : 0;
222
221
  return bWeight - aWeight;
223
222
  }
224
- const aLength = shared.normalizeFileName(a).split('/').length;
225
- const bLength = shared.normalizeFileName(b).split('/').length;
223
+ const aLength = a.split('/').length;
224
+ const bLength = b.split('/').length;
226
225
  if (aLength === bLength) {
227
226
  const aWeight = path.basename(a) === 'tsconfig.json' ? 1 : 0;
228
227
  const bWeight = path.basename(b) === 'tsconfig.json' ? 1 : 0;
@@ -1,11 +1,9 @@
1
- import * as shared from '@volar/shared';
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';
5
4
  import { URI } from 'vscode-uri';
6
5
  import { FileSystemHost, LanguageServerPlugin, RuntimeEnvironment, LanguageServerInitializationOptions } from '../types';
7
6
  import { createSnapshots } from './snapshots';
8
- import * as path from 'typesafe-path';
9
7
  import { CancellationTokenHost } from './cancellationPipe';
10
8
  export interface Workspaces extends ReturnType<typeof createWorkspaces> {
11
9
  }
@@ -18,16 +16,16 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
18
16
  uriGet: (_uri: string) => import("./project").Project | undefined;
19
17
  uriHas: (_uri: string) => boolean;
20
18
  uriSet: (_uri: string, item: import("./project").Project) => void;
21
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
22
- pathGet: (rootUri: shared._2.URI, path: string) => import("./project").Project | undefined;
23
- pathHas: (rootUri: shared._2.URI, path: string) => import("./project").Project | undefined;
24
- pathSet: (rootUri: shared._2.URI, path: string, item: import("./project").Project) => void;
19
+ pathDelete: (path: string) => boolean;
20
+ pathGet: (path: string) => import("./project").Project | undefined;
21
+ pathHas: (path: string) => import("./project").Project | undefined;
22
+ pathSet: (path: string, item: import("./project").Project) => void;
25
23
  };
26
24
  documentRegistry: ts.DocumentRegistry;
27
25
  getProjectAndTsConfig: (uri: string) => Promise<{
28
26
  tsconfig: string;
29
27
  project: {
30
- tsConfig: ts.CompilerOptions | path.PosixPath;
28
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
31
29
  scripts: {
32
30
  clear: () => void;
33
31
  values: () => IterableIterator<{
@@ -50,20 +48,20 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
50
48
  snapshot: ts.IScriptSnapshot | undefined;
51
49
  snapshotVersion: number | undefined;
52
50
  }) => void;
53
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
54
- pathGet: (rootUri: shared._2.URI, path: string) => {
51
+ pathDelete: (path: string) => boolean;
52
+ pathGet: (path: string) => {
55
53
  version: number;
56
54
  fileName: string;
57
55
  snapshot: ts.IScriptSnapshot | undefined;
58
56
  snapshotVersion: number | undefined;
59
57
  } | undefined;
60
- pathHas: (rootUri: shared._2.URI, path: string) => {
58
+ pathHas: (path: string) => {
61
59
  version: number;
62
60
  fileName: string;
63
61
  snapshot: ts.IScriptSnapshot | undefined;
64
62
  snapshotVersion: number | undefined;
65
63
  } | undefined;
66
- pathSet: (rootUri: shared._2.URI, path: string, item: {
64
+ pathSet: (path: string, item: {
67
65
  version: number;
68
66
  fileName: string;
69
67
  snapshot: ts.IScriptSnapshot | undefined;
@@ -164,7 +162,7 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
164
162
  getProject: (uri: string) => Promise<{
165
163
  tsconfig: string;
166
164
  project: {
167
- tsConfig: ts.CompilerOptions | path.PosixPath;
165
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
168
166
  scripts: {
169
167
  clear: () => void;
170
168
  values: () => IterableIterator<{
@@ -187,20 +185,20 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
187
185
  snapshot: ts.IScriptSnapshot | undefined;
188
186
  snapshotVersion: number | undefined;
189
187
  }) => void;
190
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
191
- pathGet: (rootUri: shared._2.URI, path: string) => {
188
+ pathDelete: (path: string) => boolean;
189
+ pathGet: (path: string) => {
192
190
  version: number;
193
191
  fileName: string;
194
192
  snapshot: ts.IScriptSnapshot | undefined;
195
193
  snapshotVersion: number | undefined;
196
194
  } | undefined;
197
- pathHas: (rootUri: shared._2.URI, path: string) => {
195
+ pathHas: (path: string) => {
198
196
  version: number;
199
197
  fileName: string;
200
198
  snapshot: ts.IScriptSnapshot | undefined;
201
199
  snapshotVersion: number | undefined;
202
200
  } | undefined;
203
- pathSet: (rootUri: shared._2.URI, path: string, item: {
201
+ pathSet: (path: string, item: {
204
202
  version: number;
205
203
  fileName: string;
206
204
  snapshot: ts.IScriptSnapshot | undefined;
@@ -295,7 +293,7 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
295
293
  } | {
296
294
  tsconfig: undefined;
297
295
  project: {
298
- tsConfig: ts.CompilerOptions | path.PosixPath;
296
+ tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions;
299
297
  scripts: {
300
298
  clear: () => void;
301
299
  values: () => IterableIterator<{
@@ -318,20 +316,20 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
318
316
  snapshot: ts.IScriptSnapshot | undefined;
319
317
  snapshotVersion: number | undefined;
320
318
  }) => void;
321
- pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
322
- pathGet: (rootUri: shared._2.URI, path: string) => {
319
+ pathDelete: (path: string) => boolean;
320
+ pathGet: (path: string) => {
323
321
  version: number;
324
322
  fileName: string;
325
323
  snapshot: ts.IScriptSnapshot | undefined;
326
324
  snapshotVersion: number | undefined;
327
325
  } | undefined;
328
- pathHas: (rootUri: shared._2.URI, path: string) => {
326
+ pathHas: (path: string) => {
329
327
  version: number;
330
328
  fileName: string;
331
329
  snapshot: ts.IScriptSnapshot | undefined;
332
330
  snapshotVersion: number | undefined;
333
331
  } | undefined;
334
- pathSet: (rootUri: shared._2.URI, path: string, item: {
332
+ pathSet: (path: string, item: {
335
333
  version: number;
336
334
  fileName: string;
337
335
  snapshot: ts.IScriptSnapshot | undefined;
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.createWorkspaces = void 0;
12
12
  const shared = require("@volar/shared");
13
13
  const vscode = require("vscode-languageserver");
14
- const vscode_uri_1 = require("vscode-uri");
15
14
  const types_1 = require("../types");
16
15
  const workspaceProjects_1 = require("./workspaceProjects");
17
16
  function createWorkspaces(runtimeEnv, plugins, fsHost, configurationHost, ts, tsLocalized, client, options, documents, connection, cancelTokenHost) {
@@ -141,9 +140,8 @@ function createWorkspaces(runtimeEnv, plugins, fsHost, configurationHost, ts, ts
141
140
  var _a;
142
141
  return __awaiter(this, void 0, void 0, function* () {
143
142
  const rootUris = [...workspaces.keys()]
144
- .filter(rootUri => vscode_uri_1.URI.parse(rootUri).scheme === vscode_uri_1.URI.parse(uri).scheme) // fix https://github.com/johnsoncodehk/volar/issues/1946#issuecomment-1272430742
145
- .filter(rootUri => shared.isFileInDir(vscode_uri_1.URI.parse(uri).fsPath, vscode_uri_1.URI.parse(rootUri).fsPath))
146
- .sort((a, b) => (0, workspaceProjects_1.sortTsConfigs)(vscode_uri_1.URI.parse(uri).fsPath, vscode_uri_1.URI.parse(a).fsPath, vscode_uri_1.URI.parse(b).fsPath));
143
+ .filter(rootUri => shared.isFileInDir(shared.getPathOfUri(uri), shared.getPathOfUri(rootUri)))
144
+ .sort((a, b) => (0, workspaceProjects_1.sortTsConfigs)(shared.getPathOfUri(uri), shared.getPathOfUri(a), shared.getPathOfUri(b)));
147
145
  for (const rootUri of rootUris) {
148
146
  const workspace = yield workspaces.get(rootUri);
149
147
  const project = yield (workspace === null || workspace === void 0 ? void 0 : workspace.getProjectAndTsConfig(uri));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
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.11",
21
- "@volar/language-service": "1.0.11",
22
- "@volar/shared": "1.0.11",
20
+ "@volar/language-core": "1.0.13",
21
+ "@volar/language-service": "1.0.13",
22
+ "@volar/shared": "1.0.13",
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.7",
29
29
  "vscode-uri": "^3.0.6"
30
30
  },
31
- "gitHead": "aff3d7c0896a391412a605597adca7d796e9accf"
31
+ "gitHead": "cba2eba187b2d82e1d45dd86b3edeab0ca7caad6"
32
32
  }