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

Hydra prevents vim.diagnostic.goto_next() from opening float window #87

Open
Rodrigodd opened this issue Jun 4, 2023 · 4 comments
Open

Comments

@Rodrigodd
Copy link

Hi, thank you very much for this excellent plugin, really helps with some keymaps. But I have a minor problem.

I am using Hydra with the following mapping:

Hydra({
    -- name = "Navigate diagnostics",
    mode = 'n',
    body = 'g',
    config = {
        hint = false,
    },
    heads = {
        { '[', vim.diagnostic.goto_prev },
        { ']', vim.diagnostic.goto_next },
    },
})

When you call vim.diagnostic.goto_next() it, by default, calls vim.diagnostic.open_float(), that opens a floating window with the diagnostic description. But Hydra appears to be preventing that from happening, if I run the mapping, only when I exit hydra with the Esc key that the floating window appears.

I have found this Reddit post describing the same problem in point 2. One of the comments say that "2 [looks like] as (neovim) design decision to not use floating windows and the additional complexity of handling them", but not sure what that is really implying.

There is anything that could be done to prevent this problem?

@GCBallesteros
Copy link

I'm observing a similar behaviour, where only after exiting the hydra commands actually run. It feels like they are buffered. In my particular case I have a hydra that sends a line of code to a repl but only after exiting the hydra the line gets actually shown and run on the repl.

Here is a minimal example using Vigemus/iron.nvim

hydra = require "hydra"
iron = require "iron.core"

hydra({
    name = "TestHydra",
    mode = { "n" },
    body = "<leader>u",
    heads = {
        {
            "x",
            function()
                iron.send("python", "print('hello')")
            end,
            { desc = "Run command" },
        },
        { "q", nil, { exit = true, nowait = true, desc = "exit" } },
    },
})

Running the hydra opens a new empty split, where the repl should show up. Only after exiting the hydra the repl gets populated and the line of code run. If you then exit and run again the hydra nothing happens until you exit once more.

@GCBallesteros
Copy link

@Rodrigodd After some playing around I found that making a pink hydra fixed my issue. You can try doing this by updating your hydra to:

hydra({
    name = "TestHydra",
    mode = { "n" },
    config = {
      invoke_on_body = true,
      color = "pink",
    },

    body = "<leader>u",
   --- more
})

@Rodrigodd
Copy link
Author

@GCBallesteros Can confirm, setting color = 'pink' did solve the problem (setting foreign_key = 'run' take no effect, not sure if I did that right). Also, being able to apply changes and run quick-fixes, and still continue navigating the diagnostics is nice.

Only problem was that my mappings started conflicting with [% and ]% mappings, mappings from vim built-in matchit plugin (wasn't aware that something like that exist). But that was fixed by just unmapping them.

I looked at the implementation of diagnosts.goto_next and iron.nvim, and they call vim.schedule and vim.chansend, respectively. Maybe hydra is by default blocking neovim main event-loop or something?

@GCBallesteros
Copy link

In my investigations I thought about that too and commented out most of the code in iron.nvim including the chansend but problems persisted. Then I realized that #84 had found the same solution and that other plugins such as notify.nvim have problems too.

With notify.nvim I noticed that when called from the hydra you can see a faint outline of the notification box on the corner but it never gets fully rendered and displayed until the hydra is exited.

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

No branches or pull requests

2 participants