Documentation for Rust Analyzer settings

Hey all, I've looked at the User Manual for the Rust Analyzer, but I haven't really seen anything that touches on how to configure it through a settings.json. I'm currently working with Rust-Analyzer and YouCompleteMe in Neovim, and I am looking into how to configure my lang server, in particular how to turn off the --all-targets option. Is there any documentation I can look at?

1 Like

No, sadly we haven't got to documenting all the settings in editor-independept format properly yet.

The source of truth is here:

https://github.com/rust-analyzer/rust-analyzer/blob/a184c83535230af39fad3e238b7422b4972d597e/crates/rust-analyzer/src/config.rs#L453-L518

VS Code config (with some docs) is here:

https://github.com/rust-analyzer/rust-analyzer/blob/a184c83535230af39fad3e238b7422b4972d597e/editors/code/package.json#L204-L686

EDIT (2022-04-17): rust-analyzer --print-config-schema prints config schema in JSON format

Gotcha. Are there any plans to document this for non-vscode editors? If yes, is anybody working on it or can I go and make a PR?

So I figured out the mappings:

Basically, you want to put all of your settings inside

'ls': {
  'rust-analyzer': {
  # settings go here
  }
}

And they map to json by splitting by _, so for me the checkOnSave_allTargets would map out to

'rust-analyzer': {
  'checkOnSave': {
     'allTargets': True
  }
}

similarly it seems for all other configuration.

A possible catch is that the rust-analyzer version that comes with YCM might not be up to date, and so your desired settings might not be available. In that case, download the rust-analyzer binary and put it into ~/.cargo/bin for most rustup installations. Then point l:g_ycm_rust_toolchain_rust = '~/.cargo/' in your vim config.

Leaving this here so that if other people look they can find this.

2 Likes

Yes, but, as usual, there are more plans than available work hours.

Here are two tasks that would help

Easy: add 'ls': {'rust-analyzzer': {}} syntax to the manual so that people know where to put settings.

Hard: add support for doc comments to the source of truth, then generate package.json section from it, as well as a dedicated section in the manual. See codegen.rs for how similar things are done.

1 Like

Added somewhat more thorough mentoring insturctions to https://github.com/rust-analyzer/rust-analyzer/issues/6112#issuecomment-708457501

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.