Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/config.ts')
| -rw-r--r-- | editors/code/src/config.ts | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 06e179eb0e..340f107ebb 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -5,7 +5,7 @@ import * as vscode from "vscode"; import { expectNotUndefined, log, normalizeDriveLetter, unwrapUndefinable } from "./util"; import type { Env } from "./util"; import type { Disposable } from "vscode"; -import { get } from "lodash"; +import { cloneDeep, get, merge } from "lodash"; export type RunnableEnvCfgItem = { mask?: string; @@ -23,7 +23,7 @@ export class Config { configureLang: vscode.Disposable | undefined; readonly rootSection = "rust-analyzer"; - private readonly requiresServerReloadOpts = ["server", "files", "showSyntaxTree"].map( + private readonly requiresServerReloadOpts = ["cargo", "server", "files", "showSyntaxTree"].map( (opt) => `${this.rootSection}.${opt}`, ); @@ -31,6 +31,19 @@ export class Config { (opt) => `${this.rootSection}.${opt}`, ); + extensionConfigurations: Map<string, Record<string, unknown>> = new Map(); + + async addExtensionConfiguration(extensionId: string, configuration: Record<string, unknown>): Promise<void> { + this.extensionConfigurations.set(extensionId, configuration); + const prefix = `${this.rootSection}.`; + await this.onDidChangeConfiguration({ + affectsConfiguration(section: string, _scope?: vscode.ConfigurationScope): boolean { + // FIXME: questionable + return section.startsWith(prefix) && section.slice(prefix.length) in configuration; + }, + }); + } + constructor(disposables: Disposable[]) { vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, disposables); this.refreshLogging(); @@ -180,10 +193,15 @@ export class Config { // We don't do runtime config validation here for simplicity. More on stackoverflow: // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension - private get cfg(): vscode.WorkspaceConfiguration { + private get rawCfg(): vscode.WorkspaceConfiguration { return vscode.workspace.getConfiguration(this.rootSection); } + public get cfg(): ConfigurationTree { + const vsCodeConfig = cloneDeep<ConfigurationTree>(this.rawCfg); + return merge(vsCodeConfig, ...this.extensionConfigurations.values()); + } + /** * Beware that postfix `!` operator erases both `null` and `undefined`. * This is why the following doesn't work as expected: @@ -227,7 +245,7 @@ export class Config { } async toggleCheckOnSave() { - const config = this.cfg.inspect<boolean>("checkOnSave") ?? { key: "checkOnSave" }; + const config = this.rawCfg.inspect<boolean>("checkOnSave") ?? { key: "checkOnSave" }; let overrideInLanguage; let target; let value; @@ -253,7 +271,7 @@ export class Config { overrideInLanguage = config.defaultLanguageValue; value = config.defaultValue || config.defaultLanguageValue; } - await this.cfg.update("checkOnSave", !(value || false), target || null, overrideInLanguage); + await this.rawCfg.update("checkOnSave", !(value || false), target || null, overrideInLanguage); } get problemMatcher(): string[] { @@ -371,7 +389,7 @@ export class Config { } async setAskBeforeUpdateTest(value: boolean) { - await this.cfg.update("runnables.askBeforeUpdateTest", value, true); + await this.rawCfg.update("runnables.askBeforeUpdateTest", value, true); } } |