Skip to content

Commit 6de1792

Browse files
docs
1 parent c53b566 commit 6de1792

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ type ShowStatusBar = "always" | "never" | { documentSelector: vscode.DocumentSel
1919

2020
export class Config {
2121
readonly extensionId = "rust-lang.rust-analyzer";
22-
readonly workspaceState: vscode.Memento;
22+
2323
configureLang: vscode.Disposable | undefined;
24+
workspaceState: vscode.Memento;
2425

25-
readonly rootSection = "rust-analyzer";
26+
private readonly rootSection = "rust-analyzer";
2627
private readonly requiresServerReloadOpts = ["cargo", "server", "files", "showSyntaxTree"].map(
2728
(opt) => `${this.rootSection}.${opt}`,
2829
);
@@ -42,11 +43,14 @@ export class Config {
4243
this.configureLang?.dispose();
4344
}
4445

46+
private readonly extensionConfigurationStateKey = "extensionConfigurations";
47+
4548
/// Returns the rust-analyzer-specific workspace configuration, incl. any
4649
/// configuration items overridden by (present) extensions.
4750
get extensionConfigurations(): Record<string, Record<string, unknown>> {
4851
return pickBy(
4952
this.workspaceState.get<Record<string, ConfigurationTree>>("extensionConfigurations", {}),
53+
// ignore configurations from disabled/removed extensions
5054
(_, extensionId) => vscode.extensions.getExtension(extensionId) !== undefined,
5155
);
5256
}
@@ -56,7 +60,7 @@ export class Config {
5660

5761
const extCfgs = this.extensionConfigurations;
5862
extCfgs[extensionId] = configuration;
59-
await this.workspaceState.update("extensionConfigurations", extCfgs);
63+
await this.workspaceState.update(this.extensionConfigurationStateKey, extCfgs);
6064

6165
const newConfiguration = this.cfg;
6266
const prefix = `${this.rootSection}.`;
@@ -207,10 +211,14 @@ export class Config {
207211
// We don't do runtime config validation here for simplicity. More on stackoverflow:
208212
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
209213

214+
// Returns the raw configuration for rust-analyzer as returned by vscode. This
215+
// should only be used when modifications to the user/workspace configuration
216+
// are required.
210217
private get rawCfg(): vscode.WorkspaceConfiguration {
211218
return vscode.workspace.getConfiguration(this.rootSection);
212219
}
213220

221+
// Returns the final configuration to use, with extension configuration overrides merged in.
214222
public get cfg(): ConfigurationTree {
215223
return merge(cloneDeep(this.rawCfg), ...Object.values(this.extensionConfigurations));
216224
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export interface RustAnalyzerExtensionApi {
1414
// FIXME: this should be non-optional
1515
readonly client?: lc.LanguageClient;
1616

17+
// Allows adding a configuration override from another extension.
18+
// `configuration` is a `rust-analyzer` subtree of the vscode configuration
19+
// that gets merged with the workspace/user configuration. `extensionId` is
20+
// used to only merge configuration override from present extensions.
1721
addConfiguration(extensionId: string, configuration: Record<string, unknown>): Promise<void>;
1822
}
1923

0 commit comments

Comments
 (0)