Skip to content

Commit 145677f

Browse files
Don't pretend to have a WorkspaceConfiguration if there isn't one
1 parent f35b6df commit 145677f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/tools/rust-analyzer/editors/code/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { RaLanguageClient } from "./lang_client";
1313
export async function createClient(
1414
traceOutputChannel: vscode.OutputChannel,
1515
outputChannel: vscode.OutputChannel,
16-
initializationOptions: vscode.WorkspaceConfiguration,
16+
initializationOptions: lc.LanguageClientOptions["initializationOptions"],
1717
serverOptions: lc.ServerOptions,
1818
config: Config,
1919
unlinkedFiles: vscode.Uri[],

src/tools/rust-analyzer/editors/code/src/config.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import * as vscode from "vscode";
55
import { expectNotUndefined, log, normalizeDriveLetter, unwrapUndefinable } from "./util";
66
import type { Env } from "./util";
77
import type { Disposable } from "vscode";
8+
import { get } from "lodash";
89

910
export type RunnableEnvCfgItem = {
1011
mask?: string;
1112
env: { [key: string]: { toString(): string } | null };
1213
platform?: string | string[];
1314
};
1415

16+
export type ConfigurationTree = { [key: string]: ConfigurationValue };
17+
export type ConfigurationValue = undefined | null | boolean | number | string | ConfigurationValue[] | ConfigurationTree;
18+
1519
type ShowStatusBar = "always" | "never" | { documentSelector: vscode.DocumentSelector };
1620

1721
export class Config {
@@ -197,7 +201,7 @@ export class Config {
197201
* So this getter handles this quirk by not requiring the caller to use postfix `!`
198202
*/
199203
private get<T>(path: string): T | undefined {
200-
return prepareVSCodeConfig(this.cfg.get<T>(path));
204+
return prepareVSCodeConfig(get(this.cfg, path)) as T;
201205
}
202206

203207
get serverPath() {
@@ -371,22 +375,20 @@ export class Config {
371375
}
372376
}
373377

374-
export function prepareVSCodeConfig<T>(resp: T): T {
378+
export function prepareVSCodeConfig(resp: ConfigurationValue): ConfigurationValue {
375379
if (Is.string(resp)) {
376-
return substituteVSCodeVariableInString(resp) as T;
377-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
378-
} else if (resp && Is.array<any>(resp)) {
380+
return substituteVSCodeVariableInString(resp);
381+
} else if (resp && Is.array(resp)) {
379382
return resp.map((val) => {
380383
return prepareVSCodeConfig(val);
381-
}) as T;
384+
});
382385
} else if (resp && typeof resp === "object") {
383-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
384-
const res: { [key: string]: any } = {};
386+
const res: ConfigurationTree = {};
385387
for (const key in resp) {
386388
const val = resp[key];
387389
res[key] = prepareVSCodeConfig(val);
388390
}
389-
return res as T;
391+
return res;
390392
}
391393
return resp;
392394
}

0 commit comments

Comments
 (0)