patrickpichler / hovercraft.nvim

Context aware hover provider alternative to vim.lsp.buf.hover
MIT License
20 stars 0 forks source link

Sometimes I get an error when hovering over things that might not return anything #3

Closed av1155 closed 4 months ago

av1155 commented 4 months ago

Here I attempted to hover over a comment (lmao don't ask why)

Error executing vim.schedule lua callback: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...lar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/util.lua:1682: 'width' key must be a positive Integer
stack traceback:
    [C]: in function 'error'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'done'
    ...zy/hovercraft.nvim/lua/hovercraft/provider/lsp/hover.lua:43: in function 'handler'
    ...azy/hovercraft.nvim/lua/hovercraft/provider/lsp/util.lua:74: in function 'handler'
    ...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
patrickpichler commented 4 months ago

Do you by any chance have an example? I tried hovering over a comment in go and it just works, haha.

av1155 commented 4 months ago

In the below file; when hovering over 'extends' on the first JavaDoc comment, this error shows up:

Error executing vim.schedule lua callback: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...lar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/util.lua:1682: 'width' key must be a positive Integer
stack traceback:
    [C]: in function 'error'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'done'
    ...zy/hovercraft.nvim/lua/hovercraft/provider/lsp/hover.lua:43: in function 'handler'
    ...azy/hovercraft.nvim/lua/hovercraft/provider/lsp/util.lua:74: in function 'handler'
    ...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
package edu.aav66;

import javax.swing.JFrame;

/**
 * The {@code GameFrame} class extends {@link JFrame} and is responsible for creating
 * the main window of the Snake game. It initializes and sets up the game panel where
 * the game is played.
 *
 * This class configures the frame, adding the necessary components and setting
 * various properties like size, close operation, and visibility to make the game
 * ready to play immediately upon instantiation.
 */
public class GameFrame extends JFrame
{

    /**
     * Constructs a new {@code GameFrame} object, setting up the game environment.
     * It initializes a new {@code GamePanel} to be the content of this frame and
     * configures various properties of the frame to ensure the game is displayed
     * correctly.
     */
    public GameFrame()
    {
        // Add an instance of GamePanel to this frame
        this.add( new GamePanel() );

        // Set the title of the frame to "Snake"
        this.setTitle( "Snake" );

        // Ensure the application exits when the frame is closed
        this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

        // Disable resizing of the frame to maintain consistent gameplay
        this.setResizable( false );

        // Pack the components within the frame
        this.pack();

        // Make the frame visible to the user
        this.setVisible( true );

        // Position the frame in the center of the screen
        this.setLocationRelativeTo( null );
    }
}
av1155 commented 4 months ago

Also when I hover over extends keyword in public class GameFrame extends JFrame:

Error executing vim.schedule lua callback: ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...lar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp/util.lua:1682: 'width' key must be a positive Integer
stack traceback:
    [C]: in function 'error'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
    ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'done'
    ...zy/hovercraft.nvim/lua/hovercraft/provider/lsp/hover.lua:43: in function 'handler'
    ...azy/hovercraft.nvim/lua/hovercraft/provider/lsp/util.lua:74: in function 'handler'
    ...w/Cellar/neovim/0.9.5/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
patrickpichler commented 4 months ago

That is interesting, I cannot reproduce it locally. Can you maybe share init.lua config of how you setup hovercraft?

av1155 commented 4 months ago

I use AstroNvim as my Neovim distribution. Below is how I configure it:

Note: I utilize numerous plugins, all configured in the same manner. For details on setting up plugins with AstroNvim, refer to the Plugins Documentation.

plugins/user.lua:

    -- ==========================================================

    {
        "patrickpichler/hovercraft.nvim",

        dependencies = {
            { "nvim-lua/plenary.nvim" },
        },

        opts = function()
            return {
                window = {
                    border = "rounded",
                },

                -- keys = {
                --     { "<C-u>", function() require("hovercraft").scroll { delta = -4 } end },
                --     { "<C-d>", function() require("hovercraft").scroll { delta = 4 } end },
                --     { "<TAB>", function() require("hovercraft").hover_next() end },
                --     { "<S-TAB>", function() require("hovercraft").hover_next { step = -1 } end },
                -- },
            }
        end,
    },

    -- ==========================================================

plugins/astrolsp.lua:

            n = {
                ["<leader>ld"] = {
                    function()
                        local hovercraft = require "hovercraft"
                        if hovercraft.is_visible() then
                            hovercraft.enter_popup()
                        else
                            hovercraft.hover()
                        end
                    end,
                    desc = "Hover LSP provider",
                },
            },
av1155 commented 4 months ago

ChatGPT says there is something wrong in a line of some file; which I don't know if this file might be in AstroNvim's core, or in the files of Hovercraft:

ChatGPT response:

The error message you're encountering when using Neovim with the Hovercraft plugin indicates that there's a problem related to the 'width' key needing to be a positive integer. This issue seems to arise when the Lua callback function related to hovering actions is executed. Here’s a breakdown of what might be happening and how to approach a fix:

  1. Root of the Error: The error occurs in the file vim/lsp/util.lua at line 1682, where it specifies that the 'width' key must be a positive integer. This suggests that somewhere in the Hovercraft or a related plugin's configuration, a 'width' parameter is either not set, incorrectly set, or receiving a value that is not a positive integer.

  2. Possible Causes:

    • Incorrect Configuration: If the width is configured manually in your setup and it’s set to a non-positive integer or it’s computed dynamically and the computation goes wrong, it could lead to this error.
    • Plugin Conflict: There could be a conflict between plugins or with Neovim’s own settings that is leading to an invalid 'width' value.
    • Hovercraft Bug: The Hovercraft plugin itself might have a bug handling certain edge cases, especially when dealing with elements that don't have well-defined 'width' properties (like hovering over a JavaDoc comment where no additional information is expected).
  3. Debugging Steps:

    • Inspect Hovercraft’s Settings: Look into Hovercraft’s configuration, especially around parameters that might define dimensions like 'width'. If it’s not set, you might want to explicitly define it.
patrickpichler commented 4 months ago

I expect the problem to be occurring on this line. It is strange though, the width can be specified by the user via the config, or it is automatically calculated by nvim. The strange part is, why does it sometimes return a negative value for you? 🤔

Which version of nvim are you using?

patrickpichler commented 4 months ago

I think I found the issue. If the provider returns an empty response to display, hovercraft would replace it with a -- No Information available -- message. The problem is that this check fails for something like content = { '' }. It thinks there is something to display, but the neovim helper calculates a width of 0 for it, which causes it to fail.

I guess I have to implement a more elaborate check here 😅 I will let you know once it is fixed.

patrickpichler commented 4 months ago

@av1155 try pulling the latest version, it should fix it :)

av1155 commented 4 months ago

Thank you so much! That was crazy good bug fixing:

Awesome plugin; I have been using it since you released it!

image