It is an idea I have this afternoon..
Problem
It is annoying for we lsp user to switch the features we used in a rust project. Rust-analyer needed to be passed with the feature to selected, then it can finally enable the feature, and highlight the code related. In vscode, we can edit .vscode/settings.json, but even that it is annoying enough. Why when I switch features, I need to rewrite the config file.
Idea
I thought about what meson build and cmake do. In the build system of mesonbuild or cmake, they have a action called configure
(I got mistaken in last edition, call it precompile). like
meson setup build -D ENABLE_A=ON
and it write config to build folder, next time it do
meson compile -C build
it will use the feature to compile,
compile to cargo, every time I need to pass --feature
to tell it which features to use.
And inducing the flow of precompile to config the file allow clangd to know which option to open, this make every time, I just to reconfig the build option, then I will switch to other features, and lsp know it. I do not need to rewrite the config in project, to tell lsp to enable the features
Maybe solution
(second edition, helped by mathstuf and Nemo157)
maybe we can induce some option for cargo , like config the .cargo/config.toml, add something like
[profile.dev.package.<name>]
default-features = ["a", "b"]
this step make cargo remember the feature it used, next time I just need to run
cargo build
Then we do not to pass --feature to it again and again, and rust-analyer can use the option to do completion and highlight, no need to use extra .vscode/settings.json
or other configure file for some other editor.
and because it write something to target folder, then rust-analyzer can read it , then it will know it should enable which feature and disable others
This is the first time I make a pre-rfc. what do you think about the idea?