@volar/language-server 2.1.4 → 2.2.0-alpha.0
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/lib/project/inferredCompilerOptions.d.ts +2 -2
- package/lib/project/inferredCompilerOptions.js +3 -3
- package/lib/project/simpleProject.d.ts +2 -2
- package/lib/project/simpleProject.js +4 -4
- package/lib/project/simpleProjectProvider.js +2 -2
- package/lib/project/typescriptProject.d.ts +2 -2
- package/lib/project/typescriptProject.js +30 -11
- package/lib/project/typescriptProjectProvider.js +1 -1
- package/lib/register/registerEditorFeatures.js +35 -37
- package/lib/server.d.ts +4 -4
- package/lib/server.js +77 -42
- package/lib/serverCapabilities.d.ts +2 -2
- package/lib/types.d.ts +2 -2
- package/package.json +6 -6
- package/lib/configurationHost.d.ts +0 -5
- package/lib/configurationHost.js +0 -43
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function getInferredCompilerOptions(
|
|
2
|
+
import type { ServerContext } from '../server';
|
|
3
|
+
export declare function getInferredCompilerOptions(context: ServerContext): Promise<ts.CompilerOptions>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getInferredCompilerOptions = void 0;
|
|
4
|
-
async function getInferredCompilerOptions(
|
|
4
|
+
async function getInferredCompilerOptions(context) {
|
|
5
5
|
const [implicitProjectConfig_1 = {}, implicitProjectConfig_2 = {},] = await Promise.all([
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
context.getConfiguration('js/ts.implicitProjectConfig'),
|
|
7
|
+
context.getConfiguration('javascript.implicitProjectConfig'),
|
|
8
8
|
]);
|
|
9
9
|
const checkJs = readCheckJs();
|
|
10
10
|
const experimentalDecorators = readExperimentalDecorators();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServiceEnvironment,
|
|
1
|
+
import { ServiceEnvironment, LanguageServicePlugin } from '@volar/language-service';
|
|
2
2
|
import type { ServerContext, ServerOptions } from '../server';
|
|
3
3
|
import type { ServerProject } from '../types';
|
|
4
|
-
export declare function createSimpleServerProject(context: ServerContext, serviceEnv: ServiceEnvironment, servicePlugins:
|
|
4
|
+
export declare function createSimpleServerProject(context: ServerContext, serviceEnv: ServiceEnvironment, servicePlugins: LanguageServicePlugin[], getLanguagePlugins: ServerOptions['getLanguagePlugins']): Promise<ServerProject>;
|
|
@@ -14,16 +14,16 @@ async function createSimpleServerProject(context, serviceEnv, servicePlugins, ge
|
|
|
14
14
|
};
|
|
15
15
|
function getLanguageService() {
|
|
16
16
|
if (!languageService) {
|
|
17
|
-
const
|
|
17
|
+
const language = (0, language_service_1.createLanguage)(languagePlugins, false, uri => {
|
|
18
18
|
const script = context.documents.get(uri);
|
|
19
19
|
if (script) {
|
|
20
|
-
|
|
20
|
+
language.scripts.set(uri, script.languageId, script.getSnapshot());
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
|
-
|
|
23
|
+
language.scripts.delete(uri);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
languageService = (0, language_service_1.createLanguageService)(
|
|
26
|
+
languageService = (0, language_service_1.createLanguageService)(language, servicePlugins, serviceEnv);
|
|
27
27
|
}
|
|
28
28
|
return languageService;
|
|
29
29
|
}
|
|
@@ -38,8 +38,8 @@ function createServiceEnvironment(context, workspaceFolder) {
|
|
|
38
38
|
fs: context.runtimeEnv.fs,
|
|
39
39
|
locale: context.initializeParams.locale,
|
|
40
40
|
clientCapabilities: context.initializeParams.capabilities,
|
|
41
|
-
getConfiguration: context.
|
|
42
|
-
onDidChangeConfiguration: context.
|
|
41
|
+
getConfiguration: context.getConfiguration,
|
|
42
|
+
onDidChangeConfiguration: context.onDidChangeConfiguration,
|
|
43
43
|
onDidChangeWatchedFiles: context.onDidChangeWatchedFiles,
|
|
44
44
|
typescript: {
|
|
45
45
|
fileNameToUri: uri_1.fileNameToUri,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServiceEnvironment,
|
|
1
|
+
import { ServiceEnvironment, LanguageServicePlugin } from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { ServerProject } from '../types';
|
|
4
4
|
import { UriMap } from '../utils/uriMap';
|
|
@@ -8,4 +8,4 @@ export interface TypeScriptServerProject extends ServerProject {
|
|
|
8
8
|
tryAddFile(fileName: string): void;
|
|
9
9
|
getParsedCommandLine(): ts.ParsedCommandLine;
|
|
10
10
|
}
|
|
11
|
-
export declare function createTypeScriptServerProject(ts: typeof import('typescript'), tsLocalized: ts.MapLike<string> | undefined, tsconfig: string | ts.CompilerOptions, context: ServerContext, serviceEnv: ServiceEnvironment, servicePlugins:
|
|
11
|
+
export declare function createTypeScriptServerProject(ts: typeof import('typescript'), tsLocalized: ts.MapLike<string> | undefined, tsconfig: string | ts.CompilerOptions, context: ServerContext, serviceEnv: ServiceEnvironment, servicePlugins: LanguageServicePlugin[], getLanguagePlugins: ServerOptions['getLanguagePlugins']): Promise<TypeScriptServerProject>;
|
|
@@ -13,20 +13,42 @@ async function createTypeScriptServerProject(ts, tsLocalized, tsconfig, context,
|
|
|
13
13
|
let languageService;
|
|
14
14
|
const sys = (0, typescript_1.createSys)(ts, serviceEnv, (0, uri_1.uriToFileName)(serviceEnv.workspaceFolder));
|
|
15
15
|
const host = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
...sys,
|
|
17
|
+
configFileName: typeof tsconfig === 'string' ? tsconfig : undefined,
|
|
18
|
+
getSystemVersion() {
|
|
19
|
+
return sys.version;
|
|
20
|
+
},
|
|
21
|
+
syncSystem() {
|
|
22
|
+
return sys.sync();
|
|
23
|
+
},
|
|
24
|
+
getCurrentDirectory() {
|
|
25
|
+
return (0, uri_1.uriToFileName)(serviceEnv.workspaceFolder);
|
|
26
|
+
},
|
|
27
|
+
getProjectVersion() {
|
|
28
|
+
return projectVersion.toString();
|
|
29
|
+
},
|
|
30
|
+
getScriptFileNames() {
|
|
31
|
+
return rootFiles;
|
|
32
|
+
},
|
|
33
|
+
getScriptSnapshot(fileName) {
|
|
20
34
|
askedFiles.pathSet(fileName, true);
|
|
21
35
|
const doc = context.documents.get((0, uri_1.fileNameToUri)(fileName));
|
|
22
36
|
if (doc) {
|
|
23
37
|
return doc.getSnapshot();
|
|
24
38
|
}
|
|
25
39
|
},
|
|
26
|
-
getCompilationSettings
|
|
40
|
+
getCompilationSettings() {
|
|
41
|
+
return parsedCommandLine.options;
|
|
42
|
+
},
|
|
27
43
|
getLocalizedDiagnosticMessages: tsLocalized ? () => tsLocalized : undefined,
|
|
28
|
-
getProjectReferences
|
|
29
|
-
|
|
44
|
+
getProjectReferences() {
|
|
45
|
+
return parsedCommandLine.projectReferences;
|
|
46
|
+
},
|
|
47
|
+
getLanguageId(uri) {
|
|
48
|
+
return context.documents.get(uri)?.languageId ?? (0, language_service_1.resolveCommonLanguageId)(uri);
|
|
49
|
+
},
|
|
50
|
+
fileNameToScriptId: serviceEnv.typescript.fileNameToUri,
|
|
51
|
+
scriptIdToFileName: serviceEnv.typescript.uriToFileName,
|
|
30
52
|
};
|
|
31
53
|
const languagePlugins = await getLanguagePlugins(serviceEnv, {
|
|
32
54
|
typescript: {
|
|
@@ -62,10 +84,7 @@ async function createTypeScriptServerProject(ts, tsLocalized, tsconfig, context,
|
|
|
62
84
|
}
|
|
63
85
|
function getLanguageService() {
|
|
64
86
|
if (!languageService) {
|
|
65
|
-
const language = (0, typescript_1.
|
|
66
|
-
fileNameToFileId: serviceEnv.typescript.fileNameToUri,
|
|
67
|
-
fileIdToFileName: serviceEnv.typescript.uriToFileName,
|
|
68
|
-
});
|
|
87
|
+
const language = (0, typescript_1.createTypeScriptLanguage)(ts, languagePlugins, host);
|
|
69
88
|
languageService = (0, language_service_1.createLanguageService)(language, servicePlugins, serviceEnv);
|
|
70
89
|
}
|
|
71
90
|
return languageService;
|
|
@@ -188,7 +188,7 @@ function createTypeScriptProjectProviderFactory(ts, tsLocalized) {
|
|
|
188
188
|
async function getOrCreateInferredProject(uri, workspaceFolder) {
|
|
189
189
|
if (!inferredProjects.uriHas(workspaceFolder)) {
|
|
190
190
|
inferredProjects.uriSet(workspaceFolder, (async () => {
|
|
191
|
-
const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context
|
|
191
|
+
const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context);
|
|
192
192
|
const serviceEnv = (0, simpleProjectProvider_1.createServiceEnvironment)(context, workspaceFolder);
|
|
193
193
|
return (0, typescriptProject_1.createTypeScriptServerProject)(ts, tsLocalized, inferOptions, context, serviceEnv, servicePlugins, getLanguagePlugins);
|
|
194
194
|
})());
|
|
@@ -32,53 +32,50 @@ function registerEditorFeatures(connection, projects) {
|
|
|
32
32
|
});
|
|
33
33
|
connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, async (params) => {
|
|
34
34
|
const languageService = (await projects.getProject(params.uri)).getLanguageService();
|
|
35
|
-
const configFileName = languageService.context.language.typescript?.configFileName;
|
|
35
|
+
const configFileName = languageService.context.language.typescript?.projectHost.configFileName;
|
|
36
36
|
if (configFileName) {
|
|
37
37
|
return { uri: (0, uri_1.fileNameToUri)(configFileName) };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
connection.onRequest(protocol_1.GetVirtualFileRequest.type, async (document) => {
|
|
41
41
|
const languageService = (await projects.getProject(document.uri)).getLanguageService();
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
return prune(
|
|
42
|
+
const sourceScript = languageService.context.language.scripts.get(document.uri);
|
|
43
|
+
if (sourceScript?.generated) {
|
|
44
|
+
return prune(sourceScript.generated.root);
|
|
45
45
|
}
|
|
46
|
-
function prune(
|
|
47
|
-
const uri = languageService.context.
|
|
46
|
+
function prune(virtualCode) {
|
|
47
|
+
const uri = languageService.context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
|
|
48
48
|
let version = scriptVersions.get(uri) ?? 0;
|
|
49
|
-
if (!scriptVersionSnapshots.has(
|
|
49
|
+
if (!scriptVersionSnapshots.has(virtualCode.snapshot)) {
|
|
50
50
|
version++;
|
|
51
51
|
scriptVersions.set(uri, version);
|
|
52
|
-
scriptVersionSnapshots.add(
|
|
52
|
+
scriptVersionSnapshots.add(virtualCode.snapshot);
|
|
53
53
|
}
|
|
54
54
|
return {
|
|
55
|
-
fileUri:
|
|
56
|
-
virtualCodeId:
|
|
57
|
-
languageId:
|
|
58
|
-
embeddedCodes:
|
|
55
|
+
fileUri: sourceScript.id,
|
|
56
|
+
virtualCodeId: virtualCode.id,
|
|
57
|
+
languageId: virtualCode.languageId,
|
|
58
|
+
embeddedCodes: virtualCode.embeddedCodes?.map(prune) || [],
|
|
59
59
|
version,
|
|
60
|
-
disabled: languageService.context.
|
|
60
|
+
disabled: languageService.context.disabledEmbeddedDocumentUris.has(uri),
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
64
|
connection.onRequest(protocol_1.GetVirtualCodeRequest.type, async (params) => {
|
|
65
|
-
let content = '';
|
|
66
|
-
let codegenStacks = [];
|
|
67
65
|
const languageService = (await projects.getProject(params.fileUri)).getLanguageService();
|
|
68
|
-
const
|
|
69
|
-
const
|
|
66
|
+
const sourceScript = languageService.context.language.scripts.get(params.fileUri);
|
|
67
|
+
const virtualCode = sourceScript?.generated?.embeddedCodes.get(params.virtualCodeId);
|
|
70
68
|
if (virtualCode) {
|
|
69
|
+
const mappings = {};
|
|
71
70
|
for (const map of languageService.context.documents.getMaps(virtualCode)) {
|
|
72
|
-
content = map.embeddedDocument.getText();
|
|
73
|
-
codegenStacks = virtualCode.codegenStacks ?? [];
|
|
74
71
|
mappings[map.sourceDocument.uri] = map.map.mappings;
|
|
75
72
|
}
|
|
73
|
+
return {
|
|
74
|
+
content: virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength()),
|
|
75
|
+
codegenStacks: virtualCode.codegenStacks ?? [],
|
|
76
|
+
mappings,
|
|
77
|
+
};
|
|
76
78
|
}
|
|
77
|
-
return {
|
|
78
|
-
content,
|
|
79
|
-
mappings,
|
|
80
|
-
codegenStacks,
|
|
81
|
-
};
|
|
82
79
|
});
|
|
83
80
|
connection.onNotification(protocol_1.ReloadProjectNotification.type, () => {
|
|
84
81
|
projects.reloadProjects();
|
|
@@ -101,16 +98,16 @@ function registerEditorFeatures(connection, projects) {
|
|
|
101
98
|
else {
|
|
102
99
|
const uri = languageService.context.env.typescript.fileNameToUri(fileName);
|
|
103
100
|
if (uri.startsWith(rootUri)) {
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
const { snapshot } =
|
|
109
|
-
fs.writeFile(fileName +
|
|
101
|
+
const sourceScript = languageService.context.language.scripts.get(uri);
|
|
102
|
+
if (sourceScript?.generated) {
|
|
103
|
+
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
104
|
+
if (serviceScript) {
|
|
105
|
+
const { snapshot } = serviceScript.code;
|
|
106
|
+
fs.writeFile(fileName + serviceScript.extension, snapshot.getText(0, snapshot.getLength()), () => { });
|
|
110
107
|
}
|
|
111
|
-
if (
|
|
112
|
-
for (const
|
|
113
|
-
const { snapshot } =
|
|
108
|
+
if (sourceScript.generated.languagePlugin.typescript?.getExtraServiceScripts) {
|
|
109
|
+
for (const extraServiceScript of sourceScript.generated.languagePlugin.typescript.getExtraServiceScripts(uri, sourceScript.generated.root)) {
|
|
110
|
+
const { snapshot } = extraServiceScript.code;
|
|
114
111
|
fs.writeFile(fileName, snapshot.getText(0, snapshot.getLength()), () => { });
|
|
115
112
|
}
|
|
116
113
|
}
|
|
@@ -127,7 +124,8 @@ function registerEditorFeatures(connection, projects) {
|
|
|
127
124
|
const tsLanguageService = languageService.context.inject('typescript/languageService');
|
|
128
125
|
const program = tsLanguageService?.getProgram();
|
|
129
126
|
if (program && languageService.context.language.typescript) {
|
|
130
|
-
const {
|
|
127
|
+
const { languageServiceHost } = languageService.context.language.typescript;
|
|
128
|
+
const { configFileName } = languageService.context.language.typescript.projectHost;
|
|
131
129
|
const projectName = configFileName ?? (languageServiceHost.getCurrentDirectory() + '(inferred)');
|
|
132
130
|
const sourceFiles = program.getSourceFiles() ?? [];
|
|
133
131
|
for (const sourceFile of sourceFiles) {
|
|
@@ -171,12 +169,12 @@ function registerEditorFeatures(connection, projects) {
|
|
|
171
169
|
const project = await projects.getProject(params.fileUri);
|
|
172
170
|
const context = project.getLanguageServiceDontCreate()?.context;
|
|
173
171
|
if (context) {
|
|
174
|
-
const virtualFileUri = project.getLanguageService().context.
|
|
172
|
+
const virtualFileUri = project.getLanguageService().context.encodeEmbeddedDocumentUri(params.fileUri, params.virtualCodeId);
|
|
175
173
|
if (params.disabled) {
|
|
176
|
-
context.
|
|
174
|
+
context.disabledEmbeddedDocumentUris.add(virtualFileUri);
|
|
177
175
|
}
|
|
178
176
|
else {
|
|
179
|
-
context.
|
|
177
|
+
context.disabledEmbeddedDocumentUris.delete(virtualFileUri);
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
});
|
package/lib/server.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { LanguagePlugin, ServiceEnvironment,
|
|
1
|
+
import { LanguagePlugin, ServiceEnvironment, LanguageServicePlugin } from '@volar/language-service';
|
|
2
2
|
import { SnapshotDocument } from '@volar/snapshot-document';
|
|
3
3
|
import type { TextDocuments } from 'vscode-languageserver';
|
|
4
4
|
import * as vscode from 'vscode-languageserver';
|
|
5
|
-
import { createConfigurationHost } from './configurationHost.js';
|
|
6
5
|
import { InitializationOptions, ProjectContext, ServerProjectProvider, ServerProjectProviderFactory, ServerRuntimeEnvironment } from './types.js';
|
|
7
6
|
import { type UriMap } from './utils/uriMap.js';
|
|
8
7
|
export interface ServerContext {
|
|
@@ -11,7 +10,8 @@ export interface ServerContext {
|
|
|
11
10
|
};
|
|
12
11
|
runtimeEnv: ServerRuntimeEnvironment;
|
|
13
12
|
onDidChangeWatchedFiles: vscode.Connection['onDidChangeWatchedFiles'];
|
|
14
|
-
|
|
13
|
+
onDidChangeConfiguration: vscode.Connection['onDidChangeConfiguration'];
|
|
14
|
+
getConfiguration<T>(section: string, scopeUri?: string): Promise<T | undefined>;
|
|
15
15
|
workspaceFolders: UriMap<boolean>;
|
|
16
16
|
documents: TextDocuments<SnapshotDocument>;
|
|
17
17
|
reloadDiagnostics(): void;
|
|
@@ -19,7 +19,7 @@ export interface ServerContext {
|
|
|
19
19
|
}
|
|
20
20
|
export interface ServerOptions {
|
|
21
21
|
watchFileExtensions?: string[];
|
|
22
|
-
getServicePlugins():
|
|
22
|
+
getServicePlugins(): LanguageServicePlugin[] | Promise<LanguageServicePlugin[]>;
|
|
23
23
|
getLanguagePlugins(serviceEnv: ServiceEnvironment, projectContext: ProjectContext): LanguagePlugin[] | Promise<LanguagePlugin[]>;
|
|
24
24
|
}
|
|
25
25
|
export declare function createServerBase(connection: vscode.Connection, getRuntimeEnv: (params: ServerContext['initializeParams']) => ServerRuntimeEnvironment): {
|
package/lib/server.js
CHANGED
|
@@ -7,7 +7,6 @@ const l10n = require("@vscode/l10n");
|
|
|
7
7
|
const request_light_1 = require("request-light");
|
|
8
8
|
const vscode = require("vscode-languageserver");
|
|
9
9
|
const vscode_uri_1 = require("vscode-uri");
|
|
10
|
-
const configurationHost_js_1 = require("./configurationHost.js");
|
|
11
10
|
const serverCapabilities_js_1 = require("./serverCapabilities.js");
|
|
12
11
|
const types_js_1 = require("./types.js");
|
|
13
12
|
const uri_js_1 = require("./uri.js");
|
|
@@ -28,7 +27,9 @@ function createServerBase(connection, getRuntimeEnv) {
|
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
29
|
const didChangeWatchedFilesCallbacks = new Set();
|
|
30
|
+
const didChangeConfigurationCallbacks = new Set();
|
|
31
31
|
const workspaceFolders = (0, uriMap_js_1.createUriMap)(uri_js_1.fileNameToUri);
|
|
32
|
+
const configurations = new Map();
|
|
32
33
|
documents.listen(connection);
|
|
33
34
|
return {
|
|
34
35
|
initialize,
|
|
@@ -50,9 +51,29 @@ function createServerBase(connection, getRuntimeEnv) {
|
|
|
50
51
|
...env,
|
|
51
52
|
fs: createFsWithCache(env.fs),
|
|
52
53
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
getConfiguration(section, scopeUri) {
|
|
55
|
+
if (!params.capabilities.workspace?.configuration) {
|
|
56
|
+
return Promise.resolve(undefined);
|
|
57
|
+
}
|
|
58
|
+
if (!scopeUri && params.capabilities.workspace?.didChangeConfiguration) {
|
|
59
|
+
if (!configurations.has(section)) {
|
|
60
|
+
configurations.set(section, getConfigurationWorker(section, scopeUri));
|
|
61
|
+
}
|
|
62
|
+
return configurations.get(section);
|
|
63
|
+
}
|
|
64
|
+
return getConfigurationWorker(section, scopeUri);
|
|
65
|
+
async function getConfigurationWorker(section, scopeUri) {
|
|
66
|
+
return (await connection.workspace.getConfiguration({ scopeUri, section })) ?? undefined /* replace null to undefined */;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
onDidChangeConfiguration(cb) {
|
|
70
|
+
didChangeConfigurationCallbacks.add(cb);
|
|
71
|
+
return {
|
|
72
|
+
dispose() {
|
|
73
|
+
didChangeConfigurationCallbacks.delete(cb);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
56
77
|
onDidChangeWatchedFiles: cb => {
|
|
57
78
|
didChangeWatchedFilesCallbacks.add(cb);
|
|
58
79
|
return {
|
|
@@ -92,7 +113,7 @@ function createServerBase(connection, getRuntimeEnv) {
|
|
|
92
113
|
}
|
|
93
114
|
connection.sendDiagnostics({ uri: document.uri, diagnostics: [] });
|
|
94
115
|
});
|
|
95
|
-
context.
|
|
116
|
+
context.onDidChangeConfiguration(updateDiagnosticsAndSemanticTokens);
|
|
96
117
|
(await import('./register/registerEditorFeatures.js')).registerEditorFeatures(connection, projects);
|
|
97
118
|
(await import('./register/registerLanguageFeatures.js')).registerLanguageFeatures(connection, projects, params, semanticTokensLegend);
|
|
98
119
|
const result = {
|
|
@@ -101,48 +122,16 @@ function createServerBase(connection, getRuntimeEnv) {
|
|
|
101
122
|
if (params.initializationOptions?.diagnosticModel !== types_js_1.DiagnosticModel.Pull) {
|
|
102
123
|
result.capabilities.diagnosticProvider = undefined;
|
|
103
124
|
}
|
|
104
|
-
try {
|
|
105
|
-
const packageJson = require('../package.json');
|
|
106
|
-
result.serverInfo = {
|
|
107
|
-
name: packageJson.name,
|
|
108
|
-
version: packageJson.version,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
catch { }
|
|
112
125
|
return result;
|
|
113
126
|
}
|
|
114
127
|
function initialized() {
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
registerWorkspaceFolderWatcher();
|
|
129
|
+
registerConfigurationWatcher();
|
|
130
|
+
registerFileWatcher();
|
|
117
131
|
updateHttpSettings();
|
|
118
|
-
|
|
119
|
-
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
120
|
-
for (const folder of e.added) {
|
|
121
|
-
workspaceFolders.uriSet(folder.uri, true);
|
|
122
|
-
}
|
|
123
|
-
for (const folder of e.removed) {
|
|
124
|
-
workspaceFolders.uriDelete(folder.uri);
|
|
125
|
-
}
|
|
126
|
-
projects.reloadProjects();
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (context.initializeParams.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration
|
|
130
|
-
&& serverOptions.watchFileExtensions?.length) {
|
|
131
|
-
connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
|
132
|
-
watchers: [
|
|
133
|
-
{
|
|
134
|
-
globPattern: `**/*.{${serverOptions.watchFileExtensions.join(',')}}`
|
|
135
|
-
},
|
|
136
|
-
]
|
|
137
|
-
});
|
|
138
|
-
connection.onDidChangeWatchedFiles(e => {
|
|
139
|
-
for (const cb of didChangeWatchedFilesCallbacks) {
|
|
140
|
-
cb(e);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
132
|
+
context.onDidChangeConfiguration(updateHttpSettings);
|
|
144
133
|
async function updateHttpSettings() {
|
|
145
|
-
const httpSettings = await context.
|
|
134
|
+
const httpSettings = await context.getConfiguration('http');
|
|
146
135
|
(0, request_light_1.configure)(httpSettings?.proxy, httpSettings?.proxyStrictSSL ?? false);
|
|
147
136
|
}
|
|
148
137
|
}
|
|
@@ -206,6 +195,52 @@ function createServerBase(connection, getRuntimeEnv) {
|
|
|
206
195
|
],
|
|
207
196
|
};
|
|
208
197
|
}
|
|
198
|
+
function registerConfigurationWatcher() {
|
|
199
|
+
const didChangeConfiguration = context.initializeParams.capabilities.workspace?.didChangeConfiguration;
|
|
200
|
+
if (didChangeConfiguration) {
|
|
201
|
+
connection.onDidChangeConfiguration(params => {
|
|
202
|
+
configurations.clear();
|
|
203
|
+
for (const cb of didChangeConfigurationCallbacks) {
|
|
204
|
+
cb(params);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
if (didChangeConfiguration.dynamicRegistration) {
|
|
208
|
+
connection.client.register(vscode.DidChangeConfigurationNotification.type);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function registerFileWatcher() {
|
|
213
|
+
const didChangeWatchedFiles = context.initializeParams.capabilities.workspace?.didChangeWatchedFiles;
|
|
214
|
+
if (didChangeWatchedFiles && serverOptions.watchFileExtensions?.length) {
|
|
215
|
+
connection.onDidChangeWatchedFiles(e => {
|
|
216
|
+
for (const cb of didChangeWatchedFilesCallbacks) {
|
|
217
|
+
cb(e);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
if (didChangeWatchedFiles.dynamicRegistration) {
|
|
221
|
+
connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
|
222
|
+
watchers: [
|
|
223
|
+
{
|
|
224
|
+
globPattern: `**/*.{${serverOptions.watchFileExtensions.join(',')}}`
|
|
225
|
+
},
|
|
226
|
+
]
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function registerWorkspaceFolderWatcher() {
|
|
232
|
+
if (context.initializeParams.capabilities.workspace?.workspaceFolders) {
|
|
233
|
+
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
234
|
+
for (const folder of e.added) {
|
|
235
|
+
workspaceFolders.uriSet(folder.uri, true);
|
|
236
|
+
}
|
|
237
|
+
for (const folder of e.removed) {
|
|
238
|
+
workspaceFolders.uriDelete(folder.uri);
|
|
239
|
+
}
|
|
240
|
+
projects.reloadProjects();
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
209
244
|
function reloadDiagnostics() {
|
|
210
245
|
if (!isServerPushEnabled()) {
|
|
211
246
|
return;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServicePlugin } from '@volar/language-service';
|
|
2
2
|
import * as vscode from 'vscode-languageserver';
|
|
3
|
-
export declare function getServerCapabilities(watchExts: string[], servicePlugins:
|
|
3
|
+
export declare function getServerCapabilities(watchExts: string[], servicePlugins: LanguageServicePlugin[], semanticTokensLegend: vscode.SemanticTokensLegend): vscode.ServerCapabilities<any>;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FileSystem, LanguageService,
|
|
1
|
+
import type { FileSystem, LanguageService, LanguageServicePlugin, TypeScriptProjectHost } from '@volar/language-service';
|
|
2
2
|
import type * as vscode from 'vscode-languageserver';
|
|
3
3
|
import type { ServerContext, ServerOptions } from './server';
|
|
4
4
|
import type { createSys } from '@volar/typescript';
|
|
@@ -40,5 +40,5 @@ export interface ServerProjectProvider {
|
|
|
40
40
|
reloadProjects(): Promise<void> | void;
|
|
41
41
|
}
|
|
42
42
|
export interface ServerProjectProviderFactory {
|
|
43
|
-
(context: ServerContext, servicePlugins:
|
|
43
|
+
(context: ServerContext, servicePlugins: LanguageServicePlugin[], getLanguagePlugins: ServerOptions['getLanguagePlugins']): ServerProjectProvider;
|
|
44
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"directory": "packages/language-server"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.
|
|
16
|
-
"@volar/language-service": "2.
|
|
17
|
-
"@volar/snapshot-document": "2.
|
|
18
|
-
"@volar/typescript": "2.
|
|
15
|
+
"@volar/language-core": "2.2.0-alpha.0",
|
|
16
|
+
"@volar/language-service": "2.2.0-alpha.0",
|
|
17
|
+
"@volar/snapshot-document": "2.2.0-alpha.0",
|
|
18
|
+
"@volar/typescript": "2.2.0-alpha.0",
|
|
19
19
|
"@vscode/l10n": "^0.0.16",
|
|
20
20
|
"path-browserify": "^1.0.1",
|
|
21
21
|
"request-light": "^0.7.0",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/path-browserify": "latest"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "95ffe51f944ee87f570be113541e17ddfe75f588"
|
|
31
31
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ServiceEnvironment } from '@volar/language-service';
|
|
2
|
-
import * as vscode from 'vscode-languageserver';
|
|
3
|
-
export declare function createConfigurationHost(params: vscode.InitializeParams, connection: vscode.Connection): Pick<ServiceEnvironment, 'getConfiguration' | 'onDidChangeConfiguration'> & {
|
|
4
|
-
ready(): void;
|
|
5
|
-
};
|
package/lib/configurationHost.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConfigurationHost = void 0;
|
|
4
|
-
const vscode = require("vscode-languageserver");
|
|
5
|
-
function createConfigurationHost(params, connection) {
|
|
6
|
-
const callbacks = new Set();
|
|
7
|
-
const cache = new Map();
|
|
8
|
-
connection.onDidChangeConfiguration(async () => {
|
|
9
|
-
cache.clear();
|
|
10
|
-
for (const cb of callbacks) {
|
|
11
|
-
cb();
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return {
|
|
15
|
-
ready() {
|
|
16
|
-
if (params.capabilities.workspace?.didChangeConfiguration?.dynamicRegistration) {
|
|
17
|
-
connection.client.register(vscode.DidChangeConfigurationNotification.type);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
async getConfiguration(section, scopeUri) {
|
|
21
|
-
if (!scopeUri && params.capabilities.workspace?.didChangeConfiguration) {
|
|
22
|
-
if (!cache.has(section)) {
|
|
23
|
-
cache.set(section, await getConfigurationWorker(section, scopeUri));
|
|
24
|
-
}
|
|
25
|
-
return cache.get(section);
|
|
26
|
-
}
|
|
27
|
-
return await getConfigurationWorker(section, scopeUri);
|
|
28
|
-
},
|
|
29
|
-
onDidChangeConfiguration(cb) {
|
|
30
|
-
callbacks.add(cb);
|
|
31
|
-
return {
|
|
32
|
-
dispose() {
|
|
33
|
-
callbacks.delete(cb);
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
async function getConfigurationWorker(section, scopeUri) {
|
|
39
|
-
return (await connection.workspace.getConfiguration({ scopeUri, section })) ?? undefined /* replace null to undefined */;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.createConfigurationHost = createConfigurationHost;
|
|
43
|
-
//# sourceMappingURL=configurationHost.js.map
|