hovercraft.nvim icon indicating copy to clipboard operation
hovercraft.nvim copied to clipboard

Use pylsp as provider

Open Andrey1008 opened this issue 1 year ago • 15 comments

Is there any easy way to set pylsp as provider? I seen in readme that it is possible to make custom provider, but sadly I doesnt know lua at all.

Andrey1008 avatar Oct 11 '24 17:10 Andrey1008

Hey, Thanks for the request. I am not familiar with pylsp, but if you setup your neovim to work with pylsp (e.g. autocompletion or hover works with the built-in hover window), it should work out of the box with hovercraft.nvim.

Is there any particular issue you are facing?

patrickpichler avatar Oct 12 '24 09:10 patrickpichler

Hover window never appeared for me so I guess there something to do with providers

Andrey1008 avatar Oct 12 '24 12:10 Andrey1008

Interesting! I just tried it locally and for me it appears to be working fine hm.

Can you maybe share a minimal example of your dotfiles + some project where you experience the problem?

The reason the window never shows up, is that the LSP is probably never responding. Maybe some kind of timeout would be a good idea.

patrickpichler avatar Oct 12 '24 17:10 patrickpichler

I just copied setup to my init.lua file, checked that it is was visible in lazy menu and created new .py to test it out, but nothing happened. Also after starting nvim there is text "No active providers for line!" at the bottom, is that important or not?

Andrey1008 avatar Oct 12 '24 17:10 Andrey1008

Can you maybe share your init.lua file?

patrickpichler avatar Oct 12 '24 17:10 patrickpichler

init.lua.txt github doesnt allow lua files so I changed extension to txt

Andrey1008 avatar Oct 12 '24 17:10 Andrey1008

Ah I see, you are missing the LSP setup path in nvim. I would recommend having a look at how kickstarter.nvim is doing the setup here.

patrickpichler avatar Oct 12 '24 17:10 patrickpichler

So I need to copy that code from line 454 to line 666 into my init.lua? Tried that out, but it doesnt seem to help. Could you please explain what is lsp setup path, I dont know lua so it is hard for me to understand how it works.

Andrey1008 avatar Oct 12 '24 18:10 Andrey1008

It seems as if you are new to neovim and therefore I would highly recommend you to read up on the documentation. In the end, the lines you copied on its own will not install any LSP, it will only configure mason.nvim, as well as nvim-lspconfig. You can now run the :Mason command and install pylsp via it. After that you should have the LSP setup.

Overall, I would recommend taking a closer look at kickstarter.nvim and maybe even consider basing your whole config on it.

patrickpichler avatar Oct 13 '24 17:10 patrickpichler

I think there is some misunderstanding, I have working python lsp in neovim, also I had hover.nvim before and it worked in term of displaying hover window, but there was issue when wrong documentation showed up, so I tried hovercraft and this all started. In summary whole issue is that in same conditions that hover.nvim works, hovercraft doesnt. Sorry for misleading issue title.

Andrey1008 avatar Oct 14 '24 19:10 Andrey1008

Ah ok! Which version of neovim are you using?

patrickpichler avatar Oct 19 '24 18:10 patrickpichler

0.10

Andrey1008 avatar Oct 19 '24 21:10 Andrey1008

Sorry for the very late response, is the problem still there?

I am pretty sure it is caused by the LSP not being fully initialised and hence will hang when calling the lsp util method to get the data back (here).

patrickpichler avatar Dec 22 '24 10:12 patrickpichler

Don't know if it's the same issue, but in my case I think the LSP is taking over the keymap during BufferNew or other events. Thus hovercraft doesn't get a chance to bind K again. I'm using LazyVim

msoares1979 avatar Feb 10 '25 12:02 msoares1979

Do you by any chance have a minimal example config for me to test this?

patrickpichler avatar Feb 10 '25 19:02 patrickpichler

I've tried this simple LazyVim installation

.config/nvim/init.lua

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  spec = {
    { "LazyVim/LazyVim", import = "lazyvim.plugins", opts = { colorscheme = "catppuccin" } },
    { import = "plugins/hovercraft" }, -- import/override with your plugins
  },
  defaults = {    lazy = false,    version = false },
  install = { colorscheme = { "tokyonight", "catppuccin" } },
  checker = { enabled = true }, -- automatically check for plugin updates
  performance = {
    rtp = {
      disabled_plugins = {
        "gzip",
        "netrwPlugin",
        "tohtml",
        "tutor",
        "zipPlugin",
      },
    },
  },
})

hovercraft configuration

return {
  'patrickpichler/hovercraft.nvim',

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

  debug = true,

  -- this is the default config and can be skipped
  opts = {
    providers = {
      providers = {
        { 'lsp',  function() return require('hovercraft.provider.lsp.hover') end },
        { 'man',  function() return require('hovercraft.provider.man') end },
        { 'dict', function() return require('hovercraft.provider.dictionary') end },
      }
    },

    window = {      border = 'single',    },

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

  event = 'VeryLazy',

  keys = {
    {
      "<leader>k", function()
        local hovercraft = require("hovercraft")
        if hovercraft.is_visible() then
          hovercraft.enter_popup()
        else
          hovercraft.hover()
        end
      end,
      desc = 'Hovercraft keywords'
    },
  },
}

I don't get anything even when calling :lua require('hovercraft').hover() directly, although the plugin appear as loaded

msoares1979 avatar May 28 '25 16:05 msoares1979

I managed to reproduce the issue with lazy. I am on vacation this week though and will have a look at it next weekend!

patrickpichler avatar Jun 01 '25 11:06 patrickpichler

Alright, I found the issue @msoares1979. The config needs to look like this:

return {
  'patrickpichler/hovercraft.nvim',

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

  debug = true,

  -- this is the default config and can be skipped
  opts = function() -- <-- sadly we need to use a function here
    return {
      providers = {
        providers = {
          { 'lsp',  require('hovercraft.provider.lsp.hover').new() }, -- <-- we need to use the .new() constructor of the provider, as functions have special meanings (i will rework this part probably)
          { 'man',  require('hovercraft.provider.man').new() },
          { 'dict', require('hovercraft.provider.dictionary').new() },
        }
      },

      window = { border = 'single', },

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

  event = 'VeryLazy',

  keys = {
    {
      "<leader>k",
      function()
        local hovercraft = require("hovercraft")
        if hovercraft.is_visible() then
          hovercraft.enter_popup()
        else
          hovercraft.hover()
        end
      end,
      desc = 'Hovercraft keywords'
    },
  },
}

This brings up a good point though, as this is not best practice on how to configure a plugin via lazy. I need to rethink the configuration a bit. Thanks for raising the issue!

patrickpichler avatar Jun 22 '25 09:06 patrickpichler

I will close this issue. Feel free to reopen it, if needed.

patrickpichler avatar Oct 19 '25 18:10 patrickpichler