@volar/language-server 1.0.0-beta.2 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,23 +10,59 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const shared = require("@volar/shared");
13
- const path = require("upath");
13
+ const path = require("typesafe-path");
14
14
  const vscode = require("vscode-languageserver");
15
- const requests_1 = require("../requests");
15
+ const protocol_1 = require("../protocol");
16
+ const language_core_1 = require("@volar/language-core");
16
17
  function register(connection, projects) {
17
- connection.onRequest(requests_1.GetMatchTsConfigRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
18
+ connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
18
19
  var _a;
19
- return (_a = (yield projects.getProject(params.uri))) === null || _a === void 0 ? void 0 : _a.tsconfig;
20
+ const project = (yield projects.getProject(params.uri));
21
+ if (project) {
22
+ return {
23
+ fileName: project.tsconfig,
24
+ raw: (_a = project.project) === null || _a === void 0 ? void 0 : _a.getParsedCommandLine().raw,
25
+ };
26
+ }
27
+ }));
28
+ connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
29
+ var _b, _c;
30
+ const project = yield projects.getProject(document.uri);
31
+ const fileNames = [];
32
+ if (project) {
33
+ const sourceFile = (_c = (_b = project.project) === null || _b === void 0 ? void 0 : _b.getLanguageService().context.core.mapper.get(shared.getPathOfUri(document.uri))) === null || _c === void 0 ? void 0 : _c[0];
34
+ if (sourceFile) {
35
+ (0, language_core_1.forEachEmbeddeds)(sourceFile.embeddeds, e => {
36
+ if (e.text && e.kind === 1) {
37
+ fileNames.push(e.fileName);
38
+ }
39
+ });
40
+ }
41
+ }
42
+ return fileNames;
43
+ }));
44
+ connection.onRequest(protocol_1.GetVirtualFileRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
45
+ var _d, _e;
46
+ const project = yield projects.getProject(params.sourceFileUri);
47
+ if (project) {
48
+ const embeddedFile = (_e = (_d = project.project) === null || _d === void 0 ? void 0 : _d.getLanguageService().context.core.mapper.fromEmbeddedFileName(params.virtualFileName)) === null || _e === void 0 ? void 0 : _e.embedded;
49
+ if (embeddedFile) {
50
+ return {
51
+ content: embeddedFile.text,
52
+ mappings: embeddedFile.mappings,
53
+ };
54
+ }
55
+ }
20
56
  }));
21
- connection.onNotification(requests_1.ReloadProjectNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
57
+ connection.onNotification(protocol_1.ReloadProjectNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
22
58
  projects.reloadProject();
23
59
  }));
24
- connection.onNotification(requests_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
25
- var _b;
60
+ connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
61
+ var _f;
26
62
  const fs = yield Promise.resolve().then(() => require('fs'));
27
63
  const project = yield projects.getProject(params.uri);
28
64
  if (project) {
29
- const ls = (_b = (yield project.project)) === null || _b === void 0 ? void 0 : _b.getLanguageServiceDontCreate();
65
+ const ls = (_f = (yield project.project)) === null || _f === void 0 ? void 0 : _f.getLanguageServiceDontCreate();
30
66
  if (ls) {
31
67
  const sourceFiles = new Set(ls.context.host.getScriptFileNames());
32
68
  for (const virtualFile of ls.context.core.typescriptLanguageServiceHost.getScriptFileNames()) {
@@ -40,15 +76,15 @@ function register(connection, projects) {
40
76
  }
41
77
  }
42
78
  }));
43
- connection.onNotification(requests_1.VerifyAllScriptsNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
44
- var _c;
79
+ connection.onNotification(protocol_1.VerifyAllScriptsNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
80
+ var _g;
45
81
  let errors = 0;
46
82
  let warnings = 0;
47
83
  const progress = yield connection.window.createWorkDoneProgress();
48
84
  progress.begin('Verify', 0, '', true);
49
85
  const project = yield projects.getProject(params.uri);
50
86
  if (project) {
51
- const ls = (_c = (yield project.project)) === null || _c === void 0 ? void 0 : _c.getLanguageServiceDontCreate();
87
+ const ls = (_g = (yield project.project)) === null || _g === void 0 ? void 0 : _g.getLanguageServiceDontCreate();
52
88
  if (ls) {
53
89
  const allVueDocuments = ls.context.documents.getAll();
54
90
  let i = 0;
@@ -57,7 +93,7 @@ function register(connection, projects) {
57
93
  if (progress.token.isCancellationRequested) {
58
94
  continue;
59
95
  }
60
- let _result = yield ls.doValidation(vueFile.uri);
96
+ let _result = yield ls.doValidation(vueFile.uri, progress.token);
61
97
  connection.sendDiagnostics({ uri: vueFile.uri, diagnostics: _result });
62
98
  errors += _result.filter(error => error.severity === vscode.DiagnosticSeverity.Error).length;
63
99
  warnings += _result.filter(error => error.severity === vscode.DiagnosticSeverity.Warning).length;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
- const requests_1 = require("../requests");
12
+ const protocol_1 = require("../protocol");
13
13
  function register(connection, documents, documentServiceHost) {
14
14
  connection.onDocumentFormatting(params => {
15
15
  return worker(params.textDocument.uri, document => {
@@ -56,7 +56,7 @@ function register(connection, documents, documentServiceHost) {
56
56
  return documentServiceHost.get(document.uri).getColorPresentations(document, params.color, params.range);
57
57
  });
58
58
  });
59
- connection.onRequest(requests_1.AutoInsertRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
59
+ connection.onRequest(protocol_1.AutoInsertRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
60
60
  return worker(params.textDocument.uri, document => {
61
61
  return documentServiceHost.get(document.uri).doAutoInsert(document, params.position, params.options);
62
62
  });
@@ -1,3 +1,4 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
+ import { CancellactionTokenHost } from '../utils/cancellationPipe';
2
3
  import type { Workspaces } from '../utils/workspaces';
3
- export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams): void;
4
+ export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, cancelHost: CancellactionTokenHost): void;
@@ -11,8 +11,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const embedded = require("@volar/language-service");
13
13
  const vscode = require("vscode-languageserver");
14
- const requests_1 = require("../requests");
15
- function register(connection, projects, initParams) {
14
+ const protocol_1 = require("../protocol");
15
+ const shared = require("@volar/shared");
16
+ function register(connection, projects, initParams, cancelHost) {
16
17
  let lastCompleteUri;
17
18
  let lastCompleteLs;
18
19
  let lastCodeLensLs;
@@ -79,7 +80,7 @@ function register(connection, projects, initParams) {
79
80
  token,
80
81
  workDoneProgress,
81
82
  applyEdit: (paramOrEdit) => connection.workspace.applyEdit(paramOrEdit),
82
- showReferences: (params) => connection.sendNotification(requests_1.ShowReferencesNotification.type, params),
83
+ showReferences: (params) => connection.sendNotification(protocol_1.ShowReferencesNotification.type, params),
83
84
  });
84
85
  });
85
86
  }
@@ -112,7 +113,7 @@ function register(connection, projects, initParams) {
112
113
  return vueLs.findReferences(params.textDocument.uri, params.position);
113
114
  });
114
115
  }));
115
- connection.onRequest(requests_1.FindFileReferenceRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
116
+ connection.onRequest(protocol_1.FindFileReferenceRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
116
117
  return worker(params.textDocument.uri, vueLs => {
117
118
  return vueLs.findFileReferences(params.textDocument.uri);
118
119
  });
@@ -174,6 +175,9 @@ function register(connection, projects, initParams) {
174
175
  }));
175
176
  connection.languages.semanticTokens.on((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
176
177
  var _j;
178
+ yield shared.sleep(200);
179
+ if (token.isCancellationRequested)
180
+ return buildTokens([]);
177
181
  return (_j = yield worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
178
182
  var _k;
179
183
  const result = (_k = yield (vueLs === null || vueLs === void 0 ? void 0 : vueLs.getSemanticTokens(params.textDocument.uri, undefined, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _k !== void 0 ? _k : [];
@@ -182,15 +186,19 @@ function register(connection, projects, initParams) {
182
186
  }));
183
187
  connection.languages.semanticTokens.onRange((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
184
188
  var _l;
189
+ yield shared.sleep(200);
190
+ if (token.isCancellationRequested)
191
+ return buildTokens([]);
185
192
  return (_l = yield worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
186
193
  var _m;
187
194
  const result = (_m = yield (vueLs === null || vueLs === void 0 ? void 0 : vueLs.getSemanticTokens(params.textDocument.uri, params.range, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _m !== void 0 ? _m : [];
188
195
  return buildTokens(result);
189
196
  }))) !== null && _l !== void 0 ? _l : buildTokens([]);
190
197
  }));
191
- connection.languages.diagnostics.on((params, cancellationToken, workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
198
+ connection.languages.diagnostics.on((params, token, workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
199
+ token = cancelHost.createCancellactionToken(token);
192
200
  const result = yield worker(params.textDocument.uri, vueLs => {
193
- return vueLs.doValidation(params.textDocument.uri, errors => {
201
+ return vueLs.doValidation(params.textDocument.uri, token, errors => {
194
202
  // resultProgressReporter is undefined in vscode
195
203
  resultProgressReporter === null || resultProgressReporter === void 0 ? void 0 : resultProgressReporter.report({
196
204
  relatedDocuments: {
@@ -200,7 +208,7 @@ function register(connection, projects, initParams) {
200
208
  },
201
209
  },
202
210
  });
203
- }, cancellationToken);
211
+ });
204
212
  });
205
213
  return {
206
214
  kind: vscode.DocumentDiagnosticReportKind.Full,
@@ -208,9 +216,9 @@ function register(connection, projects, initParams) {
208
216
  };
209
217
  }));
210
218
  connection.languages.inlayHint.on((params) => __awaiter(this, void 0, void 0, function* () {
211
- return worker(params.textDocument.uri, vueLs => {
219
+ return worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
212
220
  return vueLs.getInlayHints(params.textDocument.uri, params.range);
213
- });
221
+ }));
214
222
  }));
215
223
  // TODO: connection.languages.inlayHint.resolve
216
224
  connection.workspace.onWillRenameFiles((params) => __awaiter(this, void 0, void 0, function* () {
@@ -228,7 +236,7 @@ function register(connection, projects, initParams) {
228
236
  return (_a = vueLs.getEditsForFileRename(file.oldUri, file.newUri)) !== null && _a !== void 0 ? _a : null;
229
237
  })) !== null && _o !== void 0 ? _o : null;
230
238
  }));
231
- connection.onRequest(requests_1.AutoInsertRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
239
+ connection.onRequest(protocol_1.AutoInsertRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
232
240
  return worker(params.textDocument.uri, vueLs => {
233
241
  return vueLs.doAutoInsert(params.textDocument.uri, params.position, params.options);
234
242
  });
@@ -237,7 +245,12 @@ function register(connection, projects, initParams) {
237
245
  return __awaiter(this, void 0, void 0, function* () {
238
246
  const vueLs = yield getLanguageService(uri);
239
247
  if (vueLs) {
240
- return cb(vueLs);
248
+ try {
249
+ return cb(vueLs); // handle for TS cancel throw
250
+ }
251
+ catch (_a) {
252
+ return undefined;
253
+ }
241
254
  }
242
255
  });
243
256
  }
package/out/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from '@volar/language-service';
2
- export * from './requests';
1
+ export * from './protocol';
3
2
  export * from './types';
3
+ export * from '@volar/language-core/out/types';
4
+ export * from '@volar/language-service/out/types';
package/out/index.js CHANGED
@@ -13,7 +13,9 @@ 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
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- __exportStar(require("@volar/language-service"), exports);
17
- __exportStar(require("./requests"), exports);
16
+ __exportStar(require("./protocol"), exports);
18
17
  __exportStar(require("./types"), exports);
18
+ // only export types of depend packages
19
+ __exportStar(require("@volar/language-core/out/types"), exports);
20
+ __exportStar(require("@volar/language-service/out/types"), exports);
19
21
  //# sourceMappingURL=index.js.map
@@ -9,12 +9,9 @@ export declare namespace ShowReferencesNotification {
9
9
  };
10
10
  const type: vscode.NotificationType<ResponseType>;
11
11
  }
12
- export declare namespace GetDocumentPrintWidthRequest {
13
- type ParamsType = vscode.TextDocumentIdentifier;
14
- type ResponseType = number | undefined;
15
- type ErrorType = never;
16
- const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
17
- }
12
+ /**
13
+ * Client request server
14
+ */
18
15
  export declare namespace FindFileReferenceRequest {
19
16
  type ParamsType = {
20
17
  textDocument: vscode.TextDocumentIdentifier;
@@ -23,12 +20,12 @@ export declare namespace FindFileReferenceRequest {
23
20
  type ErrorType = never;
24
21
  const type: vscode.RequestType<ParamsType, ResponseType, never>;
25
22
  }
26
- /**
27
- * Client request server
28
- */
29
23
  export declare namespace GetMatchTsConfigRequest {
30
24
  type ParamsType = vscode.TextDocumentIdentifier;
31
- type ResponseType = string | null | undefined;
25
+ type ResponseType = {
26
+ fileName: string;
27
+ raw: any;
28
+ } | null | undefined;
32
29
  type ErrorType = never;
33
30
  const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
34
31
  }
@@ -56,6 +53,28 @@ export declare namespace WriteVirtualFilesNotification {
56
53
  export declare namespace ReloadProjectNotification {
57
54
  const type: vscode.NotificationType<vscode.TextDocumentIdentifier>;
58
55
  }
56
+ export declare namespace GetVirtualFileNamesRequest {
57
+ type ParamsType = vscode.TextDocumentIdentifier;
58
+ type ResponseType = string[];
59
+ type ErrorType = never;
60
+ const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
61
+ }
62
+ export declare namespace GetVirtualFileRequest {
63
+ type ParamsType = {
64
+ sourceFileUri: string;
65
+ virtualFileName: string;
66
+ };
67
+ type ResponseType = {
68
+ content: string;
69
+ mappings: {
70
+ sourceRange: [number, number];
71
+ generatedRange: [number, number];
72
+ data: undefined;
73
+ }[];
74
+ };
75
+ type ErrorType = never;
76
+ const type: vscode.RequestType<ParamsType, ResponseType, never>;
77
+ }
59
78
  /**
60
79
  * FS request for browser
61
80
  */
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.GetDocumentPrintWidthRequest = exports.ShowReferencesNotification = void 0;
2
+ exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.ShowReferencesNotification = void 0;
3
3
  const vscode = require("vscode-languageserver-protocol");
4
4
  /**
5
5
  * Server request client
@@ -8,17 +8,13 @@ var ShowReferencesNotification;
8
8
  (function (ShowReferencesNotification) {
9
9
  ShowReferencesNotification.type = new vscode.NotificationType('vue.findReferences');
10
10
  })(ShowReferencesNotification = exports.ShowReferencesNotification || (exports.ShowReferencesNotification = {}));
11
- var GetDocumentPrintWidthRequest;
12
- (function (GetDocumentPrintWidthRequest) {
13
- GetDocumentPrintWidthRequest.type = new vscode.RequestType('vue/getDocumentWordWrapColumn');
14
- })(GetDocumentPrintWidthRequest = exports.GetDocumentPrintWidthRequest || (exports.GetDocumentPrintWidthRequest = {}));
11
+ /**
12
+ * Client request server
13
+ */
15
14
  var FindFileReferenceRequest;
16
15
  (function (FindFileReferenceRequest) {
17
16
  FindFileReferenceRequest.type = new vscode.RequestType('vue/findFileReference');
18
17
  })(FindFileReferenceRequest = exports.FindFileReferenceRequest || (exports.FindFileReferenceRequest = {}));
19
- /**
20
- * Client request server
21
- */
22
18
  var GetMatchTsConfigRequest;
23
19
  (function (GetMatchTsConfigRequest) {
24
20
  GetMatchTsConfigRequest.type = new vscode.RequestType('volar/tsconfig');
@@ -39,6 +35,14 @@ var ReloadProjectNotification;
39
35
  (function (ReloadProjectNotification) {
40
36
  ReloadProjectNotification.type = new vscode.NotificationType('volar.action.reloadProject');
41
37
  })(ReloadProjectNotification = exports.ReloadProjectNotification || (exports.ReloadProjectNotification = {}));
38
+ var GetVirtualFileNamesRequest;
39
+ (function (GetVirtualFileNamesRequest) {
40
+ GetVirtualFileNamesRequest.type = new vscode.RequestType('vue/virtualFileNames');
41
+ })(GetVirtualFileNamesRequest = exports.GetVirtualFileNamesRequest || (exports.GetVirtualFileNamesRequest = {}));
42
+ var GetVirtualFileRequest;
43
+ (function (GetVirtualFileRequest) {
44
+ GetVirtualFileRequest.type = new vscode.RequestType('vue/virtualFile');
45
+ })(GetVirtualFileRequest = exports.GetVirtualFileRequest || (exports.GetVirtualFileRequest = {}));
42
46
  /**
43
47
  * FS request for browser
44
48
  */
@@ -54,4 +58,4 @@ var FsReadDirectoryRequest;
54
58
  (function (FsReadDirectoryRequest) {
55
59
  FsReadDirectoryRequest.type = new vscode.RequestType('fs/readDirectory');
56
60
  })(FsReadDirectoryRequest = exports.FsReadDirectoryRequest || (exports.FsReadDirectoryRequest = {}));
57
- //# sourceMappingURL=requests.js.map
61
+ //# sourceMappingURL=protocol.js.map
@@ -1,5 +1,5 @@
1
- import { LanguageServerPlugin, InitializationOptions } from './types';
1
+ import { LanguageServerPlugin, LanguageServerInitializationOptions } from './types';
2
2
  import * as vscode from 'vscode-languageserver';
3
3
  import { ClientCapabilities } from 'vscode-languageserver';
4
4
  export declare function setupSyntacticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities): void;
5
- export declare function setupSemanticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, options: InitializationOptions, plugins: ReturnType<LanguageServerPlugin>[]): void;
5
+ export declare function setupSemanticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, options: LanguageServerInitializationOptions, plugins: ReturnType<LanguageServerPlugin>[]): void;
@@ -65,7 +65,7 @@ function setupSemanticCapabilities(params, server, options, plugins) {
65
65
  fileOperations: {
66
66
  willRename: {
67
67
  filters: [
68
- ...plugins.map(plugin => plugin.extensions.map(ext => ({ pattern: { glob: `**/*${ext}` } }))).flat(),
68
+ ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ pattern: { glob: `**/*.${ext.extension}` } }))).flat(),
69
69
  { pattern: { glob: '**/*.js' } },
70
70
  { pattern: { glob: '**/*.ts' } },
71
71
  { pattern: { glob: '**/*.jsx' } },
@@ -162,7 +162,7 @@ function setupSemanticCapabilities(params, server, options, plugins) {
162
162
  if (((_x = params.textDocument) === null || _x === void 0 ? void 0 : _x.diagnostic) && ((_y = options.diagnosticModel) !== null && _y !== void 0 ? _y : types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
163
163
  server.diagnosticProvider = {
164
164
  documentSelector: [
165
- ...plugins.map(plugin => plugin.extensions.map(ext => ({ pattern: `**/*${ext}` }))).flat(),
165
+ ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ pattern: `**/*.${ext.extension}` }))).flat(),
166
166
  { pattern: '**/*.{ts,js,tsx,jsx}' },
167
167
  ],
168
168
  interFileDependencies: true,
package/out/server.js CHANGED
@@ -17,6 +17,7 @@ const documentServiceHost_1 = require("./utils/documentServiceHost");
17
17
  const snapshots_1 = require("./utils/snapshots");
18
18
  const workspaces_1 = require("./utils/workspaces");
19
19
  const registerFeatures_1 = require("./registerFeatures");
20
+ const cancellationPipe_1 = require("./utils/cancellationPipe");
20
21
  function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
21
22
  let params;
22
23
  let options;
@@ -84,6 +85,7 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
84
85
  }));
85
86
  connection.listen();
86
87
  function createDocumenntServiceHost() {
88
+ var _a, _b;
87
89
  return __awaiter(this, void 0, void 0, function* () {
88
90
  const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
89
91
  documentServiceHost = (0, documentServiceHost_1.createDocumentServiceHost)(runtimeEnv, plugins, ts, configHost);
@@ -91,6 +93,9 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
91
93
  documentServiceHost.add(root);
92
94
  }
93
95
  (yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(connection, documents, documentServiceHost);
96
+ for (const plugin of plugins) {
97
+ (_b = (_a = plugin.documentService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, connection);
98
+ }
94
99
  });
95
100
  }
96
101
  function createLanguageServiceHost() {
@@ -99,13 +104,14 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
99
104
  const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
100
105
  fsHost = runtimeEnv.createFileSystemHost(ts, params.capabilities);
101
106
  const tsLocalized = params.locale ? runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, params.locale) : undefined;
102
- const _projects = (0, workspaces_1.createWorkspaces)(runtimeEnv, plugins, fsHost, configHost, ts, tsLocalized, params.capabilities, options, documents, connection);
107
+ const cancelTokenHost = (0, cancellationPipe_1.createCancellactionTokenHost)(options.cancellationPipeName);
108
+ const _projects = (0, workspaces_1.createWorkspaces)(runtimeEnv, plugins, fsHost, configHost, ts, tsLocalized, params.capabilities, options, documents, connection, cancelTokenHost);
103
109
  projects = _projects;
104
110
  for (const root of roots) {
105
111
  projects.add(root);
106
112
  }
107
113
  (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects);
108
- (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, params);
114
+ (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, params, cancelTokenHost);
109
115
  for (const plugin of plugins) {
110
116
  (_b = (_a = plugin.languageService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, connection, getLanguageService);
111
117
  }
package/out/types.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as embedded from '@volar/language-core';
4
4
  import type { FileSystemProvider } from 'vscode-html-languageservice';
5
5
  import type * as ts from 'typescript/lib/tsserverlibrary';
6
6
  import * as vscode from 'vscode-languageserver';
7
- import type * as Requests from './requests';
7
+ import type * as Requests from './protocol';
8
8
  import { URI } from 'vscode-uri';
9
9
  export declare let __requests: typeof Requests;
10
10
  export type FileSystemHost = {
@@ -24,8 +24,8 @@ export interface RuntimeEnvironment {
24
24
  fileSystemProvide: FileSystemProvider | undefined;
25
25
  createFileSystemHost: (ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities) => FileSystemHost;
26
26
  }
27
- export type LanguageServerPlugin<A extends InitializationOptions = InitializationOptions, B extends embedded.LanguageServiceHost = embedded.LanguageServiceHost, C = embeddedLS.LanguageService> = (initOptions: A) => {
28
- extensions: string[];
27
+ export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, B extends embedded.LanguageServiceHost = embedded.LanguageServiceHost, C = embeddedLS.LanguageService> = (initOptions: A) => {
28
+ extraFileExtensions: ts.FileExtensionInfo[];
29
29
  languageService?: {
30
30
  semanticTokenLegend?: vscode.SemanticTokensLegend;
31
31
  resolveLanguageServiceHost?(ts: typeof import('typescript/lib/tsserverlibrary'), sys: FileSystem, tsConfig: string | ts.CompilerOptions, host: embedded.LanguageServiceHost): B;
@@ -36,6 +36,7 @@ export type LanguageServerPlugin<A extends InitializationOptions = Initializatio
36
36
  documentService?: {
37
37
  getLanguageModules?(ts: typeof import('typescript/lib/tsserverlibrary'), env: embeddedLS.LanguageServicePluginContext['env']): embedded.EmbeddedLanguageModule[];
38
38
  getServicePlugins?(context: embeddedLS.DocumentServiceRuntimeContext): embeddedLS.LanguageServicePlugin[];
39
+ onInitialize?(connection: vscode.Connection): void;
39
40
  };
40
41
  };
41
42
  export declare enum ServerMode {
@@ -47,7 +48,7 @@ export declare enum DiagnosticModel {
47
48
  Push = 1,
48
49
  Pull = 2
49
50
  }
50
- export interface InitializationOptions {
51
+ export interface LanguageServerInitializationOptions {
51
52
  typescript: {
52
53
  tsdk: string;
53
54
  };
@@ -55,4 +56,8 @@ export interface InitializationOptions {
55
56
  diagnosticModel?: DiagnosticModel;
56
57
  textDocumentSync?: vscode.TextDocumentSyncKind | number;
57
58
  ignoreTriggerCharacters?: string[];
59
+ /**
60
+ * https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29#cancellation
61
+ */
62
+ cancellationPipeName?: string;
58
63
  }
@@ -0,0 +1,6 @@
1
+ import * as vscode from 'vscode-languageserver';
2
+ export type CancellactionTokenHost = ReturnType<typeof createCancellactionTokenHost>;
3
+ export declare function createCancellactionTokenHost(_cancellationPipeName: string | undefined): {
4
+ createCancellactionToken(original: vscode.CancellationToken): vscode.CancellationToken;
5
+ getMtime(): number;
6
+ };
@@ -0,0 +1,44 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.createCancellactionTokenHost = void 0;
3
+ const vscode = require("vscode-languageserver");
4
+ function createCancellactionTokenHost(_cancellationPipeName) {
5
+ if (_cancellationPipeName === undefined) {
6
+ return {
7
+ createCancellactionToken(original) {
8
+ return original;
9
+ },
10
+ getMtime() {
11
+ return -1;
12
+ }
13
+ };
14
+ }
15
+ const cancellationPipeName = _cancellationPipeName;
16
+ const fs = require('fs');
17
+ return {
18
+ createCancellactionToken,
19
+ getMtime,
20
+ };
21
+ function createCancellactionToken(original) {
22
+ const mtime = getMtime();
23
+ const token = {
24
+ get isCancellationRequested() {
25
+ if (original.isCancellationRequested) {
26
+ return true;
27
+ }
28
+ return getMtime() !== mtime;
29
+ },
30
+ onCancellationRequested: vscode.Event.None,
31
+ };
32
+ return token;
33
+ }
34
+ function getMtime() {
35
+ try {
36
+ return fs.statSync(cancellationPipeName).mtime.valueOf();
37
+ }
38
+ catch (_a) {
39
+ return -1;
40
+ }
41
+ }
42
+ }
43
+ exports.createCancellactionTokenHost = createCancellactionTokenHost;
44
+ //# sourceMappingURL=cancellationPipe.js.map
@@ -2,23 +2,25 @@ import * as embeddedLS from '@volar/language-service';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
3
  import * as vscode from 'vscode-languageserver';
4
4
  import { URI } from 'vscode-uri';
5
- import { FileSystemHost, LanguageServerPlugin, RuntimeEnvironment, InitializationOptions } from '../types';
5
+ import { FileSystemHost, LanguageServerPlugin, RuntimeEnvironment } from '../types';
6
6
  import { createSnapshots } from './snapshots';
7
7
  import { ConfigurationHost } from '@volar/vue-language-service';
8
+ import * as path from 'typesafe-path';
9
+ import { CancellactionTokenHost } from './cancellationPipe';
8
10
  export interface Project extends ReturnType<typeof createProject> {
9
11
  }
10
- export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost, ts: typeof import('typescript/lib/tsserverlibrary'), options: InitializationOptions, rootUri: URI, tsConfig: string | ts.CompilerOptions, tsLocalized: ts.MapLike<string> | undefined, documents: ReturnType<typeof createSnapshots>, connection: vscode.Connection, configHost: ConfigurationHost | undefined, documentRegistry: ts.DocumentRegistry | undefined): Promise<{
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: CancellactionTokenHost): Promise<{
11
13
  getLanguageService: () => {
12
- doValidation: (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined, cancellationToken?: vscode.CancellationToken | undefined) => Promise<vscode.Diagnostic[]>;
14
+ doValidation: (uri: string, token?: vscode.CancellationToken | undefined, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
13
15
  findReferences: (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
14
16
  findFileReferences: (uri: string) => embeddedLS.NullableResult<vscode.Location[]>;
15
17
  findDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
16
18
  findTypeDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
17
19
  findImplementations: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
18
- prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
20
+ prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.ResponseError<void> | vscode.Range | null | undefined> | undefined>;
19
21
  doRename: (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
20
22
  getEditsForFileRename: (oldUri: string, newUri: string) => Promise<vscode.WorkspaceEdit | undefined>;
21
- getSemanticTokens: (uri: string, range?: vscode.Range | undefined, cancleToken?: vscode.CancellationToken | undefined, reportProgress?: ((tokens: embeddedLS.SemanticToken[]) => void) | undefined) => Promise<embeddedLS.SemanticToken[] | undefined> | undefined;
23
+ getSemanticTokens: (uri: string, range: vscode.Range | undefined, cancleToken: vscode.CancellationToken, reportProgress?: ((tokens: embeddedLS.SemanticToken[]) => void) | undefined) => Promise<embeddedLS.SemanticToken[] | undefined> | undefined;
22
24
  doHover: (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
23
25
  doComplete: (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext | undefined) => Promise<{
24
26
  isIncomplete: boolean;
@@ -52,16 +54,16 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
52
54
  context: embeddedLS.LanguageServiceRuntimeContext;
53
55
  };
54
56
  getLanguageServiceDontCreate: () => {
55
- doValidation: (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined, cancellationToken?: vscode.CancellationToken | undefined) => Promise<vscode.Diagnostic[]>;
57
+ doValidation: (uri: string, token?: vscode.CancellationToken | undefined, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
56
58
  findReferences: (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
57
59
  findFileReferences: (uri: string) => embeddedLS.NullableResult<vscode.Location[]>;
58
60
  findDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
59
61
  findTypeDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
60
62
  findImplementations: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
61
- prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
63
+ prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.ResponseError<void> | vscode.Range | null | undefined> | undefined>;
62
64
  doRename: (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
63
65
  getEditsForFileRename: (oldUri: string, newUri: string) => Promise<vscode.WorkspaceEdit | undefined>;
64
- getSemanticTokens: (uri: string, range?: vscode.Range | undefined, cancleToken?: vscode.CancellationToken | undefined, reportProgress?: ((tokens: embeddedLS.SemanticToken[]) => void) | undefined) => Promise<embeddedLS.SemanticToken[] | undefined> | undefined;
66
+ getSemanticTokens: (uri: string, range: vscode.Range | undefined, cancleToken: vscode.CancellationToken, reportProgress?: ((tokens: embeddedLS.SemanticToken[]) => void) | undefined) => Promise<embeddedLS.SemanticToken[] | undefined> | undefined;
65
67
  doHover: (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
66
68
  doComplete: (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext | undefined) => Promise<{
67
69
  isIncomplete: boolean;