Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions plugin/command.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
local util = require('odools.utils')
local command = {}
command.target = "0.4.0"
command.bin_path = ""

local download = function(url, output_path, asset_type)
print("Starting download from: " .. url)
print("Saving to: " .. output_path)

local stdout = vim.uv.new_pipe(false)
local stderr = vim.uv.new_pipe(false)

local handle
local args, cmd
if asset_type == "file" then
if vim.fn.filereadable(output_path) == 1 then
vim.api.nvim_echo({{"Delete previous file"}}, true, {})
vim.uv.fs_unlink(output_path)
end
cmd = "wget"
args = { "-qO", output_path, url }
else
cmd = "git"
args = { "clone", "-q", url, output_path}
end
vim.api.nvim_echo({{"Starting download from: " .. url}}, true, {})
vim.api.nvim_echo({{"Saving to: " .. output_path}}, true, {})

handle = vim.uv.spawn(cmd, {
args = args,
stdio = { nil, stdout, stderr },
Expand All @@ -27,11 +30,15 @@ local download = function(url, output_path, asset_type)
stderr:close()
handle:close()

if code == 0 then
print("\nDownload successful!")
local msg = {"\nDownload successful!"}
if code ~= 0 then
msg = {"\nDownload failed with exit code " .. code}
else
print("\nDownload failed with exit code " .. code)
vim.uv.fs_chmod(output_path, 493)
end
vim.schedule(function()
vim.api.nvim_echo({msg}, true, {})
end)
end)

stdout:read_start(function(err, data)
Expand All @@ -57,20 +64,18 @@ local download_requirements = function()
if vim.fn.isdirectory(bin_dir_path) == 0 then
os.execute('mkdir -p ' .. bin_dir_path)
end
vim.cmd.LspStop('odools')
download("https://github.com/odoo/odoo-ls/releases/download/" .. command.target .. "/odoo_ls_server", bin_path, 'file')
if vim.fn.executable('git') == 1 then
local path = bin_dir_path .. '/typeshed'
if vim.fn.isdirectory(path) == 0 then
download('https://github.com/python/typeshed.git', path, 'repo')
else
print("typeshed already downloaded")
vim.api.nvim_echo({{"typeshed already downloaded"}}, true, {})
end
else
vim.api.nvim_err_writeln("git needed to download python typeshed")
end
os.execute('chmod +x ' .. bin_path)
vim.cmd.LspStart('odools')
vim.cmd.LspRestart('odools')
end

local odoo_command = function(opts)
Expand Down