@volar/language-server 1.0.8 → 1.0.10

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.
@@ -15,6 +15,57 @@ const vscode = require("vscode-languageserver");
15
15
  const protocol_1 = require("../protocol");
16
16
  const language_core_1 = require("@volar/language-core");
17
17
  function register(connection, projects) {
18
+ connection.onNotification(protocol_1.ReportStats.type, () => __awaiter(this, void 0, void 0, function* () {
19
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
20
+ for (const [rootUri, _workspace] of projects.workspaces) {
21
+ connection.console.log('workspace: ' + rootUri);
22
+ const workspace = yield _workspace;
23
+ connection.console.log('documentRegistry stats: ' + workspace.documentRegistry.reportStats());
24
+ connection.console.log('');
25
+ connection.console.log('tsconfig: inferred');
26
+ const _inferredProject = workspace.getInferredProjectDontCreate();
27
+ if (_inferredProject) {
28
+ connection.console.log('loaded: true');
29
+ const inferredProject = yield _inferredProject;
30
+ connection.console.log('largest 10 files:');
31
+ for (const script of [...inferredProject.scripts.values()]
32
+ .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
33
+ .slice(0, 10)) {
34
+ connection.console.log(' - ' + script.fileName);
35
+ connection.console.log(` size: ${(_a = script.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()}`);
36
+ }
37
+ connection.console.log('files:');
38
+ for (const script of inferredProject.scripts.values()) {
39
+ connection.console.log(' - ' + script.fileName);
40
+ connection.console.log(` size: ${(_b = script.snapshot) === null || _b === void 0 ? void 0 : _b.getLength()}`);
41
+ connection.console.log(` ref counts: "${(_d = (_c = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _d === void 0 ? void 0 : _d.call(_c, script.fileName, (_f = (_e = inferredProject.languageServiceHost).getScriptKind) === null || _f === void 0 ? void 0 : _f.call(_e, script.fileName))})"`);
42
+ }
43
+ }
44
+ else {
45
+ connection.console.log('loaded: false');
46
+ }
47
+ connection.console.log('');
48
+ for (const _project of workspace.projects.values()) {
49
+ const project = yield _project;
50
+ connection.console.log('tsconfig: ' + project.tsConfig);
51
+ connection.console.log('loaded: ' + !!project.getLanguageServiceDontCreate());
52
+ connection.console.log('largest 10 files:');
53
+ for (const script of [...project.scripts.values()]
54
+ .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
55
+ .slice(0, 10)) {
56
+ connection.console.log(' - ' + script.fileName);
57
+ connection.console.log(` size: ${(_g = script.snapshot) === null || _g === void 0 ? void 0 : _g.getLength()}`);
58
+ }
59
+ connection.console.log('files:');
60
+ for (const script of project.scripts.values()) {
61
+ connection.console.log(' - ' + script.fileName);
62
+ connection.console.log(` size: ${(_h = script.snapshot) === null || _h === void 0 ? void 0 : _h.getLength()}`);
63
+ connection.console.log(` ref counts: "${(_k = (_j = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _k === void 0 ? void 0 : _k.call(_j, script.fileName, (_m = (_l = project.languageServiceHost).getScriptKind) === null || _m === void 0 ? void 0 : _m.call(_l, script.fileName))})"`);
64
+ }
65
+ }
66
+ connection.console.log('');
67
+ }
68
+ }));
18
69
  connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
19
70
  const project = (yield projects.getProject(params.uri));
20
71
  if (project) {
@@ -24,11 +75,11 @@ function register(connection, projects) {
24
75
  }
25
76
  }));
26
77
  connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
27
- var _a, _b;
78
+ var _o, _p;
28
79
  const project = yield projects.getProject(document.uri);
29
80
  const fileNames = [];
30
81
  if (project) {
31
- const sourceFile = (_b = (_a = project.project) === null || _a === void 0 ? void 0 : _a.getLanguageService().context.core.mapper.get(shared.getPathOfUri(document.uri))) === null || _b === void 0 ? void 0 : _b[0];
82
+ const sourceFile = (_p = (_o = project.project) === null || _o === void 0 ? void 0 : _o.getLanguageService().context.core.mapper.get(shared.getPathOfUri(document.uri))) === null || _p === void 0 ? void 0 : _p[0];
32
83
  if (sourceFile) {
33
84
  (0, language_core_1.forEachEmbeddeds)(sourceFile.embeddeds, e => {
34
85
  if (e.text && e.kind === 1) {
@@ -40,10 +91,10 @@ function register(connection, projects) {
40
91
  return fileNames;
41
92
  }));
42
93
  connection.onRequest(protocol_1.GetVirtualFileRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
43
- var _c, _d;
94
+ var _q, _r;
44
95
  const project = yield projects.getProject(params.sourceFileUri);
45
96
  if (project) {
46
- const embeddedFile = (_d = (_c = project.project) === null || _c === void 0 ? void 0 : _c.getLanguageService().context.core.mapper.fromEmbeddedFileName(params.virtualFileName)) === null || _d === void 0 ? void 0 : _d.embedded;
97
+ const embeddedFile = (_r = (_q = project.project) === null || _q === void 0 ? void 0 : _q.getLanguageService().context.core.mapper.fromEmbeddedFileName(params.virtualFileName)) === null || _r === void 0 ? void 0 : _r.embedded;
47
98
  if (embeddedFile) {
48
99
  return {
49
100
  content: embeddedFile.text,
@@ -56,11 +107,11 @@ function register(connection, projects) {
56
107
  projects.reloadProject();
57
108
  }));
58
109
  connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
59
- var _e;
110
+ var _s;
60
111
  const fs = yield Promise.resolve().then(() => require('fs'));
61
112
  const project = yield projects.getProject(params.uri);
62
113
  if (project) {
63
- const ls = (_e = (yield project.project)) === null || _e === void 0 ? void 0 : _e.getLanguageServiceDontCreate();
114
+ const ls = (_s = (yield project.project)) === null || _s === void 0 ? void 0 : _s.getLanguageServiceDontCreate();
64
115
  if (ls) {
65
116
  const sourceFiles = new Set(ls.context.host.getScriptFileNames());
66
117
  for (const virtualFile of ls.context.core.typescriptLanguageServiceHost.getScriptFileNames()) {
@@ -75,14 +126,14 @@ function register(connection, projects) {
75
126
  }
76
127
  }));
77
128
  connection.onNotification(protocol_1.VerifyAllScriptsNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
78
- var _f;
129
+ var _t;
79
130
  let errors = 0;
80
131
  let warnings = 0;
81
132
  const progress = yield connection.window.createWorkDoneProgress();
82
133
  progress.begin('Verify', 0, '', true);
83
134
  const project = yield projects.getProject(params.uri);
84
135
  if (project) {
85
- const ls = (_f = (yield project.project)) === null || _f === void 0 ? void 0 : _f.getLanguageServiceDontCreate();
136
+ const ls = (_t = (yield project.project)) === null || _t === void 0 ? void 0 : _t.getLanguageServiceDontCreate();
86
137
  if (ls) {
87
138
  const allVueDocuments = ls.context.documents.getAll();
88
139
  let i = 0;
@@ -1,4 +1,4 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
- import { CancellactionTokenHost } from '../utils/cancellationPipe';
2
+ import { CancellationTokenHost } from '../utils/cancellationPipe';
3
3
  import type { Workspaces } from '../utils/workspaces';
4
- export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, cancelHost: CancellactionTokenHost): void;
4
+ export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, cancelHost: CancellationTokenHost): void;
@@ -13,6 +13,7 @@ const embedded = require("@volar/language-service");
13
13
  const vscode = require("vscode-languageserver");
14
14
  const protocol_1 = require("../protocol");
15
15
  const shared = require("@volar/shared");
16
+ const registerFeatures_1 = require("../registerFeatures");
16
17
  function register(connection, projects, initParams, cancelHost) {
17
18
  let lastCompleteUri;
18
19
  let lastCompleteLs;
@@ -180,7 +181,7 @@ function register(connection, projects, initParams, cancelHost) {
180
181
  return buildTokens([]);
181
182
  return (_j = yield worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
182
183
  var _k;
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 : [];
184
+ const result = (_k = yield (vueLs === null || vueLs === void 0 ? void 0 : vueLs.getSemanticTokens(params.textDocument.uri, undefined, registerFeatures_1.semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _k !== void 0 ? _k : [];
184
185
  return buildTokens(result);
185
186
  }))) !== null && _j !== void 0 ? _j : buildTokens([]);
186
187
  }));
@@ -191,12 +192,12 @@ function register(connection, projects, initParams, cancelHost) {
191
192
  return buildTokens([]);
192
193
  return (_l = yield worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
193
194
  var _m;
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 : [];
195
+ const result = (_m = yield (vueLs === null || vueLs === void 0 ? void 0 : vueLs.getSemanticTokens(params.textDocument.uri, params.range, registerFeatures_1.semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _m !== void 0 ? _m : [];
195
196
  return buildTokens(result);
196
197
  }))) !== null && _l !== void 0 ? _l : buildTokens([]);
197
198
  }));
198
199
  connection.languages.diagnostics.on((params, token, workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
199
- token = cancelHost.createCancellactionToken(token);
200
+ token = cancelHost.createCancellationToken(token);
200
201
  const result = yield worker(params.textDocument.uri, vueLs => {
201
202
  return vueLs.doValidation(params.textDocument.uri, token, errors => {
202
203
  // resultProgressReporter is undefined in vscode
package/out/protocol.d.ts CHANGED
@@ -74,6 +74,9 @@ export declare namespace GetVirtualFileRequest {
74
74
  type ErrorType = never;
75
75
  const type: vscode.RequestType<ParamsType, ResponseType, never>;
76
76
  }
77
+ export declare namespace ReportStats {
78
+ const type: vscode.NotificationType0;
79
+ }
77
80
  /**
78
81
  * FS request for browser
79
82
  */
package/out/protocol.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.ShowReferencesNotification = void 0;
2
+ exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.ReportStats = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.ShowReferencesNotification = void 0;
3
3
  const vscode = require("vscode-languageserver-protocol");
4
4
  /**
5
5
  * Server request client
@@ -43,6 +43,10 @@ var GetVirtualFileRequest;
43
43
  (function (GetVirtualFileRequest) {
44
44
  GetVirtualFileRequest.type = new vscode.RequestType('vue/virtualFile');
45
45
  })(GetVirtualFileRequest = exports.GetVirtualFileRequest || (exports.GetVirtualFileRequest = {}));
46
+ var ReportStats;
47
+ (function (ReportStats) {
48
+ ReportStats.type = new vscode.NotificationType0('vue/stats');
49
+ })(ReportStats = exports.ReportStats || (exports.ReportStats = {}));
46
50
  /**
47
51
  * FS request for browser
48
52
  */
@@ -1,5 +1,6 @@
1
1
  import { LanguageServerPlugin, LanguageServerInitializationOptions } from './types';
2
2
  import * as vscode from 'vscode-languageserver';
3
3
  import { ClientCapabilities } from 'vscode-languageserver';
4
- export declare function setupSyntacticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities): void;
5
- export declare function setupSemanticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, options: LanguageServerInitializationOptions, plugins: ReturnType<LanguageServerPlugin>[]): void;
4
+ export declare const semanticTokensLegend: vscode.SemanticTokensLegend;
5
+ export declare function setupSyntacticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, initOptions: LanguageServerInitializationOptions): void;
6
+ export declare function setupSemanticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, initOptions: LanguageServerInitializationOptions, plugins: ReturnType<LanguageServerPlugin>[]): void;
@@ -1,32 +1,72 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.setupSemanticCapabilities = exports.setupSyntacticCapabilities = void 0;
2
+ exports.setupSemanticCapabilities = exports.setupSyntacticCapabilities = exports.semanticTokensLegend = void 0;
3
3
  const embedded = require("@volar/language-service");
4
4
  const types_1 = require("./types");
5
5
  const vscode = require("vscode-languageserver");
6
- function setupSyntacticCapabilities(params, server) {
6
+ // https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers
7
+ exports.semanticTokensLegend = {
8
+ tokenTypes: [
9
+ 'namespace',
10
+ 'class',
11
+ 'enum',
12
+ 'interface',
13
+ 'struct',
14
+ 'typeParameter',
15
+ 'type',
16
+ 'parameter',
17
+ 'variable',
18
+ 'property',
19
+ 'enumMember',
20
+ 'decorator',
21
+ 'event',
22
+ 'function',
23
+ 'method',
24
+ 'macro',
25
+ 'label',
26
+ 'comment',
27
+ 'string',
28
+ 'keyword',
29
+ 'number',
30
+ 'regexp',
31
+ 'operator',
32
+ ],
33
+ tokenModifiers: [
34
+ 'declaration',
35
+ 'definition',
36
+ 'readonly',
37
+ 'static',
38
+ 'deprecated',
39
+ 'abstract',
40
+ 'async',
41
+ 'modification',
42
+ 'documentation',
43
+ 'defaultLibrary',
44
+ ],
45
+ };
46
+ function setupSyntacticCapabilities(params, server, initOptions) {
7
47
  var _a, _b, _c, _d, _e, _f, _g, _h;
8
- if ((_a = params.textDocument) === null || _a === void 0 ? void 0 : _a.selectionRange) {
48
+ if (!initOptions.respectClientCapabilities || ((_a = params.textDocument) === null || _a === void 0 ? void 0 : _a.selectionRange)) {
9
49
  server.selectionRangeProvider = true;
10
50
  }
11
- if ((_b = params.textDocument) === null || _b === void 0 ? void 0 : _b.foldingRange) {
51
+ if (!initOptions.respectClientCapabilities || ((_b = params.textDocument) === null || _b === void 0 ? void 0 : _b.foldingRange)) {
12
52
  server.foldingRangeProvider = true;
13
53
  }
14
- if ((_c = params.textDocument) === null || _c === void 0 ? void 0 : _c.linkedEditingRange) {
54
+ if (!initOptions.respectClientCapabilities || ((_c = params.textDocument) === null || _c === void 0 ? void 0 : _c.linkedEditingRange)) {
15
55
  server.linkedEditingRangeProvider = true;
16
56
  }
17
- if ((_d = params.textDocument) === null || _d === void 0 ? void 0 : _d.colorProvider) {
57
+ if (!initOptions.respectClientCapabilities || ((_d = params.textDocument) === null || _d === void 0 ? void 0 : _d.colorProvider)) {
18
58
  server.colorProvider = true;
19
59
  }
20
- if ((_e = params.textDocument) === null || _e === void 0 ? void 0 : _e.documentSymbol) {
60
+ if (!initOptions.respectClientCapabilities || ((_e = params.textDocument) === null || _e === void 0 ? void 0 : _e.documentSymbol)) {
21
61
  server.documentSymbolProvider = true;
22
62
  }
23
- if ((_f = params.textDocument) === null || _f === void 0 ? void 0 : _f.formatting) {
63
+ if (!initOptions.respectClientCapabilities || ((_f = params.textDocument) === null || _f === void 0 ? void 0 : _f.formatting)) {
24
64
  server.documentFormattingProvider = true;
25
65
  }
26
- if ((_g = params.textDocument) === null || _g === void 0 ? void 0 : _g.rangeFormatting) {
66
+ if (!initOptions.respectClientCapabilities || ((_g = params.textDocument) === null || _g === void 0 ? void 0 : _g.rangeFormatting)) {
27
67
  server.documentRangeFormattingProvider = true;
28
68
  }
29
- if ((_h = params.textDocument) === null || _h === void 0 ? void 0 : _h.onTypeFormatting) {
69
+ if (!initOptions.respectClientCapabilities || ((_h = params.textDocument) === null || _h === void 0 ? void 0 : _h.onTypeFormatting)) {
30
70
  // https://github.com/microsoft/vscode/blob/ce119308e8fd4cd3f992d42b297588e7abe33a0c/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L99
31
71
  server.documentOnTypeFormattingProvider = {
32
72
  firstTriggerCharacter: ';',
@@ -35,39 +75,43 @@ function setupSyntacticCapabilities(params, server) {
35
75
  }
36
76
  }
37
77
  exports.setupSyntacticCapabilities = setupSyntacticCapabilities;
38
- function setupSemanticCapabilities(params, server, options, plugins) {
39
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
40
- if ((_a = params.textDocument) === null || _a === void 0 ? void 0 : _a.references) {
78
+ function setupSemanticCapabilities(params, server, initOptions, plugins) {
79
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
80
+ if (!initOptions.respectClientCapabilities || ((_a = params.textDocument) === null || _a === void 0 ? void 0 : _a.references)) {
41
81
  server.referencesProvider = true;
42
82
  }
43
- if ((_b = params.textDocument) === null || _b === void 0 ? void 0 : _b.implementation) {
83
+ if (!initOptions.respectClientCapabilities || ((_b = params.textDocument) === null || _b === void 0 ? void 0 : _b.implementation)) {
44
84
  server.implementationProvider = true;
45
85
  }
46
- if ((_c = params.textDocument) === null || _c === void 0 ? void 0 : _c.definition) {
86
+ if (!initOptions.respectClientCapabilities || ((_c = params.textDocument) === null || _c === void 0 ? void 0 : _c.definition)) {
47
87
  server.definitionProvider = true;
48
88
  }
49
- if ((_d = params.textDocument) === null || _d === void 0 ? void 0 : _d.typeDefinition) {
89
+ if (!initOptions.respectClientCapabilities || ((_d = params.textDocument) === null || _d === void 0 ? void 0 : _d.typeDefinition)) {
50
90
  server.typeDefinitionProvider = true;
51
91
  }
52
- if ((_e = params.textDocument) === null || _e === void 0 ? void 0 : _e.callHierarchy) {
92
+ if (!initOptions.respectClientCapabilities || ((_e = params.textDocument) === null || _e === void 0 ? void 0 : _e.callHierarchy)) {
53
93
  server.callHierarchyProvider = true;
54
94
  }
55
- if ((_f = params.textDocument) === null || _f === void 0 ? void 0 : _f.hover) {
95
+ if (!initOptions.respectClientCapabilities || ((_f = params.textDocument) === null || _f === void 0 ? void 0 : _f.hover)) {
56
96
  server.hoverProvider = true;
57
97
  }
58
- if ((_g = params.textDocument) === null || _g === void 0 ? void 0 : _g.rename) {
98
+ if (!initOptions.respectClientCapabilities || ((_g = params.textDocument) === null || _g === void 0 ? void 0 : _g.rename)) {
59
99
  server.renameProvider = {
60
100
  prepareProvider: true,
61
101
  };
62
102
  }
63
- if ((_h = params.workspace) === null || _h === void 0 ? void 0 : _h.fileOperations) {
103
+ if (!initOptions.respectClientCapabilities || ((_h = params.workspace) === null || _h === void 0 ? void 0 : _h.fileOperations)) {
64
104
  server.workspace = {
65
105
  fileOperations: {
66
106
  willRename: {
67
107
  filters: [
68
108
  ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ pattern: { glob: `**/*.${ext.extension}` } }))).flat(),
69
109
  { pattern: { glob: '**/*.js' } },
110
+ { pattern: { glob: '**/*.cjs' } },
111
+ { pattern: { glob: '**/*.mjs' } },
70
112
  { pattern: { glob: '**/*.ts' } },
113
+ { pattern: { glob: '**/*.cts' } },
114
+ { pattern: { glob: '**/*.mts' } },
71
115
  { pattern: { glob: '**/*.jsx' } },
72
116
  { pattern: { glob: '**/*.tsx' } },
73
117
  { pattern: { glob: '**/*.json' } },
@@ -76,13 +120,13 @@ function setupSemanticCapabilities(params, server, options, plugins) {
76
120
  }
77
121
  };
78
122
  }
79
- if ((_j = params.textDocument) === null || _j === void 0 ? void 0 : _j.signatureHelp) {
123
+ if (!initOptions.respectClientCapabilities || ((_j = params.textDocument) === null || _j === void 0 ? void 0 : _j.signatureHelp)) {
80
124
  server.signatureHelpProvider = {
81
125
  triggerCharacters: ['(', ',', '<'],
82
126
  retriggerCharacters: [')'],
83
127
  };
84
128
  }
85
- if ((_k = params.textDocument) === null || _k === void 0 ? void 0 : _k.completion) {
129
+ if (!initOptions.respectClientCapabilities || ((_k = params.textDocument) === null || _k === void 0 ? void 0 : _k.completion)) {
86
130
  server.completionProvider = {
87
131
  // triggerCharacters: '!@#$%^&*()_+-=`~{}|[]\:";\'<>?,./ '.split(''), // all symbols on keyboard
88
132
  // hardcode to fix https://github.com/sublimelsp/LSP-volar/issues/114
@@ -98,22 +142,22 @@ function setupSemanticCapabilities(params, server, options, plugins) {
98
142
  ])],
99
143
  resolveProvider: true,
100
144
  };
101
- if (options.ignoreTriggerCharacters) {
102
- server.completionProvider.triggerCharacters = (_l = server.completionProvider.triggerCharacters) === null || _l === void 0 ? void 0 : _l.filter(c => !options.ignoreTriggerCharacters.includes(c));
145
+ if (initOptions.ignoreTriggerCharacters) {
146
+ server.completionProvider.triggerCharacters = (_l = server.completionProvider.triggerCharacters) === null || _l === void 0 ? void 0 : _l.filter(c => !initOptions.ignoreTriggerCharacters.includes(c));
103
147
  }
104
148
  }
105
- if ((_m = params.textDocument) === null || _m === void 0 ? void 0 : _m.documentHighlight) {
149
+ if (!initOptions.respectClientCapabilities || ((_m = params.textDocument) === null || _m === void 0 ? void 0 : _m.documentHighlight)) {
106
150
  server.documentHighlightProvider = true;
107
151
  }
108
- if ((_o = params.textDocument) === null || _o === void 0 ? void 0 : _o.documentLink) {
152
+ if (!initOptions.respectClientCapabilities || ((_o = params.textDocument) === null || _o === void 0 ? void 0 : _o.documentLink)) {
109
153
  server.documentLinkProvider = {
110
154
  resolveProvider: false, // TODO
111
155
  };
112
156
  }
113
- if ((_p = params.workspace) === null || _p === void 0 ? void 0 : _p.symbol) {
157
+ if (!initOptions.respectClientCapabilities || ((_p = params.workspace) === null || _p === void 0 ? void 0 : _p.symbol)) {
114
158
  server.workspaceSymbolProvider = true;
115
159
  }
116
- if ((_q = params.textDocument) === null || _q === void 0 ? void 0 : _q.codeLens) {
160
+ if (!initOptions.respectClientCapabilities || ((_q = params.textDocument) === null || _q === void 0 ? void 0 : _q.codeLens)) {
117
161
  server.codeLensProvider = {
118
162
  resolveProvider: true,
119
163
  };
@@ -124,23 +168,14 @@ function setupSemanticCapabilities(params, server, options, plugins) {
124
168
  ]
125
169
  };
126
170
  }
127
- if ((_t = params.textDocument) === null || _t === void 0 ? void 0 : _t.semanticTokens) {
171
+ if (!initOptions.respectClientCapabilities || ((_t = params.textDocument) === null || _t === void 0 ? void 0 : _t.semanticTokens)) {
128
172
  server.semanticTokensProvider = {
129
173
  range: true,
130
174
  full: false,
131
- legend: {
132
- tokenModifiers: [],
133
- tokenTypes: [],
134
- },
175
+ legend: exports.semanticTokensLegend,
135
176
  };
136
- for (const plugin of plugins) {
137
- if ((_u = plugin.semanticService) === null || _u === void 0 ? void 0 : _u.semanticTokenLegend) {
138
- server.semanticTokensProvider.legend.tokenModifiers = server.semanticTokensProvider.legend.tokenModifiers.concat(plugin.semanticService.semanticTokenLegend.tokenModifiers);
139
- server.semanticTokensProvider.legend.tokenTypes = server.semanticTokensProvider.legend.tokenTypes.concat(plugin.semanticService.semanticTokenLegend.tokenTypes);
140
- }
141
- }
142
177
  }
143
- if ((_v = params.textDocument) === null || _v === void 0 ? void 0 : _v.codeAction) {
178
+ if (!initOptions.respectClientCapabilities || ((_u = params.textDocument) === null || _u === void 0 ? void 0 : _u.codeAction)) {
144
179
  server.codeActionProvider = {
145
180
  codeActionKinds: [
146
181
  vscode.CodeActionKind.Empty,
@@ -156,10 +191,10 @@ function setupSemanticCapabilities(params, server, options, plugins) {
156
191
  resolveProvider: true,
157
192
  };
158
193
  }
159
- if ((_w = params.textDocument) === null || _w === void 0 ? void 0 : _w.inlayHint) {
194
+ if (!initOptions.respectClientCapabilities || ((_v = params.textDocument) === null || _v === void 0 ? void 0 : _v.inlayHint)) {
160
195
  server.inlayHintProvider = true;
161
196
  }
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) {
197
+ if (!initOptions.respectClientCapabilities || ((_w = params.textDocument) === null || _w === void 0 ? void 0 : _w.diagnostic) && ((_x = initOptions.diagnosticModel) !== null && _x !== void 0 ? _x : types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
163
198
  server.diagnosticProvider = {
164
199
  documentSelector: [
165
200
  ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ pattern: `**/*.${ext.extension}` }))).flat(),
package/out/server.js CHANGED
@@ -49,8 +49,8 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
49
49
  };
50
50
  configHost = ((_c = params.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(params, connection) : undefined;
51
51
  const serverMode = (_d = options.serverMode) !== null && _d !== void 0 ? _d : types_1.ServerMode.Semantic;
52
- (0, registerFeatures_1.setupSyntacticCapabilities)(params.capabilities, result.capabilities);
53
- yield createDocumenntServiceHost();
52
+ (0, registerFeatures_1.setupSyntacticCapabilities)(params.capabilities, result.capabilities, options);
53
+ yield _createDocumentServiceHost();
54
54
  if (serverMode === types_1.ServerMode.Semantic) {
55
55
  (0, registerFeatures_1.setupSemanticCapabilities)(params.capabilities, result.capabilities, options, plugins);
56
56
  yield createLanguageServiceHost();
@@ -67,7 +67,7 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
67
67
  return result;
68
68
  }));
69
69
  connection.onInitialized(() => __awaiter(this, void 0, void 0, function* () {
70
- var _f;
70
+ var _f, _g, _h;
71
71
  fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(connection);
72
72
  configHost === null || configHost === void 0 ? void 0 : configHost.ready();
73
73
  if ((_f = params.capabilities.workspace) === null || _f === void 0 ? void 0 : _f.workspaceFolders) {
@@ -82,9 +82,32 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
82
82
  }
83
83
  });
84
84
  }
85
+ if (options.serverMode !== types_1.ServerMode.Syntactic
86
+ && !options.disableFileWatcher
87
+ && ((_h = (_g = params.capabilities.workspace) === null || _g === void 0 ? void 0 : _g.didChangeWatchedFiles) === null || _h === void 0 ? void 0 : _h.dynamicRegistration)) {
88
+ connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
89
+ watchers: [
90
+ ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ globPattern: `**/*.${ext.extension}` }))).flat(),
91
+ {
92
+ globPattern: `**/*.{${[
93
+ 'js',
94
+ 'cjs',
95
+ 'mjs',
96
+ 'ts',
97
+ 'cts',
98
+ 'mts',
99
+ 'jsx',
100
+ 'tsx',
101
+ 'json',
102
+ ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ext.extension)).flat(),
103
+ ].join(',')}}`
104
+ },
105
+ ]
106
+ });
107
+ }
85
108
  }));
86
109
  connection.listen();
87
- function createDocumenntServiceHost() {
110
+ function _createDocumentServiceHost() {
88
111
  var _a, _b;
89
112
  return __awaiter(this, void 0, void 0, function* () {
90
113
  const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
@@ -104,7 +127,7 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
104
127
  const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
105
128
  fsHost = runtimeEnv.createFileSystemHost(ts, params.capabilities);
106
129
  const tsLocalized = params.locale ? runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, params.locale) : undefined;
107
- const cancelTokenHost = (0, cancellationPipe_1.createCancellactionTokenHost)(options.cancellationPipeName);
130
+ const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
108
131
  const _projects = (0, workspaces_1.createWorkspaces)(runtimeEnv, plugins, fsHost, configHost, ts, tsLocalized, params.capabilities, options, documents, connection, cancelTokenHost);
109
132
  projects = _projects;
110
133
  for (const root of roots) {
package/out/types.d.ts CHANGED
@@ -27,11 +27,10 @@ export interface RuntimeEnvironment {
27
27
  export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, B extends embedded.LanguageServiceHost = embedded.LanguageServiceHost, C = embeddedLS.LanguageService> = (initOptions: A) => {
28
28
  extraFileExtensions: ts.FileExtensionInfo[];
29
29
  semanticService?: {
30
- semanticTokenLegend?: vscode.SemanticTokensLegend;
31
30
  resolveLanguageServiceHost?(ts: typeof import('typescript/lib/tsserverlibrary'), sys: FileSystem, tsConfig: string | ts.CompilerOptions, host: embedded.LanguageServiceHost): B;
32
31
  getLanguageModules?(host: B): embedded.LanguageModule[];
33
32
  getServicePlugins?(host: B, service: embeddedLS.LanguageService): embeddedLS.LanguageServicePlugin[];
34
- onInitialize?(connection: vscode.Connection, getLangaugeService: (uri: string) => Promise<C>): void;
33
+ onInitialize?(connection: vscode.Connection, getLanguageService: (uri: string) => Promise<C>): void;
35
34
  };
36
35
  syntacticService?: {
37
36
  getLanguageModules?(ts: typeof import('typescript/lib/tsserverlibrary'), env: embeddedLS.LanguageServicePluginContext['env']): embedded.LanguageModule[];
@@ -61,4 +60,10 @@ export interface LanguageServerInitializationOptions {
61
60
  */
62
61
  cancellationPipeName?: string;
63
62
  noProjectReferences?: boolean;
63
+ reverseConfigFilePriority?: boolean;
64
+ disableFileWatcher?: boolean;
65
+ /**
66
+ * Enable this option to make language server setup server capabilities based on client capabilities to support multiple servers.
67
+ */
68
+ respectClientCapabilities?: boolean;
64
69
  }
@@ -1,6 +1,6 @@
1
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;
2
+ export type CancellationTokenHost = ReturnType<typeof createCancellationTokenHost>;
3
+ export declare function createCancellationTokenHost(_cancellationPipeName: string | undefined): {
4
+ createCancellationToken(original: vscode.CancellationToken): vscode.CancellationToken;
5
5
  getMtime(): number;
6
6
  };
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.createCancellactionTokenHost = void 0;
2
+ exports.createCancellationTokenHost = void 0;
3
3
  const vscode = require("vscode-languageserver");
4
- function createCancellactionTokenHost(_cancellationPipeName) {
4
+ function createCancellationTokenHost(_cancellationPipeName) {
5
5
  if (_cancellationPipeName === undefined) {
6
6
  return {
7
- createCancellactionToken(original) {
7
+ createCancellationToken(original) {
8
8
  return original;
9
9
  },
10
10
  getMtime() {
@@ -15,10 +15,10 @@ function createCancellactionTokenHost(_cancellationPipeName) {
15
15
  const cancellationPipeName = _cancellationPipeName;
16
16
  const fs = require('fs');
17
17
  return {
18
- createCancellactionToken,
18
+ createCancellationToken,
19
19
  getMtime,
20
20
  };
21
- function createCancellactionToken(original) {
21
+ function createCancellationToken(original) {
22
22
  const mtime = getMtime();
23
23
  const token = {
24
24
  get isCancellationRequested() {
@@ -40,5 +40,5 @@ function createCancellactionTokenHost(_cancellationPipeName) {
40
40
  }
41
41
  }
42
42
  }
43
- exports.createCancellactionTokenHost = createCancellactionTokenHost;
43
+ exports.createCancellationTokenHost = createCancellationTokenHost;
44
44
  //# sourceMappingURL=cancellationPipe.js.map
@@ -2,16 +2,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.loadCustomPlugins = void 0;
3
3
  function loadCustomPlugins(dir) {
4
4
  var _a;
5
+ let configPath;
5
6
  try {
6
- const configPath = require.resolve('./volar.config.js', { paths: [dir] });
7
- const config = require(configPath);
8
- // console.warn('Found', configPath, 'and loaded', config.plugins?.length, 'plugins.');
9
- return (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
7
+ configPath = require.resolve('./volar.config.js', { paths: [dir] });
8
+ }
9
+ catch (_b) { }
10
+ try {
11
+ if (configPath) {
12
+ const config = require(configPath);
13
+ return (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
14
+ }
10
15
  }
11
16
  catch (err) {
12
- // console.warn('No volar.config.js found in', dir);
13
- return [];
17
+ console.log(err);
14
18
  }
19
+ return [];
15
20
  }
16
21
  exports.loadCustomPlugins = loadCustomPlugins;
17
22
  //# sourceMappingURL=config.js.map
@@ -12,7 +12,9 @@ exports.createConfigurationHost = void 0;
12
12
  const vscode = require("vscode-languageserver");
13
13
  function createConfigurationHost(params, connection) {
14
14
  const callbacks = [];
15
+ let cache = {};
15
16
  connection.onDidChangeConfiguration(() => __awaiter(this, void 0, void 0, function* () {
17
+ cache = {};
16
18
  for (const cb of callbacks) {
17
19
  cb();
18
20
  }
@@ -25,15 +27,25 @@ function createConfigurationHost(params, connection) {
25
27
  }
26
28
  },
27
29
  getConfiguration(section, scopeUri) {
28
- var _a;
30
+ var _a, _b;
29
31
  return __awaiter(this, void 0, void 0, function* () {
30
- return (_a = (yield connection.workspace.getConfiguration({ scopeUri, section }))) !== null && _a !== void 0 ? _a : undefined /* replace null to undefined */;
32
+ if (!scopeUri && ((_a = params.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.didChangeConfiguration)) {
33
+ (_b = cache[section]) !== null && _b !== void 0 ? _b : (cache[section] = yield getConfigurationWorker(section, scopeUri));
34
+ return cache[section];
35
+ }
36
+ return yield getConfigurationWorker(section, scopeUri);
31
37
  });
32
38
  },
33
39
  onDidChangeConfiguration(cb) {
34
40
  callbacks.push(cb);
35
41
  },
36
42
  };
43
+ function getConfigurationWorker(section, scopeUri) {
44
+ var _a;
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return (_a = (yield connection.workspace.getConfiguration({ scopeUri, section }))) !== null && _a !== void 0 ? _a : undefined /* replace null to undefined */;
47
+ });
48
+ }
37
49
  }
38
50
  exports.createConfigurationHost = createConfigurationHost;
39
51
  //# sourceMappingURL=configurationHost.js.map
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.createNodeFileSystemHost = void 0;
12
- const shared = require("@volar/shared");
13
12
  const vscode = require("vscode-languageserver");
14
13
  const iterableWeakSet_1 = require("./iterableWeakSet");
14
+ const uriMap_1 = require("./uriMap");
15
15
  let currentCwd = '';
16
16
  function createNodeFileSystemHost(ts, capabilities) {
17
- const instances = shared.createUriMap();
17
+ const instances = (0, uriMap_1.createUriMap)();
18
18
  const onDidChangeWatchedFilesCb = new Set();
19
19
  const caches = new iterableWeakSet_1.IterableWeakSet();
20
20
  return {