@volar/language-server 1.0.11 → 1.0.12

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
@@ -25,10 +25,10 @@ function createLanguageServer(plugins) {
25
25
  const messageWriter = new vscode.BrowserMessageWriter(self);
26
26
  const connection = vscode.createConnection(messageReader, messageWriter);
27
27
  (0, server_1.createCommonLanguageServer)(connection, {
28
- loadTypescript(options) {
28
+ loadTypescript() {
29
29
  return ts; // not support load by user config in web
30
30
  },
31
- loadTypescriptLocalized(options) {
31
+ loadTypescriptLocalized() {
32
32
  // TODO
33
33
  },
34
34
  schemaRequestHandlers: {
@@ -103,9 +103,9 @@ function register(connection, projects) {
103
103
  }
104
104
  }
105
105
  }));
106
- connection.onNotification(protocol_1.ReloadProjectNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
106
+ connection.onNotification(protocol_1.ReloadProjectNotification.type, () => {
107
107
  projects.reloadProject();
108
- }));
108
+ });
109
109
  connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
110
110
  var _s;
111
111
  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 => {
@@ -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)();
@@ -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
  }
@@ -11,7 +11,7 @@ import { CancellationTokenHost } from './cancellationPipe';
11
11
  export interface Project extends ReturnType<typeof createProject> {
12
12
  }
13
13
  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;
14
+ tsConfig: path.PosixPath | ts.CompilerOptions;
15
15
  scripts: {
16
16
  clear: () => void;
17
17
  values: () => IterableIterator<{
@@ -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 shared.getPathOfUri(serverOptions.typescript.tsdk + '/' + ts.getDefaultLibFileName(options));
142
142
  }
143
143
  },
144
144
  getProjectVersion: () => projectVersion.toString(),
@@ -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,7 +1,7 @@
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';
4
+ import type * as _ from 'vscode-uri';
5
5
  interface IncrementalScriptSnapshotChange {
6
6
  applied: boolean;
7
7
  changeRange: ts.TextChangeRange | undefined;
@@ -22,7 +22,7 @@ declare class IncrementalScriptSnapshot {
22
22
  getSnapshot(): ts.IScriptSnapshot;
23
23
  getDocument(): TextDocument;
24
24
  clearUnReferenceVersions(): void;
25
- applyVersionToRootDocument(version: number, removeBeforeVersions: boolean): void;
25
+ applyVersionChanges(version: number, removeBeforeVersions: boolean): void;
26
26
  }
27
27
  export declare function combineContinuousChangeRanges(...changeRanges: ts.TextChangeRange[]): ts.TextChangeRange;
28
28
  export declare function createSnapshots(connection: vscode.Connection): {
@@ -33,10 +33,10 @@ export declare function createSnapshots(connection: vscode.Connection): {
33
33
  uriGet: (_uri: string) => IncrementalScriptSnapshot | undefined;
34
34
  uriHas: (_uri: string) => boolean;
35
35
  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;
36
+ pathDelete: (rootUri: _.URI, path: string) => boolean;
37
+ pathGet: (rootUri: _.URI, path: string) => IncrementalScriptSnapshot | undefined;
38
+ pathHas: (rootUri: _.URI, path: string) => IncrementalScriptSnapshot | undefined;
39
+ pathSet: (rootUri: _.URI, path: string, item: IncrementalScriptSnapshot) => void;
40
40
  };
41
41
  onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => () => boolean;
42
42
  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];
@@ -30,7 +30,7 @@ function createUriMap(map = new Map()) {
30
30
  pathToUriKeys.set(rootUri, map);
31
31
  }
32
32
  if (!map.has(path)) {
33
- map.set(path, shared.getUriByPath(rootUri, path).toLowerCase());
33
+ map.set(path, shared.getUriByPath(path).toLowerCase());
34
34
  }
35
35
  return map.get(path);
36
36
  }
@@ -12,10 +12,10 @@ exports.createWebFileSystemHost = void 0;
12
12
  const path = require("typesafe-path");
13
13
  const vscode_html_languageservice_1 = require("vscode-html-languageservice");
14
14
  const vscode = require("vscode-languageserver");
15
- const vscode_uri_1 = require("vscode-uri");
16
15
  const protocol_1 = require("../protocol");
17
16
  const utilities_1 = require("./ts/utilities");
18
17
  const uriMap_1 = require("./uriMap");
18
+ const shared = require("@volar/shared");
19
19
  let currentCwd = '/';
20
20
  function createWebFileSystemHost() {
21
21
  const instances = (0, uriMap_1.createUriMap)();
@@ -36,7 +36,7 @@ function createWebFileSystemHost() {
36
36
  connection = _connection;
37
37
  connection.onDidChangeWatchedFiles(params => {
38
38
  for (const change of params.changes) {
39
- const fsPath = vscode_uri_1.URI.parse(change.uri).fsPath;
39
+ const fsPath = shared.getPathOfUri(change.uri);
40
40
  const dir = getDir(path.dirname(fsPath));
41
41
  const name = path.basename(fsPath);
42
42
  if (change.type === vscode.FileChangeType.Created) {
@@ -77,10 +77,11 @@ function createWebFileSystemHost() {
77
77
  },
78
78
  };
79
79
  function createWorkspaceFileSystem(rootUri) {
80
+ const rootPath = shared.getPathOfUri(rootUri.toString());
80
81
  return {
81
82
  newLine: '\n',
82
83
  useCaseSensitiveFileNames: false,
83
- getCurrentDirectory: () => rootUri.fsPath,
84
+ getCurrentDirectory: () => shared.getPathOfUri(rootUri.toString()),
84
85
  fileExists,
85
86
  readFile,
86
87
  readDirectory,
@@ -89,9 +90,9 @@ function createWebFileSystemHost() {
89
90
  realpath: path => path, // TODO: cannot implement with vscode
90
91
  };
91
92
  function resolvePath(fsPath) {
92
- if (currentCwd !== rootUri.fsPath) {
93
- process.chdir(rootUri.fsPath);
94
- currentCwd = rootUri.fsPath;
93
+ if (currentCwd !== rootPath) {
94
+ process.chdir(rootPath);
95
+ currentCwd = rootPath;
95
96
  }
96
97
  return path.resolve(fsPath);
97
98
  }
@@ -129,7 +130,7 @@ function createWebFileSystemHost() {
129
130
  }
130
131
  function readDirectory(fsPath, extensions, exclude, include, depth) {
131
132
  fsPath = resolvePath(fsPath);
132
- return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootUri.fsPath, depth, _dirPath => {
133
+ return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootPath, depth, _dirPath => {
133
134
  let dirPath = _dirPath;
134
135
  dirPath = resolvePath(dirPath);
135
136
  const dir = getDir(dirPath);
@@ -165,21 +166,15 @@ function createWebFileSystemHost() {
165
166
  }
166
167
  return files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]);
167
168
  }
168
- function getFsPathUri(fsPath) {
169
- return vscode_uri_1.URI.file(fsPath).with({
170
- scheme: rootUri.scheme,
171
- authority: rootUri.authority,
172
- });
173
- }
174
169
  function statAsync(connection, fsPath, dir) {
175
170
  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());
171
+ const uri = shared.getUriByPath(fsPath);
172
+ const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri);
178
173
  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
174
  const name = path.basename(fsPath);
180
175
  dir.fileTypes.set(name, result.type);
181
176
  changes.push({
182
- uri: uri.toString(),
177
+ uri: uri,
183
178
  type: vscode.FileChangeType.Created,
184
179
  });
185
180
  }
@@ -187,13 +182,13 @@ function createWebFileSystemHost() {
187
182
  }
188
183
  function readFileAsync(connection, fsPath, dir) {
189
184
  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());
185
+ const uri = shared.getUriByPath(fsPath);
186
+ const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri);
192
187
  if (text) {
193
188
  const name = path.basename(fsPath);
194
189
  dir.fileTexts.set(name, text);
195
190
  changes.push({
196
- uri: uri.toString(),
191
+ uri: uri,
197
192
  type: vscode.FileChangeType.Changed,
198
193
  });
199
194
  }
@@ -201,12 +196,12 @@ function createWebFileSystemHost() {
201
196
  }
202
197
  function readDirectoryAsync(connection, fsPath, dir) {
203
198
  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());
199
+ const uri = shared.getUriByPath(fsPath);
200
+ const result = yield connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, uri);
206
201
  for (const [name, fileType] of result) {
207
202
  if (dir.fileTypes.get(name) !== fileType && (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink)) {
208
203
  changes.push({
209
- uri: getFsPathUri(path.join(fsPath, name)).toString(),
204
+ uri: shared.getUriByPath(path.join(fsPath, name)),
210
205
  type: vscode.FileChangeType.Created,
211
206
  });
212
207
  }
@@ -26,7 +26,7 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
26
26
  getProjectAndTsConfig: (uri: string) => Promise<{
27
27
  tsconfig: string;
28
28
  project: {
29
- tsConfig: ts.CompilerOptions | path.PosixPath;
29
+ tsConfig: path.PosixPath | ts.CompilerOptions;
30
30
  scripts: {
31
31
  clear: () => void;
32
32
  values: () => IterableIterator<{
@@ -205,7 +205,7 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
205
205
  const tsConfig = shared.normalizeFileName(_tsConfig);
206
206
  let project = projects.pathGet(rootUri, tsConfig);
207
207
  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);
208
+ 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);
209
209
  projects.pathSet(rootUri, tsConfig, project);
210
210
  }
211
211
  return project;
@@ -27,7 +27,7 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
27
27
  getProjectAndTsConfig: (uri: string) => Promise<{
28
28
  tsconfig: string;
29
29
  project: {
30
- tsConfig: ts.CompilerOptions | path.PosixPath;
30
+ tsConfig: path.PosixPath | ts.CompilerOptions;
31
31
  scripts: {
32
32
  clear: () => void;
33
33
  values: () => IterableIterator<{
@@ -164,7 +164,7 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
164
164
  getProject: (uri: string) => Promise<{
165
165
  tsconfig: string;
166
166
  project: {
167
- tsConfig: ts.CompilerOptions | path.PosixPath;
167
+ tsConfig: path.PosixPath | ts.CompilerOptions;
168
168
  scripts: {
169
169
  clear: () => void;
170
170
  values: () => IterableIterator<{
@@ -295,7 +295,7 @@ export declare function createWorkspaces(runtimeEnv: RuntimeEnvironment, plugins
295
295
  } | {
296
296
  tsconfig: undefined;
297
297
  project: {
298
- tsConfig: ts.CompilerOptions | path.PosixPath;
298
+ tsConfig: path.PosixPath | ts.CompilerOptions;
299
299
  scripts: {
300
300
  clear: () => void;
301
301
  values: () => IterableIterator<{
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.12",
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.12",
21
+ "@volar/language-service": "1.0.12",
22
+ "@volar/shared": "1.0.12",
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": "2426aa8ec6731a6f6d88086da7021a32d9306de3"
32
32
  }