@volar/language-server 1.3.0-alpha.3 → 1.4.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.createWorkspaces = void 0;
12
- const shared = require("@volar/shared");
2
+ exports.sleep = exports.createWorkspaces = void 0;
13
3
  const vscode = require("vscode-languageserver");
14
4
  const types_1 = require("../types");
15
5
  const workspace_1 = require("./workspace");
16
6
  const isFileInDir_1 = require("./utils/isFileInDir");
17
7
  function createWorkspaces(context) {
18
- var _a, _b, _c;
19
8
  const uriToFileName = context.server.runtimeEnv.uriToFileName;
20
9
  const workspaces = new Map();
21
10
  let semanticTokensReq = 0;
@@ -26,7 +15,7 @@ function createWorkspaces(context) {
26
15
  context.documents.onDidClose(({ textDocument }) => {
27
16
  context.server.connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
28
17
  });
29
- (_a = context.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(({ changes }) => {
18
+ context.fileSystemHost?.onDidChangeWatchedFiles(({ changes }) => {
30
19
  const tsConfigChanges = changes.filter(change => workspace_1.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
31
20
  if (tsConfigChanges.length) {
32
21
  reloadDiagnostics();
@@ -35,9 +24,9 @@ function createWorkspaces(context) {
35
24
  updateDiagnosticsAndSemanticTokens();
36
25
  }
37
26
  });
38
- (_c = (_b = context.server.runtimeEnv).onDidChangeConfiguration) === null || _c === void 0 ? void 0 : _c.call(_b, () => __awaiter(this, void 0, void 0, function* () {
27
+ context.server.runtimeEnv.onDidChangeConfiguration?.(async () => {
39
28
  updateDiagnosticsAndSemanticTokens();
40
- }));
29
+ });
41
30
  return {
42
31
  workspaces,
43
32
  getProject: getProjectAndTsConfig,
@@ -53,21 +42,17 @@ function createWorkspaces(context) {
53
42
  remove: (rootUri) => {
54
43
  const _workspace = workspaces.get(rootUri.toString());
55
44
  workspaces.delete(rootUri.toString());
56
- (() => __awaiter(this, void 0, void 0, function* () {
57
- var _a;
58
- (_a = (yield _workspace)) === null || _a === void 0 ? void 0 : _a.dispose();
59
- }))();
45
+ (async () => {
46
+ (await _workspace)?.dispose();
47
+ })();
60
48
  },
61
49
  };
62
- function reloadProject() {
63
- var _a;
64
- return __awaiter(this, void 0, void 0, function* () {
65
- (_a = context.fileSystemHost) === null || _a === void 0 ? void 0 : _a.reload();
66
- for (const [_, workspace] of workspaces) {
67
- (yield workspace).reload();
68
- }
69
- reloadDiagnostics();
70
- });
50
+ async function reloadProject() {
51
+ context.fileSystemHost?.reload();
52
+ for (const [_, workspace] of workspaces) {
53
+ (await workspace).reload();
54
+ }
55
+ reloadDiagnostics();
71
56
  }
72
57
  function reloadDiagnostics() {
73
58
  for (const doc of context.documents.data.values()) {
@@ -75,95 +60,90 @@ function createWorkspaces(context) {
75
60
  }
76
61
  updateDiagnosticsAndSemanticTokens();
77
62
  }
78
- function updateDiagnosticsAndSemanticTokens() {
79
- var _a, _b, _c, _d;
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const req = ++semanticTokensReq;
82
- yield updateDiagnostics();
83
- const delay = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.diagnostics.delay'))) !== null && _b !== void 0 ? _b : 200;
84
- yield shared.sleep(delay);
85
- if (req === semanticTokensReq) {
86
- if ((_c = context.initParams.capabilities.textDocument) === null || _c === void 0 ? void 0 : _c.semanticTokens) {
87
- context.server.connection.languages.semanticTokens.refresh();
88
- }
89
- if ((_d = context.initParams.capabilities.textDocument) === null || _d === void 0 ? void 0 : _d.inlayHint) {
90
- context.server.connection.languages.inlayHint.refresh();
91
- }
63
+ async function updateDiagnosticsAndSemanticTokens() {
64
+ const req = ++semanticTokensReq;
65
+ await updateDiagnostics();
66
+ const delay = await context.configurationHost?.getConfiguration('volar.diagnostics.delay') ?? 200;
67
+ await sleep(delay);
68
+ if (req === semanticTokensReq) {
69
+ if (context.initParams.capabilities.textDocument?.semanticTokens) {
70
+ context.server.connection.languages.semanticTokens.refresh();
92
71
  }
93
- });
72
+ if (context.initParams.capabilities.textDocument?.inlayHint) {
73
+ context.server.connection.languages.inlayHint.refresh();
74
+ }
75
+ }
94
76
  }
95
- function updateDiagnostics(docUri) {
96
- var _a, _b, _c;
97
- return __awaiter(this, void 0, void 0, function* () {
98
- if (((_a = context.initOptions.diagnosticModel) !== null && _a !== void 0 ? _a : types_1.DiagnosticModel.Push) !== types_1.DiagnosticModel.Push)
77
+ async function updateDiagnostics(docUri) {
78
+ if ((context.initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) !== types_1.DiagnosticModel.Push)
79
+ return;
80
+ const req = ++documentUpdatedReq;
81
+ const delay = await context.configurationHost?.getConfiguration('volar.diagnostics.delay') ?? 200;
82
+ const cancel = context.cancelTokenHost.createCancellationToken({
83
+ get isCancellationRequested() {
84
+ return req !== documentUpdatedReq;
85
+ },
86
+ onCancellationRequested: vscode.Event.None,
87
+ });
88
+ const changeDoc = docUri ? context.documents.data.uriGet(docUri) : undefined;
89
+ const otherDocs = [...context.documents.data.values()].filter(doc => doc !== changeDoc);
90
+ if (changeDoc) {
91
+ await sleep(delay);
92
+ if (cancel.isCancellationRequested) {
99
93
  return;
100
- const req = ++documentUpdatedReq;
101
- const delay = (_c = yield ((_b = context.configurationHost) === null || _b === void 0 ? void 0 : _b.getConfiguration('volar.diagnostics.delay'))) !== null && _c !== void 0 ? _c : 200;
102
- const cancel = context.cancelTokenHost.createCancellationToken({
103
- get isCancellationRequested() {
104
- return req !== documentUpdatedReq;
105
- },
106
- onCancellationRequested: vscode.Event.None,
107
- });
108
- const changeDoc = docUri ? context.documents.data.uriGet(docUri) : undefined;
109
- const otherDocs = [...context.documents.data.values()].filter(doc => doc !== changeDoc);
110
- if (changeDoc) {
111
- yield shared.sleep(delay);
112
- if (cancel.isCancellationRequested) {
113
- return;
114
- }
115
- yield sendDocumentDiagnostics(changeDoc.uri, changeDoc.version, cancel);
116
94
  }
117
- for (const doc of otherDocs) {
118
- yield shared.sleep(delay);
119
- if (cancel.isCancellationRequested) {
120
- break;
121
- }
122
- yield sendDocumentDiagnostics(doc.uri, doc.version, cancel);
95
+ await sendDocumentDiagnostics(changeDoc.uri, changeDoc.version, cancel);
96
+ }
97
+ for (const doc of otherDocs) {
98
+ await sleep(delay);
99
+ if (cancel.isCancellationRequested) {
100
+ break;
123
101
  }
124
- });
102
+ await sendDocumentDiagnostics(doc.uri, doc.version, cancel);
103
+ }
125
104
  }
126
- function sendDocumentDiagnostics(uri, version, cancel) {
127
- var _a;
128
- return __awaiter(this, void 0, void 0, function* () {
129
- const project = (_a = (yield getProjectAndTsConfig(uri))) === null || _a === void 0 ? void 0 : _a.project;
130
- if (!project)
131
- return;
132
- const languageService = project.getLanguageService();
133
- const errors = yield languageService.doValidation(uri, cancel, result => {
134
- context.server.connection.sendDiagnostics({ uri: uri, diagnostics: result, version });
135
- });
136
- context.server.connection.sendDiagnostics({ uri: uri, diagnostics: errors, version });
105
+ async function sendDocumentDiagnostics(uri, version, cancel) {
106
+ const project = (await getProjectAndTsConfig(uri))?.project;
107
+ if (!project)
108
+ return;
109
+ const languageService = project.getLanguageService();
110
+ const mode = context.initOptions.serverMode === types_1.ServerMode.PartialSemantic ? 'semantic'
111
+ : context.initOptions.serverMode === types_1.ServerMode.Syntactic ? 'syntactic'
112
+ : 'all';
113
+ const errors = await languageService.doValidation(uri, cancel, mode, result => {
114
+ context.server.connection.sendDiagnostics({ uri: uri, diagnostics: result, version });
137
115
  });
116
+ context.server.connection.sendDiagnostics({ uri: uri, diagnostics: errors, version });
138
117
  }
139
- function getProjectAndTsConfig(uri) {
140
- var _a;
141
- return __awaiter(this, void 0, void 0, function* () {
142
- let rootUris = [...workspaces.keys()]
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)));
145
- if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
146
- for (const rootUri of rootUris) {
147
- const workspace = yield workspaces.get(rootUri);
148
- const projectAndTsConfig = yield (workspace === null || workspace === void 0 ? void 0 : workspace.getProjectAndTsConfig(uri));
149
- if (projectAndTsConfig) {
150
- return projectAndTsConfig;
151
- }
118
+ async function getProjectAndTsConfig(uri) {
119
+ let rootUris = [...workspaces.keys()]
120
+ .filter(rootUri => (0, isFileInDir_1.isFileInDir)(uriToFileName(uri), uriToFileName(rootUri)))
121
+ .sort((a, b) => (0, workspace_1.sortTsConfigs)(uriToFileName(uri), uriToFileName(a), uriToFileName(b)));
122
+ if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
123
+ for (const rootUri of rootUris) {
124
+ const workspace = await workspaces.get(rootUri);
125
+ const projectAndTsConfig = await workspace?.getProjectAndTsConfig(uri);
126
+ if (projectAndTsConfig) {
127
+ return projectAndTsConfig;
152
128
  }
153
129
  }
154
- if (!rootUris.length) {
155
- rootUris = [...workspaces.keys()];
156
- }
157
- if (rootUris.length) {
158
- const project = yield ((_a = (yield workspaces.get(rootUris[0]))) === null || _a === void 0 ? void 0 : _a.getInferredProject());
159
- project === null || project === void 0 ? void 0 : project.tryAddFile(uriToFileName(uri));
160
- return {
161
- tsconfig: undefined,
162
- project,
163
- };
164
- }
165
- });
130
+ }
131
+ if (!rootUris.length) {
132
+ rootUris = [...workspaces.keys()];
133
+ }
134
+ if (rootUris.length) {
135
+ const project = await (await workspaces.get(rootUris[0]))?.getInferredProject();
136
+ project?.tryAddFile(uriToFileName(uri));
137
+ return {
138
+ tsconfig: undefined,
139
+ project,
140
+ };
141
+ }
166
142
  }
167
143
  }
168
144
  exports.createWorkspaces = createWorkspaces;
145
+ function sleep(ms) {
146
+ return new Promise(resolve => setTimeout(resolve, ms));
147
+ }
148
+ exports.sleep = sleep;
169
149
  //# sourceMappingURL=workspaces.js.map
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.createNodeFileSystemHost = void 0;
12
3
  const vscode = require("vscode-languageserver");
@@ -17,7 +8,7 @@ function createNodeFileSystemHost(ts, capabilities, env, _initOptions) {
17
8
  const onDidChangeWatchedFilesCb = new Set();
18
9
  return {
19
10
  ready(connection) {
20
- connection.onDidChangeWatchedFiles((params) => __awaiter(this, void 0, void 0, function* () {
11
+ connection.onDidChangeWatchedFiles(async (params) => {
21
12
  if (params.changes.some(change => change.type === vscode.FileChangeType.Created || change.type === vscode.FileChangeType.Deleted)) {
22
13
  for (const sys of instances.values()) {
23
14
  sys[1].forEach(cache => cache.clear());
@@ -25,10 +16,10 @@ function createNodeFileSystemHost(ts, capabilities, env, _initOptions) {
25
16
  }
26
17
  for (const cb of [...onDidChangeWatchedFilesCb]) {
27
18
  if (onDidChangeWatchedFilesCb.has(cb)) {
28
- yield cb(params);
19
+ await cb(params);
29
20
  }
30
21
  }
31
- }));
22
+ });
32
23
  },
33
24
  reload() {
34
25
  for (const sys of instances.values()) {
@@ -49,7 +40,6 @@ function createNodeFileSystemHost(ts, capabilities, env, _initOptions) {
49
40
  },
50
41
  };
51
42
  function createWorkspaceFileSystem(ts, capabilities, rootUri) {
52
- var _a;
53
43
  const rootPath = env.uriToFileName(rootUri.toString());
54
44
  const workspaceSys = new Proxy(ts.sys, {
55
45
  get(target, prop) {
@@ -73,7 +63,7 @@ function createNodeFileSystemHost(ts, capabilities, env, _initOptions) {
73
63
  const fileExistsCache = new Map();
74
64
  const directoryExistsCache = new Map();
75
65
  // don't cache fs result if client did not supports file watcher
76
- const sys = ((_a = capabilities.workspace) === null || _a === void 0 ? void 0 : _a.didChangeWatchedFiles)
66
+ const sys = capabilities.workspace?.didChangeWatchedFiles
77
67
  ? new Proxy({
78
68
  fileExists(path) {
79
69
  if (!fileExistsCache.has(path)) {
package/out/node/index.js CHANGED
@@ -12,15 +12,6 @@ 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
- };
24
15
  Object.defineProperty(exports, "__esModule", { value: true });
25
16
  exports.startLanguageServer = exports.createConnection = void 0;
26
17
  const fs = require("fs");
@@ -54,22 +45,20 @@ function startLanguageServer(connection, ...plugins) {
54
45
  },
55
46
  },
56
47
  loadTypescript(tsdk) {
57
- for (const name of ['./typescript.js', './tsserverlibrary.js', './tsserver.js']) {
48
+ for (const name of ['./typescript.js', './tsserverlibrary.js']) {
58
49
  try {
59
50
  const path = require.resolve(name, { paths: [tsdk] });
60
51
  return require(path);
61
52
  }
62
- catch (_a) { }
53
+ catch { }
63
54
  }
64
55
  },
65
- loadTypescriptLocalized(tsdk, locale) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- try {
68
- const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
69
- return require(path);
70
- }
71
- catch (_a) { }
72
- });
56
+ async loadTypescriptLocalized(tsdk, locale) {
57
+ try {
58
+ const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
59
+ return require(path);
60
+ }
61
+ catch { }
73
62
  },
74
63
  schemaRequestHandlers: {
75
64
  file: file_1.default,
package/out/types.d.ts CHANGED
@@ -37,19 +37,17 @@ export interface LanguageServiceContext {
37
37
  }
38
38
  export interface LanguageServerPlugin {
39
39
  (initOptions: LanguageServerInitializationOptions): {
40
- tsconfigExtraFileExtensions: ts.FileExtensionInfo[];
41
- diagnosticDocumentSelector: vscode.DocumentSelector;
42
- extensions: {
43
- fileRenameOperationFilter: string[];
44
- fileWatcher: string[];
45
- };
46
- resolveConfig?(config: Config, ctx: LanguageServiceContext): void;
47
- onInitialize?(_: vscode.InitializeResult, env: RuntimeEnvironment): void;
40
+ extraFileExtensions?: ts.FileExtensionInfo[];
41
+ watchFileExtensions?: string[];
42
+ resolveConfig?(config: Config, modules: {
43
+ typescript?: typeof import('typescript/lib/tsserverlibrary');
44
+ }, ctx?: LanguageServiceContext): Config;
48
45
  onInitialized?(getLanguageService: (uri: string) => Promise<LanguageService | undefined>, env: RuntimeEnvironment): void;
49
46
  };
50
47
  }
51
48
  export declare enum ServerMode {
52
49
  Semantic = 0,
50
+ PartialSemantic = 1,
53
51
  Syntactic = 2
54
52
  }
55
53
  export declare enum DiagnosticModel {
@@ -97,10 +95,6 @@ export interface LanguageServerInitializationOptions {
97
95
  noProjectReferences?: boolean;
98
96
  reverseConfigFilePriority?: boolean;
99
97
  disableFileWatcher?: boolean;
100
- /**
101
- * Enable this option to make language server setup server capabilities based on client capabilities to support multiple servers.
102
- */
103
- respectClientCapabilities?: boolean;
104
98
  maxFileSize?: number;
105
99
  configFilePath?: string;
106
100
  /**
package/out/types.js CHANGED
@@ -3,7 +3,7 @@ exports.DiagnosticModel = exports.ServerMode = void 0;
3
3
  var ServerMode;
4
4
  (function (ServerMode) {
5
5
  ServerMode[ServerMode["Semantic"] = 0] = "Semantic";
6
- // PartialSemantic = 1, // not support yet
6
+ ServerMode[ServerMode["PartialSemantic"] = 1] = "PartialSemantic";
7
7
  ServerMode[ServerMode["Syntactic"] = 2] = "Syntactic";
8
8
  })(ServerMode = exports.ServerMode || (exports.ServerMode = {}));
9
9
  var DiagnosticModel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.3.0-alpha.3",
3
+ "version": "1.4.0-alpha.1",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,9 +17,8 @@
17
17
  "directory": "packages/language-server"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "1.3.0-alpha.3",
21
- "@volar/language-service": "1.3.0-alpha.3",
22
- "@volar/shared": "1.3.0-alpha.3",
20
+ "@volar/language-core": "1.4.0-alpha.1",
21
+ "@volar/language-service": "1.4.0-alpha.1",
23
22
  "@vscode/l10n": "^0.0.11",
24
23
  "request-light": "^0.7.0",
25
24
  "typesafe-path": "^0.2.2",
@@ -29,5 +28,5 @@
29
28
  "vscode-languageserver-textdocument": "^1.0.8",
30
29
  "vscode-uri": "^3.0.7"
31
30
  },
32
- "gitHead": "03c8fff84531d8740863da5f9350e0d9382b5784"
31
+ "gitHead": "41ea915b137aea284e2bf5edd98a788ce21b779c"
33
32
  }