@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.
- package/out/browser/fileSystems.js +82 -102
- package/out/browser/index.js +11 -24
- package/out/browser/typescript/core.js +1 -1
- package/out/browser/typescript/corePublic.js +2 -2
- package/out/common/cancellationPipe.js +1 -1
- package/out/common/configurationHost.js +12 -28
- package/out/common/documents.js +2 -3
- package/out/common/features/customFeatures.js +34 -47
- package/out/common/features/languageFeatures.d.ts +1 -0
- package/out/common/features/languageFeatures.js +161 -191
- package/out/common/project.d.ts +75 -85
- package/out/common/project.js +212 -227
- package/out/common/server.js +72 -112
- package/out/common/utils/inferredCompilerOptions.js +57 -61
- package/out/common/utils/registerFeatures.d.ts +2 -2
- package/out/common/utils/registerFeatures.js +27 -74
- package/out/common/utils/serverConfig.js +2 -2
- package/out/common/utils/uriMap.js +1 -1
- package/out/common/workspace.d.ts +675 -747
- package/out/common/workspace.js +164 -197
- package/out/common/workspaces.d.ts +826 -913
- package/out/common/workspaces.js +86 -106
- package/out/node/fileSystem.js +4 -14
- package/out/node/index.js +8 -19
- package/out/types.d.ts +6 -12
- package/out/types.js +1 -1
- package/package.json +4 -5
package/out/common/server.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
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.startCommonLanguageServer = void 0;
|
|
3
|
+
const language_service_1 = require("@volar/language-service");
|
|
4
|
+
const l10n = require("@vscode/l10n");
|
|
12
5
|
const vscode = require("vscode-languageserver");
|
|
13
6
|
const vscode_uri_1 = require("vscode-uri");
|
|
14
7
|
const types_1 = require("../types");
|
|
@@ -16,8 +9,8 @@ const cancellationPipe_1 = require("./cancellationPipe");
|
|
|
16
9
|
const configurationHost_1 = require("./configurationHost");
|
|
17
10
|
const documents_1 = require("./documents");
|
|
18
11
|
const registerFeatures_1 = require("./utils/registerFeatures");
|
|
12
|
+
const serverConfig_1 = require("./utils/serverConfig");
|
|
19
13
|
const workspaces_1 = require("./workspaces");
|
|
20
|
-
const l10n = require("@vscode/l10n");
|
|
21
14
|
function startCommonLanguageServer(connection, getCtx) {
|
|
22
15
|
let initParams;
|
|
23
16
|
let options;
|
|
@@ -28,17 +21,16 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
28
21
|
let plugins;
|
|
29
22
|
let documents;
|
|
30
23
|
let context;
|
|
31
|
-
connection.onInitialize((_params) =>
|
|
32
|
-
var _a, _b, _c, _d;
|
|
24
|
+
connection.onInitialize(async (_params) => {
|
|
33
25
|
initParams = _params;
|
|
34
26
|
options = initParams.initializationOptions;
|
|
35
27
|
context = getCtx(options);
|
|
36
28
|
plugins = context.plugins.map(plugin => plugin(options));
|
|
37
29
|
documents = (0, documents_1.createDocuments)(context.runtimeEnv, connection);
|
|
38
30
|
if (options.l10n) {
|
|
39
|
-
|
|
31
|
+
await l10n.config({ uri: options.l10n.location });
|
|
40
32
|
}
|
|
41
|
-
if (
|
|
33
|
+
if (initParams.capabilities.workspace?.workspaceFolders && initParams.workspaceFolders) {
|
|
42
34
|
roots = initParams.workspaceFolders.map(folder => vscode_uri_1.URI.parse(folder.uri));
|
|
43
35
|
}
|
|
44
36
|
else if (initParams.rootUri) {
|
|
@@ -49,12 +41,30 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
49
41
|
}
|
|
50
42
|
const result = {
|
|
51
43
|
capabilities: {
|
|
52
|
-
textDocumentSync:
|
|
44
|
+
textDocumentSync: options.textDocumentSync ?? vscode.TextDocumentSyncKind.Incremental,
|
|
53
45
|
},
|
|
54
46
|
};
|
|
55
|
-
configurationHost =
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
configurationHost = initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
|
|
48
|
+
let lsPlugins = {};
|
|
49
|
+
const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
|
|
50
|
+
for (const root of roots) {
|
|
51
|
+
if (root.scheme === 'file') {
|
|
52
|
+
let config = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath) ?? {};
|
|
53
|
+
for (const plugin of plugins) {
|
|
54
|
+
if (plugin.resolveConfig) {
|
|
55
|
+
config = plugin.resolveConfig(config, { typescript: ts });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (config.plugins) {
|
|
59
|
+
lsPlugins = {
|
|
60
|
+
...lsPlugins,
|
|
61
|
+
...config.plugins,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
(0, registerFeatures_1.setupCapabilities)(result.capabilities, options, plugins, getSemanticTokensLegend(), lsPlugins);
|
|
67
|
+
await createLanguageServiceHost();
|
|
58
68
|
try {
|
|
59
69
|
// show version on LSP logs
|
|
60
70
|
const packageJson = require('../package.json');
|
|
@@ -63,30 +73,26 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
63
73
|
version: packageJson.version,
|
|
64
74
|
};
|
|
65
75
|
}
|
|
66
|
-
catch
|
|
67
|
-
for (const plugin of plugins) {
|
|
68
|
-
(_d = plugin.onInitialize) === null || _d === void 0 ? void 0 : _d.call(plugin, result, context.runtimeEnv);
|
|
69
|
-
}
|
|
76
|
+
catch { }
|
|
70
77
|
return result;
|
|
71
|
-
})
|
|
78
|
+
});
|
|
72
79
|
connection.onInitialized(() => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if ((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) {
|
|
80
|
+
fsHost?.ready(connection);
|
|
81
|
+
configurationHost?.ready();
|
|
82
|
+
if (initParams.capabilities.workspace?.workspaceFolders) {
|
|
77
83
|
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
78
84
|
for (const folder of e.added) {
|
|
79
|
-
projects
|
|
85
|
+
projects?.add(vscode_uri_1.URI.parse(folder.uri));
|
|
80
86
|
}
|
|
81
87
|
for (const folder of e.removed) {
|
|
82
|
-
projects
|
|
88
|
+
projects?.remove(vscode_uri_1.URI.parse(folder.uri));
|
|
83
89
|
}
|
|
84
90
|
});
|
|
85
91
|
}
|
|
86
92
|
if (options.serverMode !== types_1.ServerMode.Syntactic
|
|
87
93
|
&& !options.disableFileWatcher
|
|
88
|
-
&&
|
|
89
|
-
const exts = plugins.map(plugin =>
|
|
94
|
+
&& initParams.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration) {
|
|
95
|
+
const exts = plugins.map(plugin => plugin.watchFileExtensions).flat();
|
|
90
96
|
if (exts.length) {
|
|
91
97
|
connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
|
92
98
|
watchers: [
|
|
@@ -98,100 +104,54 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
106
|
});
|
|
101
|
-
connection.onShutdown(() =>
|
|
107
|
+
connection.onShutdown(async () => {
|
|
102
108
|
if (projects) {
|
|
103
109
|
for (const workspace of projects.workspaces) {
|
|
104
|
-
(
|
|
110
|
+
(await workspace[1]).dispose();
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
|
-
})
|
|
113
|
+
});
|
|
108
114
|
connection.listen();
|
|
109
|
-
function createLanguageServiceHost() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
cancelTokenHost,
|
|
126
|
-
plugins,
|
|
127
|
-
});
|
|
128
|
-
projects = _projects;
|
|
129
|
-
for (const root of roots) {
|
|
130
|
-
projects.add(root);
|
|
131
|
-
}
|
|
132
|
-
(yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
|
|
133
|
-
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
|
|
134
|
-
for (const plugin of plugins) {
|
|
135
|
-
(_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService, context.runtimeEnv);
|
|
136
|
-
}
|
|
137
|
-
function getLanguageService(uri) {
|
|
138
|
-
var _a;
|
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
const project = (_a = (yield projects.getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
|
|
141
|
-
return project === null || project === void 0 ? void 0 : project.getLanguageService();
|
|
142
|
-
});
|
|
143
|
-
}
|
|
115
|
+
async function createLanguageServiceHost() {
|
|
116
|
+
const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
|
|
117
|
+
fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.runtimeEnv, options) : undefined;
|
|
118
|
+
const tsLocalized = options.typescript && initParams.locale ? await context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
|
|
119
|
+
const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
|
|
120
|
+
const _projects = (0, workspaces_1.createWorkspaces)({
|
|
121
|
+
server: context,
|
|
122
|
+
fileSystemHost: fsHost,
|
|
123
|
+
configurationHost,
|
|
124
|
+
ts,
|
|
125
|
+
tsLocalized,
|
|
126
|
+
initParams: initParams,
|
|
127
|
+
initOptions: options,
|
|
128
|
+
documents,
|
|
129
|
+
cancelTokenHost,
|
|
130
|
+
plugins,
|
|
144
131
|
});
|
|
132
|
+
projects = _projects;
|
|
133
|
+
for (const root of roots) {
|
|
134
|
+
projects.add(root);
|
|
135
|
+
}
|
|
136
|
+
(await Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
|
|
137
|
+
(await Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
|
|
138
|
+
for (const plugin of plugins) {
|
|
139
|
+
plugin.onInitialized?.(getLanguageService, context.runtimeEnv);
|
|
140
|
+
}
|
|
141
|
+
async function getLanguageService(uri) {
|
|
142
|
+
const project = (await projects.getProject(uri))?.project;
|
|
143
|
+
return project?.getLanguageService();
|
|
144
|
+
}
|
|
145
145
|
}
|
|
146
146
|
function getSemanticTokensLegend() {
|
|
147
147
|
if (!options.semanticTokensLegend) {
|
|
148
|
-
return standardSemanticTokensLegend;
|
|
148
|
+
return language_service_1.standardSemanticTokensLegend;
|
|
149
149
|
}
|
|
150
150
|
return {
|
|
151
|
-
tokenTypes: [...standardSemanticTokensLegend.tokenTypes, ...options.semanticTokensLegend.tokenTypes],
|
|
152
|
-
tokenModifiers: [...standardSemanticTokensLegend.tokenModifiers, ...options.semanticTokensLegend.tokenModifiers],
|
|
151
|
+
tokenTypes: [...language_service_1.standardSemanticTokensLegend.tokenTypes, ...options.semanticTokensLegend.tokenTypes],
|
|
152
|
+
tokenModifiers: [...language_service_1.standardSemanticTokensLegend.tokenModifiers, ...options.semanticTokensLegend.tokenModifiers],
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
exports.startCommonLanguageServer = startCommonLanguageServer;
|
|
157
|
-
// https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers
|
|
158
|
-
const standardSemanticTokensLegend = {
|
|
159
|
-
tokenTypes: [
|
|
160
|
-
'namespace',
|
|
161
|
-
'class',
|
|
162
|
-
'enum',
|
|
163
|
-
'interface',
|
|
164
|
-
'struct',
|
|
165
|
-
'typeParameter',
|
|
166
|
-
'type',
|
|
167
|
-
'parameter',
|
|
168
|
-
'variable',
|
|
169
|
-
'property',
|
|
170
|
-
'enumMember',
|
|
171
|
-
'decorator',
|
|
172
|
-
'event',
|
|
173
|
-
'function',
|
|
174
|
-
'method',
|
|
175
|
-
'macro',
|
|
176
|
-
'label',
|
|
177
|
-
'comment',
|
|
178
|
-
'string',
|
|
179
|
-
'keyword',
|
|
180
|
-
'number',
|
|
181
|
-
'regexp',
|
|
182
|
-
'operator',
|
|
183
|
-
],
|
|
184
|
-
tokenModifiers: [
|
|
185
|
-
'declaration',
|
|
186
|
-
'definition',
|
|
187
|
-
'readonly',
|
|
188
|
-
'static',
|
|
189
|
-
'deprecated',
|
|
190
|
-
'abstract',
|
|
191
|
-
'async',
|
|
192
|
-
'modification',
|
|
193
|
-
'documentation',
|
|
194
|
-
'defaultLibrary',
|
|
195
|
-
],
|
|
196
|
-
};
|
|
197
157
|
//# sourceMappingURL=server.js.map
|
|
@@ -1,71 +1,67 @@
|
|
|
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.getInferredCompilerOptions = void 0;
|
|
12
|
-
function getInferredCompilerOptions(configurationHost) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3
|
+
async function getInferredCompilerOptions(configurationHost) {
|
|
4
|
+
let [implicitProjectConfig_1, implicitProjectConfig_2] = await Promise.all([
|
|
5
|
+
configurationHost?.getConfiguration('js/ts.implicitProjectConfig'),
|
|
6
|
+
configurationHost?.getConfiguration('javascript.implicitProjectConfig'),
|
|
7
|
+
]);
|
|
8
|
+
implicitProjectConfig_1 = implicitProjectConfig_1 ?? {};
|
|
9
|
+
implicitProjectConfig_2 = implicitProjectConfig_2 ?? {};
|
|
10
|
+
const checkJs = readCheckJs();
|
|
11
|
+
const experimentalDecorators = readExperimentalDecorators();
|
|
12
|
+
const strictNullChecks = readImplicitStrictNullChecks();
|
|
13
|
+
const strictFunctionTypes = readImplicitStrictFunctionTypes();
|
|
14
|
+
const options = {
|
|
15
|
+
...inferredProjectCompilerOptions('typescript'),
|
|
16
|
+
allowJs: true,
|
|
17
|
+
allowSyntheticDefaultImports: true,
|
|
18
|
+
allowNonTsExtensions: true,
|
|
19
|
+
resolveJsonModule: true,
|
|
20
|
+
jsx: 1 /* ts.JsxEmit.Preserve */,
|
|
21
|
+
};
|
|
22
|
+
return options;
|
|
23
|
+
function readCheckJs() {
|
|
24
|
+
return implicitProjectConfig_1['checkJs']
|
|
25
|
+
?? implicitProjectConfig_2['checkJs']
|
|
26
|
+
?? false;
|
|
27
|
+
}
|
|
28
|
+
function readExperimentalDecorators() {
|
|
29
|
+
return implicitProjectConfig_1['experimentalDecorators']
|
|
30
|
+
?? implicitProjectConfig_2['experimentalDecorators']
|
|
31
|
+
?? false;
|
|
32
|
+
}
|
|
33
|
+
function readImplicitStrictNullChecks() {
|
|
34
|
+
return implicitProjectConfig_1['strictNullChecks'] ?? false;
|
|
35
|
+
}
|
|
36
|
+
function readImplicitStrictFunctionTypes() {
|
|
37
|
+
return implicitProjectConfig_1['strictFunctionTypes'] ?? true;
|
|
38
|
+
}
|
|
39
|
+
function inferredProjectCompilerOptions(projectType) {
|
|
40
|
+
const projectConfig = {
|
|
41
|
+
module: 1 /* ts.ModuleKind.CommonJS */,
|
|
42
|
+
target: 7 /* ts.ScriptTarget.ES2020 */,
|
|
43
|
+
jsx: 1 /* ts.JsxEmit.Preserve */,
|
|
44
|
+
};
|
|
45
|
+
if (checkJs) {
|
|
46
|
+
projectConfig.checkJs = true;
|
|
47
|
+
if (projectType === 'typescript') {
|
|
48
|
+
projectConfig.allowJs = true;
|
|
49
|
+
}
|
|
29
50
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return (_b = (_a = implicitProjectConfig_1['experimentalDecorators']) !== null && _a !== void 0 ? _a : implicitProjectConfig_2['experimentalDecorators']) !== null && _b !== void 0 ? _b : false;
|
|
51
|
+
if (experimentalDecorators) {
|
|
52
|
+
projectConfig.experimentalDecorators = true;
|
|
33
53
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return (_a = implicitProjectConfig_1['strictNullChecks']) !== null && _a !== void 0 ? _a : false;
|
|
54
|
+
if (strictNullChecks) {
|
|
55
|
+
projectConfig.strictNullChecks = true;
|
|
37
56
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return (_a = implicitProjectConfig_1['strictFunctionTypes']) !== null && _a !== void 0 ? _a : true;
|
|
57
|
+
if (strictFunctionTypes) {
|
|
58
|
+
projectConfig.strictFunctionTypes = true;
|
|
41
59
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
module: 1 /* ts.ModuleKind.CommonJS */,
|
|
45
|
-
target: 7 /* ts.ScriptTarget.ES2020 */,
|
|
46
|
-
jsx: 1 /* ts.JsxEmit.Preserve */,
|
|
47
|
-
};
|
|
48
|
-
if (checkJs) {
|
|
49
|
-
projectConfig.checkJs = true;
|
|
50
|
-
if (projectType === 'typescript') {
|
|
51
|
-
projectConfig.allowJs = true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (experimentalDecorators) {
|
|
55
|
-
projectConfig.experimentalDecorators = true;
|
|
56
|
-
}
|
|
57
|
-
if (strictNullChecks) {
|
|
58
|
-
projectConfig.strictNullChecks = true;
|
|
59
|
-
}
|
|
60
|
-
if (strictFunctionTypes) {
|
|
61
|
-
projectConfig.strictFunctionTypes = true;
|
|
62
|
-
}
|
|
63
|
-
if (projectType === 'typescript') {
|
|
64
|
-
projectConfig.sourceMap = true;
|
|
65
|
-
}
|
|
66
|
-
return projectConfig;
|
|
60
|
+
if (projectType === 'typescript') {
|
|
61
|
+
projectConfig.sourceMap = true;
|
|
67
62
|
}
|
|
68
|
-
|
|
63
|
+
return projectConfig;
|
|
64
|
+
}
|
|
69
65
|
}
|
|
70
66
|
exports.getInferredCompilerOptions = getInferredCompilerOptions;
|
|
71
67
|
//# sourceMappingURL=inferredCompilerOptions.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { LanguageServerPlugin, LanguageServerInitializationOptions } from '../../types';
|
|
2
2
|
import * as vscode from 'vscode-languageserver';
|
|
3
|
-
import {
|
|
4
|
-
export declare function setupCapabilities(
|
|
3
|
+
import { Config } from '@volar/language-service';
|
|
4
|
+
export declare function setupCapabilities(server: vscode.ServerCapabilities, initOptions: LanguageServerInitializationOptions, plugins: ReturnType<LanguageServerPlugin>[], semanticTokensLegend: vscode.SemanticTokensLegend, lsPlugins: NonNullable<Config['plugins']>): void;
|
|
@@ -3,99 +3,62 @@ exports.setupCapabilities = 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 setupCapabilities(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, lsPlugins) {
|
|
7
|
+
const lsPluginInstances = Object.values(lsPlugins)
|
|
8
|
+
.map(plugin => typeof plugin === 'function' ? plugin() : plugin)
|
|
9
|
+
.filter((plugin) => !!plugin);
|
|
10
|
+
if (initOptions.serverMode === types_1.ServerMode.Semantic || initOptions.serverMode === types_1.ServerMode.Syntactic) {
|
|
10
11
|
server.selectionRangeProvider = true;
|
|
11
|
-
}
|
|
12
|
-
if (!initOptions.respectClientCapabilities || ((_b = params.textDocument) === null || _b === void 0 ? void 0 : _b.foldingRange)) {
|
|
13
12
|
server.foldingRangeProvider = true;
|
|
14
|
-
}
|
|
15
|
-
if (!initOptions.respectClientCapabilities || ((_c = params.textDocument) === null || _c === void 0 ? void 0 : _c.linkedEditingRange)) {
|
|
16
13
|
server.linkedEditingRangeProvider = true;
|
|
17
|
-
}
|
|
18
|
-
if (!initOptions.respectClientCapabilities || ((_d = params.textDocument) === null || _d === void 0 ? void 0 : _d.colorProvider)) {
|
|
19
14
|
server.colorProvider = true;
|
|
20
|
-
}
|
|
21
|
-
if (!initOptions.respectClientCapabilities || ((_e = params.textDocument) === null || _e === void 0 ? void 0 : _e.documentSymbol)) {
|
|
22
15
|
server.documentSymbolProvider = true;
|
|
23
|
-
}
|
|
24
|
-
if (!initOptions.respectClientCapabilities || ((_f = params.textDocument) === null || _f === void 0 ? void 0 : _f.formatting)) {
|
|
25
16
|
server.documentFormattingProvider = true;
|
|
26
|
-
}
|
|
27
|
-
if (!initOptions.respectClientCapabilities || ((_g = params.textDocument) === null || _g === void 0 ? void 0 : _g.rangeFormatting)) {
|
|
28
17
|
server.documentRangeFormattingProvider = true;
|
|
18
|
+
const characters = [...new Set(lsPluginInstances.map(plugin => plugin.autoFormatTriggerCharacters ?? []).flat())];
|
|
19
|
+
if (characters.length) {
|
|
20
|
+
server.documentOnTypeFormattingProvider = {
|
|
21
|
+
firstTriggerCharacter: characters[0],
|
|
22
|
+
moreTriggerCharacter: characters.slice(1),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
29
25
|
}
|
|
30
|
-
if (
|
|
31
|
-
// https://github.com/microsoft/vscode/blob/ce119308e8fd4cd3f992d42b297588e7abe33a0c/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L99
|
|
32
|
-
server.documentOnTypeFormattingProvider = {
|
|
33
|
-
firstTriggerCharacter: ';',
|
|
34
|
-
moreTriggerCharacter: ['}', '\n'],
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
// Semantic
|
|
38
|
-
if (!initOptions.respectClientCapabilities || ((_j = params.textDocument) === null || _j === void 0 ? void 0 : _j.references)) {
|
|
26
|
+
if (initOptions.serverMode === types_1.ServerMode.Semantic || initOptions.serverMode === types_1.ServerMode.PartialSemantic) {
|
|
39
27
|
server.referencesProvider = true;
|
|
40
|
-
}
|
|
41
|
-
if (!initOptions.respectClientCapabilities || ((_k = params.textDocument) === null || _k === void 0 ? void 0 : _k.implementation)) {
|
|
42
28
|
server.implementationProvider = true;
|
|
43
|
-
}
|
|
44
|
-
if (!initOptions.respectClientCapabilities || ((_l = params.textDocument) === null || _l === void 0 ? void 0 : _l.definition)) {
|
|
45
29
|
server.definitionProvider = true;
|
|
46
|
-
}
|
|
47
|
-
if (!initOptions.respectClientCapabilities || ((_m = params.textDocument) === null || _m === void 0 ? void 0 : _m.typeDefinition)) {
|
|
48
30
|
server.typeDefinitionProvider = true;
|
|
49
|
-
}
|
|
50
|
-
if (!initOptions.respectClientCapabilities || ((_o = params.textDocument) === null || _o === void 0 ? void 0 : _o.callHierarchy)) {
|
|
51
31
|
server.callHierarchyProvider = true;
|
|
52
|
-
}
|
|
53
|
-
if (!initOptions.respectClientCapabilities || ((_p = params.textDocument) === null || _p === void 0 ? void 0 : _p.hover)) {
|
|
54
32
|
server.hoverProvider = true;
|
|
55
|
-
}
|
|
56
|
-
if (!initOptions.respectClientCapabilities || ((_q = params.textDocument) === null || _q === void 0 ? void 0 : _q.rename)) {
|
|
57
33
|
server.renameProvider = {
|
|
58
34
|
prepareProvider: true,
|
|
59
35
|
};
|
|
60
|
-
}
|
|
61
|
-
if (!initOptions.respectClientCapabilities || ((_r = params.textDocument) === null || _r === void 0 ? void 0 : _r.signatureHelp)) {
|
|
62
36
|
server.signatureHelpProvider = {
|
|
63
|
-
triggerCharacters: [
|
|
64
|
-
retriggerCharacters: [
|
|
37
|
+
triggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.signatureHelpTriggerCharacters ?? []).flat())],
|
|
38
|
+
retriggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.signatureHelpRetriggerCharacters ?? []).flat())],
|
|
65
39
|
};
|
|
66
|
-
}
|
|
67
|
-
if (!initOptions.respectClientCapabilities || ((_s = params.textDocument) === null || _s === void 0 ? void 0 : _s.completion)) {
|
|
68
40
|
server.completionProvider = {
|
|
69
|
-
triggerCharacters:
|
|
41
|
+
triggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.triggerCharacters ?? []).flat())],
|
|
70
42
|
resolveProvider: true,
|
|
71
43
|
};
|
|
72
44
|
if (initOptions.ignoreTriggerCharacters) {
|
|
73
|
-
server.completionProvider.triggerCharacters =
|
|
45
|
+
server.completionProvider.triggerCharacters = server.completionProvider.triggerCharacters
|
|
46
|
+
?.filter(c => !initOptions.ignoreTriggerCharacters.includes(c));
|
|
74
47
|
}
|
|
75
|
-
}
|
|
76
|
-
if (!initOptions.respectClientCapabilities || ((_u = params.textDocument) === null || _u === void 0 ? void 0 : _u.documentHighlight)) {
|
|
77
48
|
server.documentHighlightProvider = true;
|
|
78
|
-
}
|
|
79
|
-
if (!initOptions.respectClientCapabilities || ((_v = params.textDocument) === null || _v === void 0 ? void 0 : _v.documentLink)) {
|
|
80
49
|
server.documentLinkProvider = {
|
|
81
50
|
resolveProvider: false, // TODO
|
|
82
51
|
};
|
|
83
|
-
}
|
|
84
|
-
if (!initOptions.respectClientCapabilities || ((_w = params.textDocument) === null || _w === void 0 ? void 0 : _w.codeLens)) {
|
|
85
52
|
server.codeLensProvider = {
|
|
86
53
|
resolveProvider: true,
|
|
87
54
|
};
|
|
88
|
-
|
|
55
|
+
server.executeCommandProvider ??= { commands: [] };
|
|
89
56
|
server.executeCommandProvider.commands.push(embedded.showReferencesCommand);
|
|
90
|
-
}
|
|
91
|
-
if (!initOptions.respectClientCapabilities || ((_y = params.textDocument) === null || _y === void 0 ? void 0 : _y.semanticTokens)) {
|
|
92
57
|
server.semanticTokensProvider = {
|
|
93
58
|
range: true,
|
|
94
59
|
full: false,
|
|
95
60
|
legend: semanticTokensLegend,
|
|
96
61
|
};
|
|
97
|
-
}
|
|
98
|
-
if (!initOptions.respectClientCapabilities || ((_z = params.textDocument) === null || _z === void 0 ? void 0 : _z.codeAction)) {
|
|
99
62
|
server.codeActionProvider = {
|
|
100
63
|
codeActionKinds: [
|
|
101
64
|
vscode.CodeActionKind.Empty,
|
|
@@ -110,23 +73,8 @@ function setupCapabilities(params, server, initOptions, plugins, semanticTokensL
|
|
|
110
73
|
],
|
|
111
74
|
resolveProvider: true,
|
|
112
75
|
};
|
|
113
|
-
}
|
|
114
|
-
if (!initOptions.respectClientCapabilities || ((_0 = params.textDocument) === null || _0 === void 0 ? void 0 : _0.inlayHint)) {
|
|
115
76
|
server.inlayHintProvider = true;
|
|
116
|
-
|
|
117
|
-
if ((!initOptions.respectClientCapabilities || ((_1 = params.textDocument) === null || _1 === void 0 ? void 0 : _1.diagnostic)) && ((_2 = initOptions.diagnosticModel) !== null && _2 !== void 0 ? _2 : types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
|
|
118
|
-
const selector = plugins.map(plugin => { var _a; return (_a = plugin.diagnosticDocumentSelector) !== null && _a !== void 0 ? _a : []; }).flat();
|
|
119
|
-
if (selector) {
|
|
120
|
-
server.diagnosticProvider = {
|
|
121
|
-
documentSelector: selector,
|
|
122
|
-
interFileDependencies: true,
|
|
123
|
-
workspaceDiagnostics: false,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// cross file features
|
|
128
|
-
if (!initOptions.respectClientCapabilities || ((_3 = params.workspace) === null || _3 === void 0 ? void 0 : _3.fileOperations)) {
|
|
129
|
-
const exts = plugins.map(plugin => plugin.extensions.fileRenameOperationFilter).flat();
|
|
77
|
+
const exts = plugins.map(plugin => plugin.watchFileExtensions).flat();
|
|
130
78
|
if (exts.length) {
|
|
131
79
|
server.workspace = {
|
|
132
80
|
fileOperations: {
|
|
@@ -142,10 +90,15 @@ function setupCapabilities(params, server, initOptions, plugins, semanticTokensL
|
|
|
142
90
|
}
|
|
143
91
|
};
|
|
144
92
|
}
|
|
145
|
-
}
|
|
146
|
-
if (!initOptions.respectClientCapabilities || ((_4 = params.workspace) === null || _4 === void 0 ? void 0 : _4.symbol)) {
|
|
147
93
|
server.workspaceSymbolProvider = true;
|
|
148
94
|
}
|
|
95
|
+
// diagnostics are shunted in the api
|
|
96
|
+
if ((initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
|
|
97
|
+
server.diagnosticProvider = {
|
|
98
|
+
interFileDependencies: true,
|
|
99
|
+
workspaceDiagnostics: false,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
149
102
|
}
|
|
150
103
|
exports.setupCapabilities = setupCapabilities;
|
|
151
104
|
//# sourceMappingURL=registerFeatures.js.map
|
|
@@ -3,9 +3,9 @@ exports.loadConfig = void 0;
|
|
|
3
3
|
function loadConfig(dir, configFile) {
|
|
4
4
|
let configPath;
|
|
5
5
|
try {
|
|
6
|
-
configPath = require.resolve(configFile
|
|
6
|
+
configPath = require.resolve(configFile ?? './volar.config.js', { paths: [dir] });
|
|
7
7
|
}
|
|
8
|
-
catch
|
|
8
|
+
catch { }
|
|
9
9
|
try {
|
|
10
10
|
if (configPath) {
|
|
11
11
|
const config = require(configPath);
|