Open RobertMenke opened 2 years ago
I'm having the same issue. I can't seem to get LSP for clippy
, even after adding it to checkOnSave
.
Are you sure this is a documentation issue and not a feature issue?
Make sure you're not using a rust nightly toolchain with Clippy broken. I spent days on this till I find out that Clippy was broken on the nightly version I was using. I switched back to stable and it was working.
FWIW, the checkOnSave
configuration you showed above is working for me. Here's my config.
local rt = require("rust-tools")
rt.setup({
server = {
on_attach = function(_, bufnr)
-- Hover actions
vim.keymap.set("n", "K", rt.hover_actions.hover_actions, { buffer = bufnr })
-- Code action groups
vim.keymap.set("n", "<space>ca", rt.code_action_group.code_action_group, { buffer = bufnr })
end,
settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy"
}
}
}
},
})
And here's my clippy version info:
$ cargo clippy --version
clippy 0.1.64 (a55dd71d 2022-09-19)
I fixed this issue a while ago, but I believe it was caused by initializing rust-analyzer
directly with the settings, then calling rust-tools
with no settings, which overwrote it.
The above might have been correct for previous versions of rust-analyzer
, but not anymore. Check out the rust-analyzer
manual and scroll/search your way down to rust-analyzer.checkOnSave
. You will see that this is a boolean value. It controls whether or not a "check" is run on save, and defaults to true
. By default that does cargo check
on save.
What you want is to override the rust-analyzer.check.command
to instead run clippy
. You can also add extra arguments to the command if you want.
TLDR; You want something like this:
require("rust-tools").setup({
server = {
settings = {
["rust-analyzer"] = {
check = {
command = "clippy",
extraArgs = { "--all", "--", "-W", "clippy::all" },
},
},
},
},
})
Hey, thank you for putting together this wonderful plugin!
I'm trying to get clippy feedback to show up in my editor as warnings. I think I may be missing something obvious, but given clippy's, popularity it would be great to have this integration documented on the readme. I'm more than happy to submit a PR once I can get this figured out myself.
My config is below: