rust-tools.nvim
rust-tools.nvim copied to clipboard
Inlay hints and diagnostics not updating when only_current_line_autocmd = "CursorMoved,CursorMovedI"
~Hi, this is more of a question regarding the current behaviour of rust-tools that I'm seeing. I'm unsure whether it is a bug or not.~
~You can see below in the gif provided that when code is edited in insert mode, the diagnostics do not seem to appear. It is only when I explicitly write to the buffer (as shown in the statusline) that the diagnostics update. Personally, I find this quite distracting as it always seems laggy and unresponsive. Especially when code is added/deleted, leading to the diagnostics overflows to the next line. I should also mention that the inlay hints do not update until I explicitly write to the buffer either.~
As the title says, inlay hints and diagnostics aren't updating when only_current_line_autocmd = "CursorMoved,CursorMovedI". The following gif only shows the updates when the buffer is explicitly written to.
Gif

My Config
init.lua
require("rust-tools").setup {
tools = {
autoSetHints = true,
hover_with_actions = true,
runnables = {
use_telescope = true
},
inlay_hints = {
show_parameter_hints = false,
other_hints_prefix = "<< ",
only_current_line = true,
only_current_line_autocmd = "CursorMoved,CursorMovedI"
},
},
-- See https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
server = {
on_attach = require("user.lsp.handlers").on_attach,
capabilities = require("user.lsp.handlers").capabilities,
settings = {
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
checkOnSave = {
command = "clippy"
},
completion = {
callable = {
snippets = "fill_arguments"
}
}
}
}
}
}
Diagnostic Information
Rust: rustc 1.62.1 (e092d0b6b 2022-07-16)
rust-tools.nvim: modularize_and_inlay_rewrite
rust-analyzer: 2022-08-01
Neovim: v0.8.0-dev-768-gb8dcbcc73
OS: Windows Subsystem for Linux 2
~I should also mention that I'm on the latest for the modularize_and_inlay_rewrite branch. I feel like this is a bug as I remember it updating within insert mode before. Or at the very least, updating when switching from insert to normal mode.~
~I have also remembered why I think it was working before, my config has the following option enabled to CursorMoved,CursorMovedI~
-- Event which triggers a refersh of the inlay hints.
-- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
-- not that this may cause higher CPU usage.
-- This option is only respected when only_current_line and
-- autoSetHints both are true.
only_current_line_autocmd = "CursorHold",
~In my issue, you can see in the gif I uploaded that it's not refreshing the inlay hints even though I have the above config ^ and therefore, a bug~
See original issue
For the diagnostics, its a rust-analyzer limitation. See https://github.com/rust-lang/rust-analyzer/issues/3107.
As for the inlay_hints, thanks for the report, I'll have a look
Inlay hints should update properly now. Please consider using https://github.com/simrat39/inlay-hints.nvim for a better experience with inlay hints in general.
Thanks for the quick update and the heads up for the new inlay hints plugin.
I can see the inlay hints updating in real time when only_current_line = false but if set to true, it doesn't seem to work at all :(
Could you check again? I pushed another fix which should fix your problem
I'm not sure what's happened but no inlay hints are appearing now, here is my config at the minute:
require("rust-tools").setup {
tools = {
autoSetHints = true,
hover_with_actions = true,
runnables = {
use_telescope = true
},
inlay_hints = {
show_parameter_hints = false,
other_hints_prefix = "<< "
},
},
-- See https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
server = {
on_attach = require("user.lsp.handlers").on_attach,
capabilities = require("user.lsp.handlers").capabilities,
settings = {
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
checkOnSave = {
command = "clippy"
},
completion = {
callable = {
snippets = "fill_arguments"
}
}
}
}
}
}
What about with show parameter hints set to true?
It works when parameter hints is set to true. However, I can't seem to be enable just inlay hints for variables or just for the current line.
Ok this should be fixed now, with https://github.com/simrat39/rust-tools.nvim/commit/2e9e47372930e66541a70b865fea167947b4d1da