goto-preview icon indicating copy to clipboard operation
goto-preview copied to clipboard

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

Open sainttttt opened this issue 2 years ago • 8 comments

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()<CR> 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

sainttttt avatar Feb 16 '23 03:02 sainttttt

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

rmagatti avatar Feb 17 '23 05:02 rmagatti

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.

sainttttt avatar Feb 17 '23 12:02 sainttttt

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

rmagatti avatar Feb 18 '23 00:02 rmagatti

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()

KnockerPulsar avatar Mar 17 '23 23:03 KnockerPulsar

i have a same problem too

jjpark78 avatar May 18 '23 02:05 jjpark78

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?

AlgusDark avatar Jun 12 '23 03:06 AlgusDark

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 😊

rmagatti avatar Jun 13 '23 18:06 rmagatti

@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 = {}.

AlgusDark avatar Jun 14 '23 06:06 AlgusDark

@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",
      },
    },
  },

Old-Farmer avatar Apr 18 '24 17:04 Old-Farmer