@@ -5,7 +5,7 @@ import * as vscode from "vscode";
55import { expectNotUndefined , log , normalizeDriveLetter , unwrapUndefinable } from "./util" ;
66import type { Env } from "./util" ;
77import type { Disposable } from "vscode" ;
8- import { get } from "lodash" ;
8+ import { cloneDeep , get , merge } from "lodash" ;
99
1010export type RunnableEnvCfgItem = {
1111 mask ?: string ;
@@ -23,14 +23,27 @@ export class Config {
2323 configureLang : vscode . Disposable | undefined ;
2424
2525 readonly rootSection = "rust-analyzer" ;
26- private readonly requiresServerReloadOpts = [ "server" , "files" , "showSyntaxTree" ] . map (
26+ private readonly requiresServerReloadOpts = [ "cargo" , " server", "files" , "showSyntaxTree" ] . map (
2727 ( opt ) => `${ this . rootSection } .${ opt } ` ,
2828 ) ;
2929
3030 private readonly requiresWindowReloadOpts = [ "testExplorer" ] . map (
3131 ( opt ) => `${ this . rootSection } .${ opt } ` ,
3232 ) ;
3333
34+ extensionConfigurations : Map < string , Record < string , unknown > > = new Map ( ) ;
35+
36+ async addExtensionConfiguration ( extensionId : string , configuration : Record < string , unknown > ) : Promise < void > {
37+ this . extensionConfigurations . set ( extensionId , configuration ) ;
38+ const prefix = `${ this . rootSection } .` ;
39+ await this . onDidChangeConfiguration ( {
40+ affectsConfiguration ( section : string , _scope ?: vscode . ConfigurationScope ) : boolean {
41+ // FIXME: questionable
42+ return section . startsWith ( prefix ) && section . slice ( prefix . length ) in configuration ;
43+ } ,
44+ } ) ;
45+ }
46+
3447 constructor ( disposables : Disposable [ ] ) {
3548 vscode . workspace . onDidChangeConfiguration ( this . onDidChangeConfiguration , this , disposables ) ;
3649 this . refreshLogging ( ) ;
@@ -180,10 +193,15 @@ export class Config {
180193 // We don't do runtime config validation here for simplicity. More on stackoverflow:
181194 // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
182195
183- private get cfg ( ) : vscode . WorkspaceConfiguration {
196+ private get rawCfg ( ) : vscode . WorkspaceConfiguration {
184197 return vscode . workspace . getConfiguration ( this . rootSection ) ;
185198 }
186199
200+ public get cfg ( ) : ConfigurationTree {
201+ const vsCodeConfig = cloneDeep < ConfigurationTree > ( this . rawCfg ) ;
202+ return merge ( vsCodeConfig , ...this . extensionConfigurations . values ( ) ) ;
203+ }
204+
187205 /**
188206 * Beware that postfix `!` operator erases both `null` and `undefined`.
189207 * This is why the following doesn't work as expected:
@@ -227,7 +245,7 @@ export class Config {
227245 }
228246
229247 async toggleCheckOnSave ( ) {
230- const config = this . cfg . inspect < boolean > ( "checkOnSave" ) ?? { key : "checkOnSave" } ;
248+ const config = this . rawCfg . inspect < boolean > ( "checkOnSave" ) ?? { key : "checkOnSave" } ;
231249 let overrideInLanguage ;
232250 let target ;
233251 let value ;
@@ -253,7 +271,7 @@ export class Config {
253271 overrideInLanguage = config . defaultLanguageValue ;
254272 value = config . defaultValue || config . defaultLanguageValue ;
255273 }
256- await this . cfg . update ( "checkOnSave" , ! ( value || false ) , target || null , overrideInLanguage ) ;
274+ await this . rawCfg . update ( "checkOnSave" , ! ( value || false ) , target || null , overrideInLanguage ) ;
257275 }
258276
259277 get problemMatcher ( ) : string [ ] {
@@ -371,7 +389,7 @@ export class Config {
371389 }
372390
373391 async setAskBeforeUpdateTest ( value : boolean ) {
374- await this . cfg . update ( "runnables.askBeforeUpdateTest" , value , true ) ;
392+ await this . rawCfg . update ( "runnables.askBeforeUpdateTest" , value , true ) ;
375393 }
376394}
377395
0 commit comments