rmagatti / goto-preview

A small Neovim plugin for previewing definitions using floating windows.
Apache License 2.0
835 stars 27 forks source link

[BUG] attempt to index field 'lsp_configs' (a nil value) #88

Closed sainttttt closed 3 months ago

sainttttt commented 1 year ago

Description

Hi! I'm trying to get this to work with default parameters, and my built in lsp seems to be working fine, however I get this error when trying to use the preview function

Error executing vim.schedule lua callback: .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:246: attempt to index field 'lsp_configs' (a nil value)
stack traceback:
        .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:246: in function 'handle'
        .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:280: in function 'handler'
        ...l/Cellar/neovim/0.8.2/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue

Neovim version

NVIM v0.8.2 Build type: Release LuaJIT 2.1.0-beta3 Compiled by brew@Ventura

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/local/Cellar/neovim/0.8.2/share/nvim"

Run :checkhealth for more info

Nvim-lspconfig version

9b8f526

Operating system and version

macos 13.2

Affected language servers

all

Steps to reproduce

  1. Load plugin using Packer
  2. Run lua require('goto-preview').goto_preview_definition() command

Actual behavior

Error message received

Error executing vim.schedule lua callback: .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:246: attempt to index field 'lsp_configs' (a nil value)
stack traceback:
        .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:246: in function 'handle'
        .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:280: in function 'handler'
        ...l/Cellar/neovim/0.8.2/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue

Expected behavior

Preview definition should pop up

rmagatti commented 1 year ago

Could you enable debug = true on the setup call of the plugin, reproduce the issue again and post the logs here?

sainttttt commented 1 year ago

I get the same output || Error executing vim.schedule lua callback: .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:246: attempt to index field 'lsp_configs' (a nil value) || stack traceback: || .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:246: in function 'handle' || .../pack/packer/start/goto-preview/lua/goto-preview/lib.lua:280: in function 'handler' || ...l/Cellar/neovim/0.8.2/share/nvim/runtime/lua/vim/lsp.lua:1383: in function '' || vim/_editor.lua: in function <vim/_editor.lua:0>

By logs I assume you just mean :Messages right? Sorry if I'm not aware of another location.

rmagatti commented 1 year ago

Okay, that's interesting, I've never seen this on MacOS. I also haven't been able to reproduce this just yet

KnockerPulsar commented 1 year ago

Hello, I'm also getting the same error. This is with the default config and on Ubuntu 22.04 with nvim 0.8.1. I thought this my be my config so I checked out your dotfiles for the plugin's setup but it was pretty much the default too.

Note that I'm calling the plugin through lua and not a keybind like so:

lua require('goto-preview').goto_preview_definition()
jjpark78 commented 1 year ago

i have a same problem too

AlgusDark commented 1 year ago

Could be possible that anyone is initializing the plugin with nil instead of an empty table ({})?

I had this problem since I was doing the init with LazyVim, I was relying on the default Plugin.setup() for loading it.

@rmagatti shouldn't this plugin also should be ok to load with nil on the init params?

rmagatti commented 1 year ago

Oh that's a good catch, I think you're right, setting the config to nil might pose some issues currently. You are correct that it should just default to the default items if nil is passed for the whole config. I'll add this to my list of things to do but would accept a PR if anyone's willing to help out as well 😊

AlgusDark commented 1 year ago

@rmagatti I did some tests and require("goto-preview").setup() works as expected 🤔 I also see that there was a PR merged for accepting nil in 2022.

On my side, the problem is on how I can't setup the plugin with Lazy to be used with the heuristic setup

{
  "rmagatti/goto-preview",
  -- it doesn't work if you don't set opts

  -- opts = {}, -- it works

  -- this also works
  --      config = function()
  --        require("goto-preview").setup()
  --      end,

  -- this doesn't work
  -- main = "goto-preview",
}

I don't know what happens here as the issue here is not on LazyVIM in specific. On my end, when doing the other ways on setting up this on lazy (it seems that isn't heuristically finding the plugin main name) makes it so that the call target, cursor_position = M.conf.lsp_configs.get_config(data) is using M.conf = {}.

Old-Farmer commented 5 months ago

@rmagatti I did some tests and require("goto-preview").setup() works as expected 🤔 I also see that there was a PR merged for accepting nil in 2022.

On my side, the problem is on how I can't setup the plugin with Lazy to be used with the heuristic setup

{
  "rmagatti/goto-preview",
  -- it doesn't work if you don't set opts

  -- opts = {}, -- it works

  -- this also works
  --      config = function()
  --        require("goto-preview").setup()
  --      end,

  -- this doesn't work
  -- main = "goto-preview",
}

I don't know what happens here as the issue here is not on LazyVIM in specific. On my end, when doing the other ways on setting up this on lazy (it seems that isn't heuristically finding the plugin main name) makes it so that the call target, cursor_position = M.conf.lsp_configs.get_config(data) is using M.conf = {}.

I think this plugin need setup function called first. So for lazy.nvim, if you use default setup and do not set 'opts', you must set 'config' to true.

example:

  {
    "rmagatti/goto-preview",
    event = "BufEnter",
    config = true,
    keys = {
      {
        "<leader>pd",
        "<cmd>lua require('goto-preview').goto_preview_definition()<CR>",
        noremap = true,
        desc = "goto preview definition",
      },
      {
        "<leader>pD",
        "<cmd>lua require('goto-preview').goto_preview_declaration()<CR>",
        noremap = true,
        desc = "goto preview declaration",
      },
      {
        "<leader>pi",
        "<cmd>lua require('goto-preview').goto_preview_implementation()<CR>",
        noremap = true,
        desc = "goto preview implementation",
      },
      {
        "<leader>py",
        "<cmd>lua require('goto-preview').goto_preview_type_definition()<CR>",
        noremap = true,
        desc = "goto preview type definition",
      },
      {
        "<leader>pr",
        "<cmd>lua require('goto-preview').goto_preview_references()<CR>",
        noremap = true,
        desc = "goto preview references",
      },
      {
        "<leader>P",
        "<cmd>lua require('goto-preview').close_all_win()<CR>",
        noremap = true,
        desc = "close all preview windows",
      },
    },
  },