Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocmd only works once after upgrade to 0.10.0 #28874

Closed
telbizov opened this issue May 20, 2024 · 2 comments
Closed

autocmd only works once after upgrade to 0.10.0 #28874

telbizov opened this issue May 20, 2024 · 2 comments
Labels
closed:duplicate issues that are closed as duplicates of other issues

Comments

@telbizov
Copy link

Problem

Hello,

I have the following setup:

vim.api.nvim_create_autocmd("CursorHold", {
    once = false,
    callback = vim.diagnostic.open_float,
})

This used to work just fine before I upgraded to 0.10.0. It used to show the diagnostic float window every time when I positioned the cursor over the line of code that had the problem. If I moved out and back in it would show it again. After upgrade it now only pops up once after starting neovim. It seems like a regression. Or perhaps I need to modify the config somehow?

Thanks

Steps to reproduce

Try the config above

Expected behavior

Show the diagnostic float window every time. I.e. trigger the callback repeatedly not, only once!

Neovim version (nvim -v)

NVIM v0.10.0

Vim (not Nvim) behaves the same?

N/A because I need LSP

Operating system/version

macOS 14.4.1

Terminal name/version

iTerm2 3.4.23

$TERM environment variable

xterm-256color

Installation

brew

@telbizov telbizov added the bug issues reporting wrong behavior label May 20, 2024
@clason
Copy link
Member

clason commented May 20, 2024

Any return value will delete the callback, see :h news.

Your example will not work correctly anyway, since the callback is called with arguments, which other functions will not expect.

Callbacks should always be wrapped in dedicated functions; do not simply pass handles to API functions.

@telbizov
Copy link
Author

telbizov commented May 20, 2024

Roger that.
I had this code piece before and it used to work but I am far from an expert in neovim and Lua. Now that I took a closer look the following is what it should be:

vim.api.nvim_create_autocmd("CursorHold", {
    callback = function(ev)
        vim.diagnostic.open_float()
    end,
})

This works now!

Thanks for the pointers

@zeertzjq zeertzjq added closed:question issues that are closed as usage questions closed:duplicate issues that are closed as duplicates of other issues and removed bug issues reporting wrong behavior closed:question issues that are closed as usage questions labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:duplicate issues that are closed as duplicates of other issues
Projects
None yet
Development

No branches or pull requests

3 participants