@volar/language-server 1.4.0-alpha.0 → 1.4.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/browser/fileSystems.js +82 -102
- package/out/browser/index.js +10 -23
- 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.js +127 -152
- package/out/common/project.d.ts +62 -62
- package/out/common/project.js +211 -227
- package/out/common/server.js +51 -65
- package/out/common/utils/inferredCompilerOptions.js +57 -61
- package/out/common/utils/registerFeatures.js +8 -8
- package/out/common/utils/serverConfig.js +2 -2
- package/out/common/utils/uriMap.js +1 -1
- package/out/common/workspace.d.ts +558 -558
- package/out/common/workspace.js +164 -193
- package/out/common/workspaces.d.ts +682 -682
- package/out/common/workspaces.js +81 -107
- package/out/node/fileSystem.js +4 -14
- package/out/node/index.js +7 -18
- package/package.json +4 -4
package/out/common/server.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.startCommonLanguageServer = void 0;
|
|
12
3
|
const language_service_1 = require("@volar/language-service");
|
|
@@ -30,17 +21,16 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
30
21
|
let plugins;
|
|
31
22
|
let documents;
|
|
32
23
|
let context;
|
|
33
|
-
connection.onInitialize((_params) =>
|
|
34
|
-
var _a, _b, _c, _d;
|
|
24
|
+
connection.onInitialize(async (_params) => {
|
|
35
25
|
initParams = _params;
|
|
36
26
|
options = initParams.initializationOptions;
|
|
37
27
|
context = getCtx(options);
|
|
38
28
|
plugins = context.plugins.map(plugin => plugin(options));
|
|
39
29
|
documents = (0, documents_1.createDocuments)(context.runtimeEnv, connection);
|
|
40
30
|
if (options.l10n) {
|
|
41
|
-
|
|
31
|
+
await l10n.config({ uri: options.l10n.location });
|
|
42
32
|
}
|
|
43
|
-
if (
|
|
33
|
+
if (initParams.capabilities.workspace?.workspaceFolders && initParams.workspaceFolders) {
|
|
44
34
|
roots = initParams.workspaceFolders.map(folder => vscode_uri_1.URI.parse(folder.uri));
|
|
45
35
|
}
|
|
46
36
|
else if (initParams.rootUri) {
|
|
@@ -51,27 +41,30 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
51
41
|
}
|
|
52
42
|
const result = {
|
|
53
43
|
capabilities: {
|
|
54
|
-
textDocumentSync:
|
|
44
|
+
textDocumentSync: options.textDocumentSync ?? vscode.TextDocumentSyncKind.Incremental,
|
|
55
45
|
},
|
|
56
46
|
};
|
|
57
|
-
configurationHost =
|
|
47
|
+
configurationHost = initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
|
|
58
48
|
let lsPlugins = {};
|
|
59
49
|
const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
|
|
60
50
|
for (const root of roots) {
|
|
61
51
|
if (root.scheme === 'file') {
|
|
62
|
-
let config = (
|
|
52
|
+
let config = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath) ?? {};
|
|
63
53
|
for (const plugin of plugins) {
|
|
64
54
|
if (plugin.resolveConfig) {
|
|
65
55
|
config = plugin.resolveConfig(config, { typescript: ts });
|
|
66
56
|
}
|
|
67
57
|
}
|
|
68
58
|
if (config.plugins) {
|
|
69
|
-
lsPlugins =
|
|
59
|
+
lsPlugins = {
|
|
60
|
+
...lsPlugins,
|
|
61
|
+
...config.plugins,
|
|
62
|
+
};
|
|
70
63
|
}
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
66
|
(0, registerFeatures_1.setupCapabilities)(result.capabilities, options, plugins, getSemanticTokensLegend(), lsPlugins);
|
|
74
|
-
|
|
67
|
+
await createLanguageServiceHost();
|
|
75
68
|
try {
|
|
76
69
|
// show version on LSP logs
|
|
77
70
|
const packageJson = require('../package.json');
|
|
@@ -80,26 +73,25 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
80
73
|
version: packageJson.version,
|
|
81
74
|
};
|
|
82
75
|
}
|
|
83
|
-
catch
|
|
76
|
+
catch { }
|
|
84
77
|
return result;
|
|
85
|
-
})
|
|
78
|
+
});
|
|
86
79
|
connection.onInitialized(() => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
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) {
|
|
91
83
|
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
92
84
|
for (const folder of e.added) {
|
|
93
|
-
projects
|
|
85
|
+
projects?.add(vscode_uri_1.URI.parse(folder.uri));
|
|
94
86
|
}
|
|
95
87
|
for (const folder of e.removed) {
|
|
96
|
-
projects
|
|
88
|
+
projects?.remove(vscode_uri_1.URI.parse(folder.uri));
|
|
97
89
|
}
|
|
98
90
|
});
|
|
99
91
|
}
|
|
100
92
|
if (options.serverMode !== types_1.ServerMode.Syntactic
|
|
101
93
|
&& !options.disableFileWatcher
|
|
102
|
-
&&
|
|
94
|
+
&& initParams.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration) {
|
|
103
95
|
const exts = plugins.map(plugin => plugin.watchFileExtensions).flat();
|
|
104
96
|
if (exts.length) {
|
|
105
97
|
connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
|
@@ -112,50 +104,44 @@ function startCommonLanguageServer(connection, getCtx) {
|
|
|
112
104
|
}
|
|
113
105
|
}
|
|
114
106
|
});
|
|
115
|
-
connection.onShutdown(() =>
|
|
107
|
+
connection.onShutdown(async () => {
|
|
116
108
|
if (projects) {
|
|
117
109
|
for (const workspace of projects.workspaces) {
|
|
118
|
-
(
|
|
110
|
+
(await workspace[1]).dispose();
|
|
119
111
|
}
|
|
120
112
|
}
|
|
121
|
-
})
|
|
113
|
+
});
|
|
122
114
|
connection.listen();
|
|
123
|
-
function createLanguageServiceHost() {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
cancelTokenHost,
|
|
140
|
-
plugins,
|
|
141
|
-
});
|
|
142
|
-
projects = _projects;
|
|
143
|
-
for (const root of roots) {
|
|
144
|
-
projects.add(root);
|
|
145
|
-
}
|
|
146
|
-
(yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
|
|
147
|
-
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
|
|
148
|
-
for (const plugin of plugins) {
|
|
149
|
-
(_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService, context.runtimeEnv);
|
|
150
|
-
}
|
|
151
|
-
function getLanguageService(uri) {
|
|
152
|
-
var _a;
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
const project = (_a = (yield projects.getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
|
|
155
|
-
return project === null || project === void 0 ? void 0 : project.getLanguageService();
|
|
156
|
-
});
|
|
157
|
-
}
|
|
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,
|
|
158
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
|
+
}
|
|
159
145
|
}
|
|
160
146
|
function getSemanticTokensLegend() {
|
|
161
147
|
if (!options.semanticTokensLegend) {
|
|
@@ -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
|
|
@@ -4,7 +4,6 @@ const embedded = require("@volar/language-service");
|
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const vscode = require("vscode-languageserver");
|
|
6
6
|
function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, lsPlugins) {
|
|
7
|
-
var _a, _b, _c;
|
|
8
7
|
const lsPluginInstances = Object.values(lsPlugins)
|
|
9
8
|
.map(plugin => typeof plugin === 'function' ? plugin() : plugin)
|
|
10
9
|
.filter((plugin) => !!plugin);
|
|
@@ -16,7 +15,7 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
|
|
|
16
15
|
server.documentSymbolProvider = true;
|
|
17
16
|
server.documentFormattingProvider = true;
|
|
18
17
|
server.documentRangeFormattingProvider = true;
|
|
19
|
-
const characters = [...new Set(lsPluginInstances.map(plugin =>
|
|
18
|
+
const characters = [...new Set(lsPluginInstances.map(plugin => plugin.autoFormatTriggerCharacters ?? []).flat())];
|
|
20
19
|
if (characters.length) {
|
|
21
20
|
server.documentOnTypeFormattingProvider = {
|
|
22
21
|
firstTriggerCharacter: characters[0],
|
|
@@ -35,15 +34,16 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
|
|
|
35
34
|
prepareProvider: true,
|
|
36
35
|
};
|
|
37
36
|
server.signatureHelpProvider = {
|
|
38
|
-
triggerCharacters: [...new Set(lsPluginInstances.map(plugin =>
|
|
39
|
-
retriggerCharacters: [...new Set(lsPluginInstances.map(plugin =>
|
|
37
|
+
triggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.signatureHelpTriggerCharacters ?? []).flat())],
|
|
38
|
+
retriggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.signatureHelpRetriggerCharacters ?? []).flat())],
|
|
40
39
|
};
|
|
41
40
|
server.completionProvider = {
|
|
42
|
-
triggerCharacters: [...new Set(lsPluginInstances.map(plugin =>
|
|
41
|
+
triggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.triggerCharacters ?? []).flat())],
|
|
43
42
|
resolveProvider: true,
|
|
44
43
|
};
|
|
45
44
|
if (initOptions.ignoreTriggerCharacters) {
|
|
46
|
-
server.completionProvider.triggerCharacters =
|
|
45
|
+
server.completionProvider.triggerCharacters = server.completionProvider.triggerCharacters
|
|
46
|
+
?.filter(c => !initOptions.ignoreTriggerCharacters.includes(c));
|
|
47
47
|
}
|
|
48
48
|
server.documentHighlightProvider = true;
|
|
49
49
|
server.documentLinkProvider = {
|
|
@@ -52,7 +52,7 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
|
|
|
52
52
|
server.codeLensProvider = {
|
|
53
53
|
resolveProvider: true,
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
server.executeCommandProvider ??= { commands: [] };
|
|
56
56
|
server.executeCommandProvider.commands.push(embedded.showReferencesCommand);
|
|
57
57
|
server.semanticTokensProvider = {
|
|
58
58
|
range: true,
|
|
@@ -93,7 +93,7 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
|
|
|
93
93
|
server.workspaceSymbolProvider = true;
|
|
94
94
|
}
|
|
95
95
|
// diagnostics are shunted in the api
|
|
96
|
-
if ((
|
|
96
|
+
if ((initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
|
|
97
97
|
server.diagnosticProvider = {
|
|
98
98
|
interFileDependencies: true,
|
|
99
99
|
workspaceDiagnostics: false,
|
|
@@ -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);
|