nvimdev / epo.nvim

A blazing fast and minimal neovim autocompletion
MIT License
131 stars 4 forks source link

Attempt to index field "_session" (a nil value) #7

Closed BenjaminKern closed 8 months ago

BenjaminKern commented 9 months ago

When using the following config,

vim.opt.completeopt = "menu,menuone,noselect"

-- default settings
require('epo').setup({
    signature = true,
    snippet_path = nil,
})

I get the following error message, when jumping into a method with no parameters

Error executing vim.schedule lua callback: .../share/nvim/lazy/epo.nvim/lua/epo/init.lua:181: attempt to index field '_session' ( a nil value)

Most probably this one here https://github.com/nvimdev/epo.nvim/blob/main/lua/epo/init.lua#L181 needs to adapted. Maybe like


    api.nvim_create_autocmd('CursorMovedI', {
      buffer = ctx.bufnr,
      group = g,
      callback = function()
        ---@diagnostic disable-next-line: invisible
         if not vim.snippet._session then
          return
        end
        local count = vim.tbl_count(vim.snippet._session.tabstops)
        local curindex = vim.snippet._session.current_tabstop.index + 1
        if curindex == count then
          pcall(api.nvim_win_close, fwin, true)
          api.nvim_del_augroup_by_id(g)
        end
      end,
    })
  end, bufnr)

?

BenjaminKern commented 8 months ago

Unfortunately, the bug is still present, cf. attached screencast. bug

glepnir commented 8 months ago

can't reproduce. make sure is last commit

BenjaminKern commented 8 months ago

Hmm I am using the latest commit, I‘ll try to come up with a minimal reproducable example EDIT: This patch below, fixes it for me locally (which sort of makes sense, since you are checking that vim.snippet._session is null within the autocommand, but outside of the autocmmand you assume that vim.snippet._session is always not null). Still trying to come up with a simple reproducable example

diff --git a/lua/epo/init.lua b/lua/epo/init.lua
index 8fd955a..ef9623f 100644
--- a/lua/epo/init.lua
+++ b/lua/epo/init.lua
@@ -165,8 +165,6 @@ local function signature_help(client, bufnr, lnum)
       end,
     })

-    ---@diagnostic disable-next-line: invisible
-    local count = vim.tbl_count(vim.snippet._session.tabstops)
     api.nvim_create_autocmd({ 'CursorMovedI', 'CursorMoved' }, {
       buffer = ctx.bufnr,
       group = g,
@@ -178,7 +176,8 @@ local function signature_help(client, bufnr, lnum)
           ---@diagnostic disable-next-line: invisible
           and vim.snippet._session
           ---@diagnostic disable-next-line: invisible
-          and vim.snippet._session.current_tabstop.index + 1 == count
+          and vim.snippet._session.current_tabstop.index + 1
+            == vim.tbl_count(vim.snippet._session.tabstops)
         then
           is_out = true
         end