-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
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. |
☔ 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 |
Okay diagnostics work now, though the UX is horrible for now and this generally needs some cleanup that I'll task @alibektas with as a follow up. It also seems like the server hangs up when you create a fresh toml file so I'll investigate that later |
@bors r+ |
feat: TOML based config for rust-analyzer # 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 named `rust-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. 1. Client keys: These keys only make sense when set by the client (e.g., by setting them in `settings.json` in VSCode). They are but a small portion of this list. One such example is `rust_analyzer.files_watcher`, based on which either the client or the server will be responsible for watching for changes made to project files. 2. Global keys: These keys apply to the entire workspace and can only be set on the very top layers of the hierarchy. The next section gives instructions on which layers these are. 3. Local keys: Keys that can be changed for each crate if desired. ### 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 : | Platform | Value | Example | | ------- | ------------------------------------- | ---------------------------------------- | | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config | | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support | | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | ### 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. > With this PR, you don't need to port anything to benefit from new features. You can continue to use your old settings as they are. ### 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. > You may choose to have more than one `rust-analyzer.toml` files within a `SourceRoot`, but among them, the one closer to the project root will be
💔 Test failed - checks-actions |
4c2b832
to
3178e5f
Compare
@bors r+ |
Quoting my comment on #13529 for visibility:
|
☀️ Test successful - checks-actions |
minor : fixes for ratoml module This is a follow-up PR to #17058. - Parse errors are reflected as such by defining a new variant called `ConfigError::ParseError` - New error collection has been added to store config level agnostic errors. EDIT : Some things that this PR promised to solve are removed and will be addressed by other PRs
TOML Based Config for RA
This PR ( addresses #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 Configuration
Scope: Global, Workspace, Local
A
rust-analyzer.toml
file that is located at the root of your workspace can be used to configure all of the mentioned scopes. Aworkspace
scope does in practice not exist but will soon be implemented and these files will soon not have a global scope but rather onlyworkspace
andlocal
.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.