tzachar / compe-tabnine

TabNine source for hrsh7th/nvim-compe
BSD 3-Clause "New" or "Revised" License
52 stars 3 forks source link

Attempt to index field 'tabnine' (a boolean value) #5

Closed steinbrueckri closed 3 years ago

steinbrueckri commented 3 years ago

Hi Guys, I followed the "install guide" in the readme.:

  1. Install the Plugin - Plug 'tzachar/compe-tabnine', { 'do': './install.sh' }
  2. active the plugin - let g:compe.source.tabnine = v:true

and I get this error.:

Error detected while processing function <lambda>29:
line    1:
E5108: Error executing lua ...re/nvim/plugged/compe-tabnine/lua/compe_tabnine/init.lua:43: attempt to index field 'tabnine' (a boolean value)

OS: Darwin anubis 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64 nvim:

NVIM v0.5.0-dev+1112-ge55ded00c
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: /Applications/Xcode_12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/Users/runner/work/neovim/neovim/build/config -I/Users/runner/work/neovim/neovim/src -I/Users/runner/work/neovim/neovim/.deps/usr/include -I/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/include -I/Library/Frameworks/Mono.framework/Headers -I/Users/runner/work/neovim/neovim/build/src/nvim/auto -I/Users/runner/work/neovim/neovim/build/include
Compiled by runner@Mac-1614230343343.local

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

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info

Br Richard

tzachar commented 3 years ago

Can you try to apply this patch?

diff --git a/lua/compe_tabnine/init.lua b/lua/compe_tabnine/init.lua
index 76c783f..41fd4f6 100644
--- a/lua/compe_tabnine/init.lua
+++ b/lua/compe_tabnine/init.lua
@@ -40,8 +40,8 @@ function Source.get_metadata(_)
                menu = '[TN]';
                -- by default, do not sort
                sort = false;
-           max_lines = (vim.g.compe and vim.g.compe.source.tabnine.max_line) or 1000;
-           max_num_results = (vim.g.compe and vim.g.compe.source.tabnine.max_num_results) or 20;
+         max_lines = (vim.g.compe and vim.g.compe.source.tabnine and vim.g.compe.source.tabnine.max_line) or 1000;
+         max_num_results = (vim.g.compe and vim.g.compe.source.tabnine and vim.g.compe.source.tabnine.max_num_results) or 20;
        }
 end
steinbrueckri commented 3 years ago

image

tzachar commented 3 years ago

ok, a bit more verbose now:

diff --git a/lua/compe_tabnine/init.lua b/lua/compe_tabnine/init.lua
index 76c783f..72ea694 100644
--- a/lua/compe_tabnine/init.lua
+++ b/lua/compe_tabnine/init.lua
@@ -32,6 +32,19 @@ local Source = {
        callback = nil;
 }

+local function istable(t)
+ return type(t) == 'table'
+end
+
+local function has_conf(key, default)
+ if vim.g.compe and vim.g.compe.source and vim.g.compe.source.tabnine then
+         if istable(vim.g.compe.source.tabnine) then
+                 return vim.g.compe.source.tabnine[key]
+         end
+ end
+ return default
+end
+
 --- get_metadata
 function Source.get_metadata(_)
        return {
@@ -40,8 +53,8 @@ function Source.get_metadata(_)
                menu = '[TN]';
                -- by default, do not sort
                sort = false;
-           max_lines = (vim.g.compe and vim.g.compe.source.tabnine.max_line) or 1000;
-           max_num_results = (vim.g.compe and vim.g.compe.source.tabnine.max_num_results) or 20;
+         max_lines = has_conf('max_line', 1000);
+         max_num_results = has_conf('max_num_results', 20);
        }
 end
steinbrueckri commented 3 years ago

image

Do you need more input from me? BTW: Maybe it makes more sense if you just open a new branch for you fixed and I just pull the branch.

tzachar commented 3 years ago

ok, try this branch: https://github.com/tzachar/compe-tabnine/tree/fix_%235

Its strange as the bug above never happened on my machine. BTW, do you get the proper binaries downloaded?

steinbrueckri commented 3 years ago

@tzachar now it's working 🙌

image

BTW:

md5sum binaries/TabNine_Darwin
a2eb4c093999abc2695d87eae2edc5dd  binaries/TabNine_Darwin
tzachar commented 3 years ago

fixed in 0739a25