MCPcopy
hub / github.com/microsoft/vscode-languageserver-node / ConfigurationFeature

Class ConfigurationFeature

client/src/configuration.ts:18–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18export class ConfigurationFeature implements StaticFeature {
19
20 constructor(private _client: BaseLanguageClient) {
21 }
22
23 public fillClientCapabilities(capabilities: ClientCapabilities): void {
24 capabilities.workspace = capabilities.workspace || {};
25 capabilities.workspace!.configuration = true;
26 }
27
28 public initialize(): void {
29 let client = this._client;
30 client.onRequest(ConfigurationRequest.type, (params, token) => {
31 let configuration: ConfigurationRequest.HandlerSignature = (params) => {
32 let result: any[] = [];
33 for (let item of params.items) {
34 let resource = item.scopeUri !== void 0 && item.scopeUri !== null ? this._client.protocol2CodeConverter.asUri(item.scopeUri) : undefined;
35 result.push(this.getConfiguration(resource, item.section !== null ? item.section : undefined));
36 }
37 return result;
38 }
39 let middleware = client.clientOptions.middleware!.workspace;
40 return middleware && middleware.configuration
41 ? middleware.configuration(params, token, configuration)
42 : configuration(params, token);
43 });
44 }
45
46 private getConfiguration(resource: Uri | undefined, section: string | undefined): any {
47 let result: any = null;
48 if (section) {
49 let index = section.lastIndexOf('.');
50 if (index === -1) {
51 result = workspace.getConfiguration(undefined, resource).get(section);
52 } else {
53 let config = workspace.getConfiguration(section.substr(0, index));
54 if (config) {
55 result = config.get(section.substr(index + 1))
56 }
57 }
58 } else {
59 let config = workspace.getConfiguration(undefined, resource);
60 result = {};
61 for (let key of Object.keys(config)) {
62 if (config.has(key)) {
63 result[key] = config.get(key);
64 }
65 }
66 }
67 if (!result) {
68 return null;
69 }
70 return result;
71 }
72}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected