SmiteshP / nvim-navbuddy

A simple popup display that provides breadcrumbs feature using LSP server
Apache License 2.0
762 stars 30 forks source link

Getting error (attempt to index field 'data' (a nil value)) if auto_attach is set to true #64

Closed thatanjan closed 1 year ago

thatanjan commented 1 year ago

I installed this plugin with the following code.

    use {
        "SmiteshP/nvim-navbuddy",
        requires = {
            "neovim/nvim-lspconfig",
            "SmiteshP/nvim-navic",
            "MunifTanjim/nui.nvim",
            "numToStr/Comment.nvim", -- Optional
            "nvim-telescope/telescope.nvim", -- Optional
        },
        config = function()
            require("nvim-navbuddy").setup {
                lsp = {
                    auto_attach = true, -- If set to true, you don't need to manually use attach function
                },
            }
        end,
    }

I am getting this error when I open a file. But the plugin just works fine after that.

Error detected while processing LspAttach Autocommands for "*":                                                                                                             
E5108: Error executing lua vim/_editor.lua:0: LspAttach Autocommands for "*"..script nvim_exec2() called at LspAttach Autocommands for "*":0: Vim(echomsg):E114: Missing quo
te: "Error in packer_compiled: ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:118: LspAttach Autocommands for \"*\"..LspAttach Autocommands for \"*\": Vim(appe
nd):Error executing lua callback: ...ck/packer/start/nvim-navbuddy/lua/nvim-navbuddy/init.lua:367: attempt to index field 'data' (a nil value)                              
stack traceback:                                                                                                                                                            
        [C]: in function 'nvim_exec2'                                                                                                                                       
        vim/_editor.lua: in function 'cmd'                                                                                                                                  
        ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:179: in function <...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:175>                      
        [string ":lua"]:1: in main chunk                                                                                                                                    
        [C]: in function 'nvim_exec_autocmds'                                                                                                                               
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1665: in function '_on_attach'                                                                                              
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1472: in function ''                                                                                                        
        vim/_editor.lua: in function <vim/_editor.lua:0>                                                                                                                    

My neovim version: NVIM v0.10.0-dev-533+g7e301ed5b Config repo: https://github.com/thatanjan/neovim-config

SmiteshP commented 1 year ago

Can you check if this occurs in current neovim stable release as well for you? If not this could be some bug in the nightly version.

thatanjan commented 1 year ago

@SmiteshP I have tried the stable version but getting the same problem

SmiteshP commented 1 year ago

@thatanjan @navxio Is this occuring for any specific language? I am not able to reproduce this issue 🤔

navxio commented 1 year ago

@SmiteshP Apparently it happens with both lua and python for me.. I'm using neodev / lspconfig.pyright if that helps..

Here's the whole thing: https://github.com/navxio/dots/blob/trunk/.config/nvim/init.lua

thatanjan commented 1 year ago

@thatanjan @navxio Is this occuring for any specific language? I am not able to reproduce this issue thinking

@SmiteshP I have tried on ts, tsx, less, py. Basically, it occurs on all filetypes if you have lsp server installed for that file.

SmiteshP commented 1 year ago

@thatanjan @navxio Can you guys checkout the debug branch, have auto_attach=true in config and then open any file that shows this issue. Then run :messages command and paste the output here?

And for now as a work around you may use manual attachments instead

thatanjan commented 1 year ago

@SmiteshP here is the output.

{                                                                                                                                                                           
  buf = 1,                                                                                                                                                                  
  data = {                                                                                                                                                                  
    client_id = 1                                                                                                                                                           
  },                                                                                                                                                                        
  event = "LspAttach",                                                                                                                                                      
  file = "/home/anjan/.dotfiles/.config/qtile/config.py",                                                                                                                   
  id = 80,                                                                                                                                                                  
  match = "/home/anjan/.dotfiles/.config/qtile/config.py"                                                                                                                   
}                                                                                                                                                                           
{                                                                                                                                                                           
  buf = 1,                                                                                                                                                                  
  event = "LspAttach",                                                                                                                                                      
  file = "*",                                                                                                                                                               
  id = 80,                                                                                                                                                                  
  match = "/home/anjan/.dotfiles/*"                                                                                                                                         
}                                                                                                                                                                           
Error detected while processing LspAttach Autocommands for "*":                                                                                                             
E5108: Error executing lua vim/_editor.lua:0: LspAttach Autocommands for "*"..script nvim_exec2() called at LspAttach Autocommands for "*":0: Vim(echomsg):E114: Missing quo
te: "Error in packer_compiled: ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:118: LspAttach Autocommands for \"*\"..LspAttach Autocommands for \"*\": Vim(appe
nd):Error executing lua callback: ...ck/packer/start/nvim-navbuddy/lua/nvim-navbuddy/init.lua:368: attempt to index field 'data' (a nil value)                              
stack traceback:                                                                                                                                                            
        [C]: in function 'nvim_exec2'                                                                                                                                       
        vim/_editor.lua: in function 'cmd'                                                                                                                                  
        ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:179: in function <...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:175>                      
        [string ":lua"]:1: in main chunk                                                                                                                                    
        [C]: in function 'nvim_exec_autocmds'                                                                                                                               
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1665: in function '_on_attach'                                                                                              
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1472: in function ''                                                                                                        
        vim/_editor.lua: in function <vim/_editor.lua:0>  
SmiteshP commented 1 year ago

Aah I see whats happening!

The first autocommand being triggered is correct

{                                                                                                                                                                           
  buf = 1,                                                                                                                                                                  
  data = {                                                                                                                                                                  
    client_id = 1                                                                                                                                                           
  },                                                                                                                                                                        
  event = "LspAttach",                                                                                                                                                      
  file = "/home/anjan/.dotfiles/.config/qtile/config.py",                                                                                                                   
  id = 80,                                                                                                                                                                  
  match = "/home/anjan/.dotfiles/.config/qtile/config.py"                                                                                                                   
}          

But something is triggering the second autocommand as well which doesn't contain the data for some reason. Cannot definitively say whats causing this since I cannot reproduce the error, but perhaps some plugins you both have in common is doing it? Anyways, I can add a small check to ensure that data field is not null to fix the issue.

SmiteshP commented 1 year ago

Latest commit should have fixed this issue for you guys

thatanjan commented 1 year ago

image I still have the problem.

SmiteshP commented 1 year ago

Did you switch to master branch again?

thatanjan commented 1 year ago

Did you switch to master branch again?

Yes.

SmiteshP commented 1 year ago

Huh weird.. The if else check I added should prevent this error 🤔 Can you paste the error message again? is it the same error? Also can you double check if you are on latest commit of master.

thatanjan commented 1 year ago

Yes, I am using the master branch with the latest commit. Here is the error

E5108: Error executing lua vim/_editor.lua:0: LspAttach Autocommands for "*"..script nvim_exec2() called at LspAttach Autocommands for "*":0: Vim(echomsg):E114: Missing quote: "Error in packer_compiled: ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:118: LspAttach Autocommands for \"*\"..LspAttach Autocommands for \"*\": Vim(append):Error executing lua callback: ...ck/packer/start/nvim-navbuddy/lua/nvim-navbuddy/init.lua:367: attempt to index field 'data' (a nil value)
stack traceback:
    [C]: in function 'nvim_exec2'
    vim/_editor.lua: in function 'cmd'
    ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:179: in function <...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:175>
    [string ":lua"]:1: in main chunk
    [C]: in function 'nvim_exec_autocmds'
    /usr/share/nvim/runtime/lua/vim/lsp.lua:1687: in function '_on_attach'
    /usr/share/nvim/runtime/lua/vim/lsp.lua:1454: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
thatanjan commented 1 year ago

Just found out that the problem was with the Lspsaga plugin with Packer. Check this issue. https://github.com/nvimdev/lspsaga.nvim/issues/1128