New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: TOML based config for rust-analyzer #17058
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nits; i'll try to review more later.
@@ -827,16 +1177,45 @@ impl Config { | |||
caps: ClientCapabilities, | |||
workspace_roots: Vec<AbsPathBuf>, | |||
visual_studio_code_version: Option<Version>, | |||
user_config_path: Option<Utf8PathBuf>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: are there non-user
config paths? i would just rename all usage here to config_path
, IMO.
(i see a "root config path", but I'd remove the user
qualifier entirely.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the user here refers to the user's home dir I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah naming things is not my strength. I though of XDG_CONFIG_.. but that is also not very accurate either. As a matter of fact it was Veykril's suggestion to change it to user_config. In any case the name is still the same but I added comment.
crates/rust-analyzer/src/config.rs
Outdated
client_config: ClientConfig::default(), | ||
user_config: None, | ||
ratoml_files: FxHashMap::default(), | ||
default_config: ConfigData::default(), | ||
source_root_parent_map: Arc::new(FxHashMap::default()), | ||
user_config_path, | ||
root_ratoml: None, | ||
root_ratoml_path, | ||
should_update: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do two things:
- keep
ConfigData
nameddata
instead ofdefault_config
. - I'd group all the configuration file-related values into their own wrapper struct.
// FIXME @alibektas : This is the only config that is confusing. If it's a proper configuration | ||
// why is it not among the others? If it's client only which I doubt it is current state should be alright |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's weird because the VS Code extension, by default, cares about what folder rust-analyzer is running in. it's debatable whether it makes sense in this context, but I'm inclined to think it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a very odd config and only necessary (I hope) because we are lacking proper support for handling detached files currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not a complete review yet, will give the previous PR another pass and merge that first (then adjust things as I see to speed up things, instead of doing more review rounds on that)
☔ The latest upstream changes (presumably #16639) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #17110) made this pull request unmergeable. Please resolve the merge conflicts. |
change.change_client_config(json); | ||
let mut error_sink = ConfigError::default(); | ||
config = config.apply_change(change, &mut error_sink); | ||
// FIXME @alibektas : What happens to errors without logging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They get eaten, we should probably set up our tracing logging to error by default in these binaries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am holding onto this one as I couldn't quite understand what I need to do.
☔ The latest upstream changes (presumably #17118) made this pull request unmergeable. Please resolve the merge conflicts. |
74e7863
to
2199f2d
Compare
☔ The latest upstream changes (presumably #17157) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 more things otherwise I think this is good to go
@bors delegate+ |
✌️ @alibektas, you can now approve this pull request! If @Veykril told you to " |
My splitting the config keys into global/local/client wasn't really meticulous, because I was thinking that you would intervene at some point 😄. Are we planning to this in the near future or do you want to take a look before I actually merge this PR @Veykril ? |
I haven't given the split a look yet tbf, I can do that afterwards / once you've fixed up the rest here |
Hi! I'm reading this with an eye toward enabling rust-analyzer in our complex cross-compilation builds in Hubris. I'm not very deep into it (and in particular need to look at your split of config keys into client/global/local) but one thing jumped out:
It would be really nice for this to be at least a warning. Otherwise I foresee frustration where we set a key and it silently doesn't take effect. |
Caveat: I am not familiar with this codebase and have no idea how big of a request I am making. I'm also not a VScode user, and some of the comments in the code seem VScode-specific, so it's possible I'm not understanding things correctly. It would be nice for rust-embedded use cases if the following things were available as crate-local rather than workspace-level settings; from my read of the current code they are global:
I assume that sufficiently flexible/configurable clients are able to override all of the settings? (This seems important if config files are checked in but you want to do something different in a specific editor.) |
We ought to have that indeed thats a good point to raise. Regarding the preference for crate-local configs, the ones you raised are certainly targets for those but they will require some more follow up work to this. This PR is mainly bringing the infra up that allows us to have these config files for now. |
☔ The latest upstream changes (presumably #17203) made this pull request unmergeable. Please resolve the merge conflicts. |
TOML Based Config for RA
This PR ( fixes #13529 and this is a follow-up PR on #16639 ) makes rust-analyzer configurable by configuration files called
rust-analyzer.toml
. Files must be namedrust-analyzer.toml
. There is not a strict rule regarding where the files should be placed, but it is recommended to put them near a file that triggers server to start (i.e.,Cargo.{toml,lock}
,rust-project.json
).Configuration Types
Previous configuration keys are now split into three different classes.
settings.json
in VSCode). They are but a small portion of this list. One such example isrust_analyzer.files_watcher
, based on which either the client or the server will be responsible for watching for changes made to project files.How Am I Supposed To Know If A Config Is Gl/Loc/Cl ?
#17101
Configuration Hierarchy
There are 5 levels in the configuration hierarchy. When a key is searched for, it is searched in a bottom-up depth-first fashion.
Default Configuration
Scope: Global, Local, and Client
This is a hard-coded set of configurations. When a configuration key could not be found, then its default value applies.
User configuration
Scope: Global, Local
If you want your configurations to apply to every project you have, you can do so by setting them in your
$CONFIG_DIR/rust-analyzer/rust-analyzer.toml
file, where$CONFIG_DIR
is :$XDG_CONFIG_HOME
or$HOME
/.config$HOME
/Library/Application Support{FOLDERID_RoamingAppData}
Client configuration
Scope: Global, Local, and Client
Previously, the only way to configure rust-analyzer was to configure it from the settings of the Client you are using. This level corresponds to that.
Workspace Root Configuration
Scope: Global, Local
Rust-analyzer already used the path of the workspace you opened in your Client. We used this information to create a configuration file that won't affect your other projects and define global level configurations at the same time.
Local Configuration
Scope: Local
You can also configure rust-analyzer on a crate level. Although it is not an error to define global ( or client ) level keys in such files, they won't be taken into consideration by the server. Defined local keys will affect the crate in which they are defined and crate's descendants. Internally, a Rust project is split into what we call
SourceRoot
s. This, although with exceptions, is equal to splitting a project into crates.