rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

VS Code Extension Config API

Open alexander-heimbuch opened this issue 1 year ago • 4 comments

Our VS Code extension integrates with the Rust Analyzer extension. In order for Rust Analyzer to work in our environment, it needs dynamic values in the configuration. So far we update the settings.json according to the dynamic values, but this leads to overwriting any configurations of the user and leaving the workspace in a potential dirty state. Accordingly, a different configuration interface would be desirable.

VS Code Extensions offer the possibility to expose an API via the activate hook, here a config function could be added, which enables a configuration in an extension to extension communication:

const rustAnalyzer = vscode.extensions.getExtension("rust-lang.rust-analyzer")?.exports;

await rustAnalyzer.config({ ... });

This function should respect the existing configuration (user configurations have precedence).

alexander-heimbuch avatar Nov 04 '24 12:11 alexander-heimbuch

This function should respect the existing configuration (user configurations have precedence).

I don't think this can be honored. The VSCode settings API does not tell you whether what you fetched was explicitly user set or a default as far as I am aware.

Veykril avatar May 06 '25 15:05 Veykril

The VSCode settings API does not tell you whether what you fetched was explicitly user set or a default

When you call inspect on the fetched configuration (https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration) (rather than get) you get an object that tells you which values are defined:

{
  defaultLanguageValue: T, 
  defaultValue: T, 
  globalLanguageValue: T, 
  globalValue: T, 
  key: string, 
  languageIds: string[], 
  workspaceFolderLanguageValue: T, 
  workspaceFolderValue: T, 
  workspaceLanguageValue: T, 
  workspaceValue: T
}

Rather than just getting the computed result this would hint whether a specific configuration was overwritten by the user in any scope (language, workspace, workspace folder or globally)

erikmueller avatar May 26 '25 08:05 erikmueller

What sort of values/configuration are being set by your extension? Is it some build configuration/project discovery stuff, or...?

davidbarsky avatar May 26 '25 13:05 davidbarsky

We need to set rust-analyzer.cargo.cfgs and rust-analyzer.cargo.extraEnv in a dynamic way. The best case scenario would be that we also be able to control RA server restarts. Right now we write the settings.json but this has some downsides because the interaction is indirect.

alexander-heimbuch avatar May 27 '25 08:05 alexander-heimbuch