You can press the rustc(Click for full compiler diagnostic)
inside the vscode errors panel, I'm not necessarily looking for that exact same "click" feature inside Neovim, but I definitely want to get the actual full compiler diagnostic
itself somehow because they are very helpful.
I saw it on Jon Gjengset's youtube channel, unfortunately if forgot which video, however his was after either a test or just doing cargo run, it panicked and it showed the full compiler diagnostic
where it said exactly what he had to do to fix the error, which is what I mean when I say full compiler diagnostic
, rather than just saying code panicked here.
Just to be clear, I have 0 problems with rust-analyzer, normal errors, inlay hints, or clippy in neovim. Everything works fine, I'm just missing this feature from vscode, and can't find how to add it.
I asked around on discord, however I got mostly "I dont know"s, and a few people were recommending me fully fledged rust plugins for neovim that I just don't need, As I am already using trouble for errors, and I have no other problems with rust-analyzer and mason, I dont plan on adding in another plugin just for this extremely simple feature's sake.
I'm thinking that since this is the default for Vscode, I'm not sure why it wouldn't be possible without some kind of external dependency, just like how you can simply enable clippy via mason
& mason-lspconfig
like so:
lspconfig.rust_analyzer.setup({
settings = {
["rust-analyzer"] = {
check = {
command = "clippy",
},
},
},
})
If this really is not possible, I'm just going make a github issue, so I thought I would ask stackoverflow as a last resort before I did that, as I really doubt that there is not just some simple flag I can add to my settings, but I cannot find it, and nobody else knows.
I think that is more issue of neovim rendering what rust-analyzer already send.
You might study source code of this plugin. It retrieves full explanation and show it in separate window. If you want to show
available diagnostics in fancy way you might want to create your own handler :h diagnostic-handlers
Below is simple method that render full explanation in float window, you can find them in custom data (user_data
) returned by lsp:
diagnostic.user_data.lsp.data.rendered
-- where diagnostic is @type vim.Diagnostic
I found it by studing current buffer diagnostics with:
:lua print(vim.inspect(vim.diagnostic.get()))
You can try to format diagnostic shown in float, My configuration contains:
vim.diagnostic.config({
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "",
[vim.diagnostic.severity.WARN] = "",
[vim.diagnostic.severity.HINT] = "",
[vim.diagnostic.severity.INFO] = "",
}
},
float = {
header = "",
focusable = false,
border = "rounded",
close_events = {
"BufLeave",
"CursorMoved",
"InsertEnter",
"FocusLost"
},
prefix = "",
suffix = "",
format = function(diagnostic)
if diagnostic.source == 'rustc'
and diagnostic.user_data.lsp.data ~= nil
then
return diagnostic.user_data.lsp.data.rendered
else
return diagnostic.message
end
end,
},
virtual_text = false,
update_in_insert = true,
})
vim.keymap.set("n", "<leader>cd", vim.diagnostic.open_float, { desc = "Show diagnostic" })
Important here is format
function, it takes vim.Diagnostic
as an argument and return string
that is shown in float.