rust-tools.nvim
rust-tools.nvim copied to clipboard
How do I configure virtual text?
Thanks for this tool. It makes the daily argument with the Rust compiler easier to manage.
The problem I'm running into is that I find all this virtual text to be highly distracting. I would rather errors and hints be hidden until I hover over them or navigate to them with [g. I tried setting various options in tools.inlay_hints but none of them seem to be doing anything (I actually don't know what an inlay hint is.) I've previously just turned off virtual text all together with:
vim.diagnostic.config{
virtual_text = false
}
But I actually like some of the virtual text that it gives information about the type that each line returns like the gray text shown here:

I don't want to miss out on all of the virtual text features but I'd like to reduce the amount of information overload. How can I configure what information is shown in the virtual text?
Additionally, it seems that RustDisableInlayHints only turns off that gray text but the warnings and hints remain appended to the line the appear on. I basically would like the opposite of that. Sorry for my ignorance, but I can't find where any of this is documented. :h doesn't have any results for "inlay"
The yellow/blue stuff is normal neovim diagnostic virtual text, so yeah you can disable it the way you did. For the others, I would probably recommend the only_current_line config option (not sure if that's the exact key, check the readme), this shows the inlay hint only for the currently hovered line
I actually tried that and it didn't seem to do anything. I was still getting virtual text on other lines. :(
Could you paste your rust-tools config please?
Sure.
local opts = {
tools = { -- rust-tools options
autoSetHints = false,
hover_with_actions = true,
inlay_hints = {
-- only_current_line = true,
show_parameter_hints = false,
-- parameter_hints_prefix = "",
-- other_hints_prefix = "",
},
},
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
server = {
settings = {
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
checkOnSave = {
command = "clippy",
allFeatures = true,
},
}
}
},
}
require('rust-tools').setup(opts)
Sure.
local opts = { tools = { -- rust-tools options autoSetHints = false, hover_with_actions = true, inlay_hints = { -- only_current_line = true, show_parameter_hints = false, -- parameter_hints_prefix = "", -- other_hints_prefix = "", }, }, -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer server = { settings = { -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc ["rust-analyzer"] = { checkOnSave = { command = "clippy", allFeatures = true, }, } } }, } require('rust-tools').setup(opts)
only_current_line is commented, is it still broken when its not commented? Might be a bug when show_parameter_hints is disabled and only_current_line is enabled at the same time
Okay I uncommented only_current_line and left everything else as is. I'm getting virtual text same as shown in my original post. Toggling show_parameter_hints seems to have no effect.
Okay I've created a minimal configuration to try to rule out the problem but it seems to persist. This is my init.lua and virtual text is still showing up in this configuration.
vim.cmd([[
call plug#begin('~/.local/share/nvim/plugs')
Plug 'neovim/nvim-lspconfig'
Plug 'simrat39/rust-tools.nvim'
call plug#end()
]])
local opts = {
tools = { -- rust-tools options
autoSetHints = false,
hover_with_actions = true,
inlay_hints = {
-- only_current_line = true,
show_parameter_hints = false,
-- parameter_hints_prefix = "",
-- other_hints_prefix = "",
},
},
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
server = {
settings = {
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
checkOnSave = {
command = "clippy",
allFeatures = true,
},
}
}
},
}
require('rust-tools').setup(opts)