[Question] How to override a specific lsp config #747
-
Hi, I just found out about this project, very promising stuff I am trying to customize the lsp config: I install Is there a way to configure |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply, I tried that, but now I am encountering a different issue: I put this in [[language]]
name = "rust"
language-server = { command = "rustup", args = ["run", "nightly", "rust-analyzer"] }
config = """
{
"cargo": {
"allFeatures": true,
},
"checkOnSave": {
"command": "clippy",
}
}
""" But |
Beta Was this translation helpful? Give feedback.
-
Try turning on logging via |
Beta Was this translation helpful? Give feedback.
-
I tried that, but the |
Beta Was this translation helpful? Give feedback.
-
Seems like it doesn't work because the |
Beta Was this translation helpful? Give feedback.
-
So is it a bug ? Or am I doing something wrong in the config ? Also, changing back to language-server = { command = "rust-analyzer" } is no good either |
Beta Was this translation helpful? Give feedback.
-
That's because |
Beta Was this translation helpful? Give feedback.
-
Sorry, I meant that I tried this language-server = { command = "rust-analyzer" } with Anyhow, I figured out the problem: the json parsing of the provided config was failing silently due to the trailing commas. Since we're already in a |
Beta Was this translation helpful? Give feedback.
-
No, it has to be JSON according to the LSP spec. As for trailing commas, we should probably be logging such errors https://github.com/serde-rs/json/blob/8604ef948bec5190db6fa23d362bd3368620990c/src/error.rs#L66 Line 321 in 05c2a72 I'll get it done later today. |
Beta Was this translation helpful? Give feedback.
-
yes, I meant read it as a let toml_value: toml::Value = toml::from_str(r#"
[config.cargo]
allFeatures = true
[config.checkOnSave]
command = "clippy"
"#).unwrap();
let json_value: serde_json::Value = toml_value.try_into().unwrap();
println!("{}", serde_json::to_string_pretty(&json_value).unwrap()) |
Beta Was this translation helpful? Give feedback.
-
This goes outside of what I know (I haven't worked with the LSP code), but I suspect that it's because converting from JSON to Toml didn't really make sense. This was brought up before in the past before this was implemented, and I guess we decided to stick with JSON. |
Beta Was this translation helpful? Give feedback.
-
If anybody like me found this thread and tried to pass parameters to rust-analyzer this way: [[language]]
name = "rust"
language-server = { command = "rustup", args = ["run", "nightly", "rust-analyzer"] }
config = """
{
"cargo": {
"allFeatures": true
},
"checkOnSave": {
"command": "clippy"
}
}
""" and it did not work, here's how I managed to make it work: [[language]]
name = "rust"
# LSP config
config.cargo.features = "all" Basically, treat the config parameter as an object instead of a string. Found this reading the logs of the LSP with |
Beta Was this translation helpful? Give feedback.
-
For reference, these are some of my settings for Rust with rust-analyzer, and links to those settings, for anyone that wants to reference exactly which settings are being set. [[language]]
name = "rust"
[language.language-server]
# LSP Provider
command = "rust-analyzer"
[language.config]
# `rust-analyzer.procMacro.enable` (bool) <https://rust-analyzer.github.io/manual.html#rust-analyzer.procMacro.enable>
procMacro = { enable = false }
# `rust-analyzer.diagnostics.disabled` (list) <https://rust-analyzer.github.io/manual.html#unresolved-proc-macro>
# * `unresoled-proc-macro` - Warnings on macros
# * `inactive-code` - Code marked as inactive, such as by a cfg(windows) proc.
diagnostics = { disabled = [
"unresolved-proc-macro",
"inactive-code",
"missing-unsafe",
] } |
Beta Was this translation helpful? Give feedback.
Sorry, I meant that I tried this
with
rust-analyzer
in myPATH
but the config wasn't being applied either.Anyhow, I figured out the problem: the json parsing of the provided config was failing silently due to the trailing commas.
Since we're already in a
toml
file, shouldn't theconfig
be passed in as atoml::Value
rather than a json string ?