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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.sleep = exports.createWorkspaces = void 0;
12
3
  const vscode = require("vscode-languageserver");
@@ -14,7 +5,6 @@ const types_1 = require("../types");
14
5
  const workspace_1 = require("./workspace");
15
6
  const isFileInDir_1 = require("./utils/isFileInDir");
16
7
  function createWorkspaces(context) {
17
- var _a, _b, _c;
18
8
  const uriToFileName = context.server.runtimeEnv.uriToFileName;
19
9
  const workspaces = new Map();
20
10
  let semanticTokensReq = 0;
@@ -25,7 +15,7 @@ function createWorkspaces(context) {
25
15
  context.documents.onDidClose(({ textDocument }) => {
26
16
  context.server.connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
27
17
  });
28
- (_a = context.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(({ changes }) => {
18
+ context.fileSystemHost?.onDidChangeWatchedFiles(({ changes }) => {
29
19
  const tsConfigChanges = changes.filter(change => workspace_1.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
30
20
  if (tsConfigChanges.length) {
31
21
  reloadDiagnostics();
@@ -34,9 +24,9 @@ function createWorkspaces(context) {
34
24
  updateDiagnosticsAndSemanticTokens();
35
25
  }
36
26
  });
37
- (_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 () => {
38
28
  updateDiagnosticsAndSemanticTokens();
39
- }));
29
+ });
40
30
  return {
41
31
  workspaces,
42
32
  getProject: getProjectAndTsConfig,
@@ -52,21 +42,17 @@ function createWorkspaces(context) {
52
42
  remove: (rootUri) => {
53
43
  const _workspace = workspaces.get(rootUri.toString());
54
44
  workspaces.delete(rootUri.toString());
55
- (() => __awaiter(this, void 0, void 0, function* () {
56
- var _a;
57
- (_a = (yield _workspace)) === null || _a === void 0 ? void 0 : _a.dispose();
58
- }))();
45
+ (async () => {
46
+ (await _workspace)?.dispose();
47
+ })();
59
48
  },
60
49
  };
61
- function reloadProject() {
62
- var _a;
63
- return __awaiter(this, void 0, void 0, function* () {
64
- (_a = context.fileSystemHost) === null || _a === void 0 ? void 0 : _a.reload();
65
- for (const [_, workspace] of workspaces) {
66
- (yield workspace).reload();
67
- }
68
- reloadDiagnostics();
69
- });
50
+ async function reloadProject() {
51
+ context.fileSystemHost?.reload();
52
+ for (const [_, workspace] of workspaces) {
53
+ (await workspace).reload();
54
+ }
55
+ reloadDiagnostics();
70
56
  }
71
57
  function reloadDiagnostics() {
72
58
  for (const doc of context.documents.data.values()) {
@@ -74,97 +60,85 @@ function createWorkspaces(context) {
74
60
  }
75
61
  updateDiagnosticsAndSemanticTokens();
76
62
  }
77
- function updateDiagnosticsAndSemanticTokens() {
78
- var _a, _b, _c, _d;
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const req = ++semanticTokensReq;
81
- yield updateDiagnostics();
82
- const delay = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.diagnostics.delay'))) !== null && _b !== void 0 ? _b : 200;
83
- yield sleep(delay);
84
- if (req === semanticTokensReq) {
85
- if ((_c = context.initParams.capabilities.textDocument) === null || _c === void 0 ? void 0 : _c.semanticTokens) {
86
- context.server.connection.languages.semanticTokens.refresh();
87
- }
88
- if ((_d = context.initParams.capabilities.textDocument) === null || _d === void 0 ? void 0 : _d.inlayHint) {
89
- context.server.connection.languages.inlayHint.refresh();
90
- }
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();
91
71
  }
92
- });
72
+ if (context.initParams.capabilities.textDocument?.inlayHint) {
73
+ context.server.connection.languages.inlayHint.refresh();
74
+ }
75
+ }
93
76
  }
94
- function updateDiagnostics(docUri) {
95
- var _a, _b, _c;
96
- return __awaiter(this, void 0, void 0, function* () {
97
- 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) {
98
93
  return;
99
- const req = ++documentUpdatedReq;
100
- const delay = (_c = yield ((_b = context.configurationHost) === null || _b === void 0 ? void 0 : _b.getConfiguration('volar.diagnostics.delay'))) !== null && _c !== void 0 ? _c : 200;
101
- const cancel = context.cancelTokenHost.createCancellationToken({
102
- get isCancellationRequested() {
103
- return req !== documentUpdatedReq;
104
- },
105
- onCancellationRequested: vscode.Event.None,
106
- });
107
- const changeDoc = docUri ? context.documents.data.uriGet(docUri) : undefined;
108
- const otherDocs = [...context.documents.data.values()].filter(doc => doc !== changeDoc);
109
- if (changeDoc) {
110
- yield sleep(delay);
111
- if (cancel.isCancellationRequested) {
112
- return;
113
- }
114
- yield sendDocumentDiagnostics(changeDoc.uri, changeDoc.version, cancel);
115
94
  }
116
- for (const doc of otherDocs) {
117
- yield sleep(delay);
118
- if (cancel.isCancellationRequested) {
119
- break;
120
- }
121
- 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;
122
101
  }
123
- });
102
+ await sendDocumentDiagnostics(doc.uri, doc.version, cancel);
103
+ }
124
104
  }
125
- function sendDocumentDiagnostics(uri, version, cancel) {
126
- var _a;
127
- return __awaiter(this, void 0, void 0, function* () {
128
- const project = (_a = (yield getProjectAndTsConfig(uri))) === null || _a === void 0 ? void 0 : _a.project;
129
- if (!project)
130
- return;
131
- const languageService = project.getLanguageService();
132
- const mode = context.initOptions.serverMode === types_1.ServerMode.PartialSemantic ? 'semantic'
133
- : context.initOptions.serverMode === types_1.ServerMode.Syntactic ? 'syntactic'
134
- : 'all';
135
- const errors = yield languageService.doValidation(uri, cancel, mode, result => {
136
- context.server.connection.sendDiagnostics({ uri: uri, diagnostics: result, version });
137
- });
138
- 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, mode, cancel, result => {
114
+ context.server.connection.sendDiagnostics({ uri: uri, diagnostics: result, version });
139
115
  });
116
+ context.server.connection.sendDiagnostics({ uri: uri, diagnostics: errors, version });
140
117
  }
141
- function getProjectAndTsConfig(uri) {
142
- var _a;
143
- return __awaiter(this, void 0, void 0, function* () {
144
- let rootUris = [...workspaces.keys()]
145
- .filter(rootUri => (0, isFileInDir_1.isFileInDir)(uriToFileName(uri), uriToFileName(rootUri)))
146
- .sort((a, b) => (0, workspace_1.sortTsConfigs)(uriToFileName(uri), uriToFileName(a), uriToFileName(b)));
147
- if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
148
- for (const rootUri of rootUris) {
149
- const workspace = yield workspaces.get(rootUri);
150
- const projectAndTsConfig = yield (workspace === null || workspace === void 0 ? void 0 : workspace.getProjectAndTsConfig(uri));
151
- if (projectAndTsConfig) {
152
- return projectAndTsConfig;
153
- }
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;
154
128
  }
155
129
  }
156
- if (!rootUris.length) {
157
- rootUris = [...workspaces.keys()];
158
- }
159
- if (rootUris.length) {
160
- const project = yield ((_a = (yield workspaces.get(rootUris[0]))) === null || _a === void 0 ? void 0 : _a.getInferredProject());
161
- project === null || project === void 0 ? void 0 : project.tryAddFile(uriToFileName(uri));
162
- return {
163
- tsconfig: undefined,
164
- project,
165
- };
166
- }
167
- });
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
+ }
168
142
  }
169
143
  }
170
144
  exports.createWorkspaces = createWorkspaces;
@@ -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");
@@ -59,17 +50,15 @@ function startLanguageServer(connection, ...plugins) {
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.4.0-alpha.0",
3
+ "version": "1.4.0-alpha.2",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,8 +17,8 @@
17
17
  "directory": "packages/language-server"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "1.4.0-alpha.0",
21
- "@volar/language-service": "1.4.0-alpha.0",
20
+ "@volar/language-core": "1.4.0-alpha.2",
21
+ "@volar/language-service": "1.4.0-alpha.2",
22
22
  "@vscode/l10n": "^0.0.11",
23
23
  "request-light": "^0.7.0",
24
24
  "typesafe-path": "^0.2.2",
@@ -28,5 +28,5 @@
28
28
  "vscode-languageserver-textdocument": "^1.0.8",
29
29
  "vscode-uri": "^3.0.7"
30
30
  },
31
- "gitHead": "2607410cae341cf802b446062d446ad497be2057"
31
+ "gitHead": "034b230da17794a6fcf5a0b07668710f98ff84e3"
32
32
  }