How to use Clippy in VS Code with rust-analyzer?

I am using rust-analyzer for IDE features. But I would like to have Clippy to lint my code as well. I could have installed Rust or Rust(rls) extension, but I don't want multiple language servers running at the same time.

7 Likes

Switch the 'Check on Save Command' setting from check to clippy:

image

Or, if you prefer editing your settings.json by hand:

"rust-analyzer.checkOnSave.command": "clippy"

This should give you Clippy errors/warnings inline like you'd expect (please don't judge my code :sweat_smile:) :

22 Likes

Have you found this to be slower? I ended up switching it off. I had issues where it took a lot longer to update the highlighting in vscode and got the alert “waiting for save actions from rust-analyzer”

I occasionally have that issue too (with checkOnSave.command set to check). I wait for a few seconds and everything goes back to normal.

I have that too with it set to “check” but set to “clippy” I ended up having to cancel the save action after a couple minutes of waiting.

1 Like

It might be a tiny bit slower, but I definitely haven't been having to wait minutes for save actions to run. I have had issues with autoformatting slowing down saving occasionally, but it's rare enough that it doesn't bother me that much.

I recently switched after @matklad let me know (on GitHub) that this was how to do it. It's definitely a bit slower, but that's to be expected. Nothing unreasonable, imo. Certainly not minutes.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.