tzachar / cmp-tabnine

TabNine plugin for hrsh7th/nvim-cmp
MIT License
287 stars 28 forks source link

Error on first startup #9

Closed bangedorrunt closed 3 years ago

bangedorrunt commented 3 years ago

I got this error when first install cmp-tabnine

...e/pack/packer/opt/cmp-tabnine/lua/cmp_tabnine/source.lua:197: attempt to index local 'ctx' (a nil value)

I'm using

NVIM v0.6.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by nixbld1

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

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/nix/store/ql7v7cs2qmbr00s6qjkwp3wz2w0bz08a-neovim-unwrapped-master/share/nvim"

Run :checkhealth for more info
tzachar commented 3 years ago

Can you try this?

diff --git a/lua/cmp_tabnine/source.lua b/lua/cmp_tabnine/source.lua
index 8317372..13923fc 100644
--- a/lua/cmp_tabnine/source.lua
+++ b/lua/cmp_tabnine/source.lua
@@ -150,10 +150,6 @@ function Source.complete(self, ctx, callback)
        Source._do_complete(ctx)
 end

-Source._on_err = function(_, _, _)
-   table.remove(Source.ctx_list, 1)
-end
-
 Source._on_exit = function(_, code)
        -- restart..
        if code == 143 then
@@ -167,7 +163,7 @@ Source._on_exit = function(_, code)
        end
        Source.ctx_list = {}
        Source.job = fn.jobstart({bin, '--client=cmp.vim'}, {
-           on_stderr = Source._on_stderr;
+         on_stderr = nil;
                on_exit = Source._on_exit;
                on_stdout = Source._on_stdout;
        })
@@ -187,7 +183,10 @@ Source._on_stdout = function(_, data, _)
       --   "user_message": [],
       --   "docs": []
       -- }
-   -- dump(data)
+ -- check that we have a context.
+ if #Source.ctx_list == 0 then
+         return
+ end
        local items = {}
        local old_prefix = ""
        local show_strength = conf:get('show_prediction_strength')
bangedorrunt commented 3 years ago

@tzachar git apply the patch failed to me so I had to do it manually, it seems the bug is fixed. I did some fresh install and no error shown up. Thank you!