tzachar / cmp-tabnine

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

Error on startup #3

Closed mayanksuman closed 3 years ago

mayanksuman commented 3 years ago

My setup is similar to this gist. However, I am getting following error on startup.

Error in packer_compiled: ...pack/packer/start/cmp-tabnine/lua/cmp_tabnine/source.lua:53: attempt to index local 'latest' (a nil value)
Please check your config for correctness
Error detected while processing /home/mayank/.local/share/nvim/site/pack/packer/start/cmp-tabnine/after/plugin/cmp-tabnine.lua:
E5113: Error while calling lua chunk: ...pack/packer/start/cmp-tabnine/lua/cmp_tabnine/source.lua:53: attempt to index local 'latest' (a nil value
)
tzachar commented 3 years ago

It looks like you do not have the TabNine binary installed. I've added a proper error message in c3a168e. Please verify your installation by running install.sh

mayanksuman commented 3 years ago

I forgot to mention in the issue description. Actually, I have TabNine binary (which I checked in the file explorer). However, still this issue comes.

Screenshot of vim startup (after updating and running install.sh). I have TabNine 3.6.8 binaries.

Screenshot from 2021-09-15 12-21-39

tzachar commented 3 years ago

Are you using WSL, or is this native windows?

mayanksuman commented 3 years ago

No, I am not using WSL. My setup is

OS: Debian GNU/Linux bookworm/sid x86_64 Kernel: 5.10.0-8-amd64 DE: GNOME 3.38.6 Shell: zsh 5.8 NVIM v0.5.0 LuaJIT 2.1.0-beta3

tzachar commented 3 years ago

Ok, can you do a find . in the binaries dir?

mayanksuman commented 3 years ago

The result for find .

.
./3.6.8
./3.6.8/x86_64-unknown-linux-musl
./3.6.8/x86_64-unknown-linux-musl/TabNine
./3.6.8/x86_64-unknown-linux-musl/TabNine-deep-cloud
./3.6.8/x86_64-unknown-linux-musl/TabNine-deep-local
./3.6.8/x86_64-unknown-linux-musl/WD-TabNine

The result for tree in the same directory.

.
└── 3.6.8
    └── x86_64-unknown-linux-musl
        ├── TabNine
        ├── TabNine-deep-cloud
        ├── TabNine-deep-local
        └── WD-TabNine

2 directories, 4 files
tzachar commented 3 years ago

Can you try this patch, and show me the output?

diff --git a/lua/cmp_tabnine/source.lua b/lua/cmp_tabnine/source.lua
index 6f3cd80..733b1cf 100644
--- a/lua/cmp_tabnine/source.lua
+++ b/lua/cmp_tabnine/source.lua
@@ -25,14 +25,18 @@ local binaries_folder = fn.expand('<sfile>:p:h:h:h') .. '/binaries'
 local function binary()
        local versions_folders = fn.globpath(binaries_folder, '*', false, true)
        local versions = {}
+ dump(versions_folders)
        for _, path in ipairs(versions_folders) do
+         dump(path)
                for version in string.gmatch(path, '/([0-9.]+)$') do
+                 dump('version:', version)
                        if version then
                                table.insert(versions, {path=path, version=version})
                        end
                end
        end
        table.sort(versions, function (a, b) return a.version < b.version end)
+ dump(versions)
        local latest = versions[#versions]
        if not latest then
                vim.notify('cmp-tabnine: Cannot find installed TabNine. Please run install.sh')
mayanksuman commented 3 years ago

The version_folder in my case is empty. Got following dump

{}
{}
cmp-tabnine: Cannot find installed TabNine. Please run install.sh
{}
{}
cmp-tabnine: Cannot find installed TabNine. Please run install.sh

I then printed out binaries_folder and I got "~/.dotfile/nvim/.config/binaries", which is wrong.

I guess issue is coming due to my choice of package manager. I use packer for managing my package. packer make packer_compiled.lua that load, run and configure all plugins. Hence, the code fn.expand('<sfile>:p') is giving the output as ~/.dotfile/nvim/.config/nvim/plugin/packer_compiled.lua

tzachar commented 3 years ago

I am also using packer, and do not have this issue. Can you try doing require('cmp_tabnine.config').setup() before loading any cmp code? A different option would be to allow users to override the automatic detection of the binaries directory.

tzachar commented 3 years ago

can you also try this?

diff --git a/lua/cmp_tabnine/source.lua b/lua/cmp_tabnine/source.lua
index 6f3cd80..98b69ab 100644
--- a/lua/cmp_tabnine/source.lua
+++ b/lua/cmp_tabnine/source.lua
@@ -21,9 +21,14 @@ end
 -- do this once on init, otherwise on restart this dows not work
 local binaries_folder = fn.expand('<sfile>:p:h:h:h') .. '/binaries'

+function script_path()
+   local str = debug.getinfo(2, "S").source:sub(2)
+   return str:match("(.*/)")
+end
+
 -- locate the binary here, as expand is relative to the calling script name
 local function binary()
-   local versions_folders = fn.globpath(binaries_folder, '*', false, true)
+ local versions_folders = fn.globpath(script_path() .. '../../binaries', '*', false, true)
        local versions = {}
        for _, path in ipairs(versions_folders) do
                for version in string.gmatch(path, '/([0-9.]+)$') do
mayanksuman commented 3 years ago

I was able to solve the issue with following diff (also submitted as PR #4 ).

diff --git c/lua/cmp_tabnine/source.lua w/lua/cmp_tabnine/source.lua
index 6f3cd80e7e17..ad63509cb2bc 100644
--- c/lua/cmp_tabnine/source.lua
+++ w/lua/cmp_tabnine/source.lua
@@ -17,9 +17,27 @@ local function json_decode(data)
    end
 end

+local function get_path_separator()
+    if ((fn.has('win64') == 1) or (fn.has('win32') == 1)) then return '\\' end
+    return '/'
+end
+
+function script_path()
+   local str = debug.getinfo(2, "S").source:sub(2)
+   return str:match("(.*" .. get_path_separator() .. ")")
+end
+
+local function get_parent_dir(path)
+    local separator = get_path_separator()
+    local pattern = "^(.+)" .. separator
+    -- if path has separator at end, remove it
+    path = string.gsub(path, separator .. '*$', '')
+    local parent_dir = string.match(path, pattern) .. separator
+    return parent_dir
+end

 -- do this once on init, otherwise on restart this dows not work
-local binaries_folder = fn.expand('<sfile>:p:h:h:h') .. '/binaries'
+local binaries_folder = get_parent_dir(get_parent_dir(script_path())) .. 'binaries'

 -- locate the binary here, as expand is relative to the calling script name
 local function binary()
tzachar commented 3 years ago

closing

Act0r1 commented 1 year ago

Are you using WSL, or is this native windows?

I'm using wsl and got this error, how I can fix that?

tzachar commented 1 year ago

idk, please provide more info in a new issue.