diff --git a/lua/tabnine/binary.lua b/lua/tabnine/binary.lua index b8c7662..86f8459 100644 --- a/lua/tabnine/binary.lua +++ b/lua/tabnine/binary.lua @@ -23,6 +23,8 @@ local function arch_and_platform() return "x86_64-pc-windows-gnu" elseif os_uname.sysname == "Windows_NT" then return "i686-pc-windows-gnu" + else + return nil end end @@ -36,6 +38,11 @@ local function binary_name() end local function binary_path() + local machine = arch_and_platform() + if not machine then + return nil -- Is this machine supported? + end + local paths = vim.tbl_map(function(path) return fn.fnamemodify(path, ":t") end, fn.glob(binaries_path .. "/*", true, true)) @@ -46,7 +53,19 @@ local function binary_path() table.sort(paths) - return binaries_path .. "/" .. tostring(paths[#paths]) .. "/" .. arch_and_platform() .. "/" .. binary_name() + local version = paths[#paths] + if not version then + vim.notify("Did you remember to run the build script for tabnine-nvim?", vim.log.levels.WARN) + return nil -- Is it installed? + end + local binary = binaries_path .. "/" .. tostring(version) .. "/" .. machine .. "/" .. binary_name() + + if vim.fn.filereadable(binary) then -- Double check that it's installed + return binary + else + vim.notify("Did you remember to run the build script for tabnine-nvim?", vim.log.levels.WARN) + return nil -- File doesn't exist or isn't readable. Is it installed? + end end local function optional_args() @@ -61,7 +80,7 @@ function TabnineBinary:start() self.stdin = uv.new_pipe() self.stdout = uv.new_pipe() self.stderr = uv.new_pipe() - self.handle, self.pid = uv.spawn(binary_path(), { + self.handle, self.pid = uv.spawn(self.binary_path, { args = vim.list_extend({ "--client", "nvim", @@ -73,6 +92,8 @@ function TabnineBinary:start() }, function() self.handle, self.pid = nil, nil uv.read_stop(self.stdout) + uv.read_stop(self.stderr) + self.stdout, self.stderr, self.stdin = nil, nil, nil end) uv.read_start( @@ -103,12 +124,16 @@ function TabnineBinary:new(o) self.restart_counter = 0 self.handle = nil self.pid = nil + self.binary_path = binary_path() self.callbacks = {} return o end function TabnineBinary:request(request, on_response) + if not self.binary_path then + return function() end -- To avoid breaking user configurations + end if not self.pid then self.restart_counter = self.restart_counter + 1 self:start()