Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

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

Open
sgoudham opened this issue Aug 3, 2022 · 9 comments

Comments

@sgoudham
Copy link

sgoudham commented Aug 3, 2022

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
Copy link
Author

sgoudham commented Aug 4, 2022

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 sgoudham changed the title How to update diagnostics in insert mode? Inlay hints and diagnostics not updating when only_current_line_autocmd = "CursorMoved,CursorMovedI" Aug 5, 2022
@simrat39
Copy link
Owner

simrat39 commented Aug 5, 2022

For the diagnostics, its a rust-analyzer limitation. See rust-lang/rust-analyzer#3107.

As for the inlay_hints, thanks for the report, I'll have a look

@simrat39
Copy link
Owner

simrat39 commented Aug 6, 2022

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.

@sgoudham
Copy link
Author

sgoudham commented Aug 6, 2022

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

@simrat39
Copy link
Owner

simrat39 commented Aug 6, 2022

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

@sgoudham
Copy link
Author

sgoudham commented Aug 6, 2022

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

@simrat39
Copy link
Owner

simrat39 commented Aug 6, 2022

What about with show parameter hints set to true?

@sgoudham
Copy link
Author

sgoudham commented Aug 7, 2022

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.

@simrat39
Copy link
Owner

Ok this should be fixed now, with 2e9e473

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants