rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

Inlay hints and diagnostics not updating when only_current_line_autocmd = "CursorMoved,CursorMovedI"

Open sgoudham opened this issue 3 years ago • 9 comments

~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

rust-diagnostics

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

sgoudham avatar Aug 03 '22 22:08 sgoudham

~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

sgoudham avatar Aug 04 '22 11:08 sgoudham

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

simrat39 avatar Aug 05 '22 23:08 simrat39

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.

simrat39 avatar Aug 06 '22 00:08 simrat39

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 :(

sgoudham avatar Aug 06 '22 00:08 sgoudham

Could you check again? I pushed another fix which should fix your problem

simrat39 avatar Aug 06 '22 01:08 simrat39

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"
                    }
                }
            }
        }
    }
}

sgoudham avatar Aug 06 '22 01:08 sgoudham

What about with show parameter hints set to true?

simrat39 avatar Aug 06 '22 02:08 simrat39

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.

sgoudham avatar Aug 07 '22 00:08 sgoudham

Ok this should be fixed now, with https://github.com/simrat39/rust-tools.nvim/commit/2e9e47372930e66541a70b865fea167947b4d1da

simrat39 avatar Aug 10 '22 00:08 simrat39