@@ -19,10 +19,11 @@ type ShowStatusBar = "always" | "never" | { documentSelector: vscode.DocumentSel
1919
2020export 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 }
0 commit comments