-
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
rust-analyzer.toml #13529
Comments
Note: Highly suggest making this a dotfile ( My usecase here is that I have a Having a per-project config file for r-a would allow me to specify a feature for analysis such as |
Yes please. We need something like this to provide proper integration with our build system and right now we can only provide that for vscode which is unfortunate.
FWIW clangd has this feature ( |
Doesn't this depend on how the client sends configs at all? Does r-a get its configuration via the client, or from the filesystem? If the former, then it's up to the client implementations to specify this. Ideally each would allow the user to specify the priorities of the searched configs, be able to merge them based on this, and then send the flattened config to r-a. I don't see how that's r-a's problem, really.
I don't think nesting is necessary. Keeping it clean and simple is probably the best route. It would also make debugging easier. (Again, this assumes that r-a is getting the config from the client directly, not from scouring the source tree etc.)
If the above are true, then is this really a fix for r-a directly? It'd be up to the individual client implementations to handle these sort of semantics. Perhaps r-a could specify that
As far as I understand, 1. and 4. are already the case. It's 2. and 3. that would have to be added. Bonus points for allowing the user to specify search paths / their order for For anyone who wants a hack-and-slash workaround for Neovim that is non-standard, use this to initialize your init.vim: function get_project_rustanalyzer_settings()
local handle = io.open(vim.fn.resolve(vim.fn.getcwd() .. '/./.rust-analyzer.json'))
if not handle then
return {}
end
local out = handle:read("*a")
handle:close()
local config = vim.json.decode(out)
if type(config) == "table" then
return config
end
return {}
end
local lspflags = {
rust_analyzer = {
settings = {
['rust-analyzer'] = vim.tbl_deep_extend(
"force",
{
-- Defaults (can be overridden by .rust-analyzer.json
},
get_project_rustanalyzer_settings(),
{
-- Overrides (forces these regardless of what's in .rust-analyzer.json
procMacro = { enable = true },
diagnostics = { disabled = {"inactive-code"} },
}
)
}
}
} Then add a {
"cargo": {
"features": [ "stm32f479" ]
}
} The downside is that this doesn't scan the directory hierarchy, so you have to open nvim from the directory that has the |
My initial thought here was for the server to consume the
So effectively with this
That's a good point to consider. The other points you've raised are somewhat moot with the thought of the server consuming it (I shouldve been clearer on that in the issue description, will edit) I think. |
Allowing both |
I remember another request for allowing Rust Analyzer to work without And ensure that we use |
Yes that somewhat plays into the third checkbox point, how r-a will look for the file and if nesting is allowed. |
@rustbot claim So I am claiming this issue just to let everyone know that someone is working on it, although this won't be my number one priority for the first couple of weeks. If someone makes any progress within this time frame, please share it. |
Here is more or less a roadmap that I plan to follow : (The two names that I use here
|
What does |
There are some configurations for which overwriting doesn't make much sense and can even be misleading. An example would be |
I still don't see why global vs local makes more sense than multiple configs. Who cares if a second config overwrites the first in some weird way? That's on the user at that point. |
(That distinction came from a discussion Ali and I had elsewhere) It is more that there a configs that apply to the server session as a whole and then there are configs that apply to individually loaded projects. There are also configs that do not make sense to be in the rust-analyzer.toml at all, like all the hover configs for example. Those are project irrelevant so they won't be configurable by the r-a toml file. Though having a second look at things, I don't think there are configs that can't be applied on a per loaded project level (opposed to server session wide), aside from current implementation reasons maybe ( |
internal: Implement parent-child relation for `SourceRoot`s This commit adds the said relation by keeping a map of type `FxHashMap<SourceRootId,Option<SourceRootId>>` inside the `GlobalState`. Its primary use case is reading `rust-analyzer.toml`(#13529) files that can be placed in every local source root. As a config will be found by traversing this "tree" we need the parent information for every local source root. This commit omits defining this relation for library source roots entirely.
This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( rust-lang#13529 ) issue. This means, that 1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only. 2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until rust-lang#13529 got merged.
This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( rust-lang#13529 ) issue. This means, that 1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only. 2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until rust-lang#13529 got merged.
This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( rust-lang#13529 ) issue. This means, that 1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only. 2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until rust-lang#13529 got merged.
This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( rust-lang#13529 ) issue. This means, that 1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only. 2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until rust-lang#13529 got merged.
internal : redesign rust-analyzer::config This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( #13529 ) issue. This means, that 1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only. 2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until #13529 got merged. Once again many thanks to `@cormacrelf` for doing all the serde work.
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
#17058 will implement the core features here, there are still some issues with it (the user config is not working correctly yet), as well some restrictions with crate specific configs due to architecture reasons (they shouldn't really be noticeably in most cases). A lot of configs are also still missing from it and the diagnostics UX (when an invalid config is supplied) is really bad. All of that will be resolved in the near or far future (time will tell). Important We don't promise any stability with this feature yet, any configs exposed may be removed again, the ordering may change etc. Once the PR lands (should today), this issue will be used to track any updates on the feature. |
feat: TOML based config for rust-analyzer > Important > > We don't promise _**any**_ stability with this feature yet, any configs exposed may be removed again, the grouping may change etc. # 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 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
A rust-analyzer config file, or at least something in BTW: the rust-analyzer project is incredibly biased towards VSCode-only solutions. As someone who deliberately doesn't use this editor, I'm constantly frustrated by features that are missing from rust-analyzer, because they're solved by some VSCode-only doodad, and are unsupported or undocumented for other editors. Per-project config is one of these. |
@kornelski 👋 you can already use per-project configuration ( see #17058 ), there are two known issues to this which will be soon resolved ( see #17483 ). Please let me know if you have any suggestions/comments in general. |
It is and we can't do anything about it. We are limited by what the LSP allows us to do. VSCode is the reference implementation that we maintain, we can't possible maintain editor extensions for all editors out there for obvious reasons. |
@alibektas that's a great news. However, I can't figure out what syntax it wants. I've tried [rust-analyzer.cargo]
features = "all"
# or
[cargo]
features = "all" but I don't see any effect, even after restarting RA manually. @Veykril The problem is that if you don't make RA less VSCode-centric, nobody else will do that for you. The other editors say "this is just one of many LSP clients, we can't possibly test and document all LSP implementations", and RA outside of VSCode ends up in a no man's land of undocumented and untested integrations owned by nobody. |
@kornelski As a non-VSCode user, I don't agree that RA is VSCode-centric. Yes, the reference implementation is the VSCode plugin, but, well, something needs to be. The RA team can't possibly maintain integrations for a bunch of editors no one on the team uses. If the integration for a specific editor is bad, someone from that community needs to step up to maintain it.
Maybe don't use those editors then if you want good LSP integration. My experience is that LSP has not been designed with the goal of "no per-server integration code needed in the editor at all".
Can you give some examples of those features? (Except per-project config, which is literally already implemented) |
FWIW, i'd love to see
Yes. This is absolutely the design. This is a very important fact: there is no LSP support directly in VS Code. There are only language-specific extensions, which happen to use the same common LSP library (that is, each extension bundles its own private copy of the library). All our extras are documented here:
|
@alibektas What is the intended syntax I also have issues with setting it up In addition to the 2 ways mentioned above, I've tried this to no avail. cargo.features = "all" I get this error.
|
@alibektas is something like |
See #17945, right now almost none of the configs can be used in a workspace or user toml file |
|
That I still need to fix. I worked on it but it is still not complete |
I tried to use this. I have a workspace like this
crate 2 and 4 have a feature called "example_feature" that i want to enable for RA, There is still a lot of uncertainty about the format of |
You were right in assuming that we omit EDIT : Now thinking about it for a second time, the problem must be due to the fact that |
Where can I find an example of |
This is a tracking issue/discussion for a potential
rust-analyzer.toml
. There have been a lot of requests for a per-project configuration in various issues, some clients like VSCode allow specifying settings per workspace, but usually these kinds of settings are not committed in a repo and are therefor usually not meant to necessarily configure r-a for the project specifically (like certain coding style settings, think of import merging etc.). Other related things might be requiring a special built procedure for a cargo project, prime example being https://github.com/rust-lang/rust which currently has a few suggested config lines in the dev guide which a user has to specify manually when they check out the repo locally, see https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc.The idea is for the server to consume this file, so that you do not need a "rust-analyzer capable" LSP client to make use of it.
So there is clearly a need for a project config option like this, but here are few open questions.
Cargo.toml
metadata section instead, but that would only solve the problem for cargo based projects and it feels wrong to have certain settings in there opposed to arust-analyzer.toml
I believe.rust-analyzer.toml
to be the correct solution here.rust-analyzer.toml
, but we cannot know if a client sends us the default config for something or if its explicitly set, so we might have to bite the bullet and preferrust-analyzer.toml
.The text was updated successfully, but these errors were encountered: