Skip to content

Commit

Permalink
fixup! fix(nextls): force a download
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Mar 8, 2024
1 parent d5c18c4 commit c26139d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 44 deletions.
14 changes: 0 additions & 14 deletions busted/nextls/install_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ describe("install", function()
vim.g.next_ls_cache_dir = "./busted/fixtures/basic/bin"
vim.g.next_ls_data_dir = "./busted/fixtures/basic/data"
vim.g.next_ls_default_bin = "./busted/fixtures/basic/bin/nextls"
local selected = nil
-- inputlist would require input and block the test;
vim.fn.inputlist = function(x)
selected = true
return 1
end
require("elixir.nextls").setup({auto_update = true, cmd = "./busted/fixtures/basic/bin/nextls" })
vim.cmd.edit("./busted/fixtures/basic/lib/basic.ex")
vim.wait(5000, function() return selected ~= nil end)
]])

eq(luv.fs_stat("./busted/fixtures/basic/bin/nextls").mode, 33523)
Expand All @@ -43,15 +36,8 @@ describe("install", function()
vim.g.next_ls_cache_dir = "./busted/fixtures/basic/bin"
vim.g.next_ls_data_dir = "./busted/fixtures/basic/data"
vim.g.next_ls_default_bin = "./busted/fixtures/basic/bin/nextls"
local selected = nil
-- inputlist would require input and block the test;
vim.fn.inputlist = function(x)
selected = true
return 1
end
require("elixir.nextls").setup({auto_update = true, cmd = "./busted/fixtures/basic/bin/nextls" })
vim.cmd.edit("./busted/fixtures/basic/lib/basic.ex")
vim.wait(5000, function() return selected ~= nil end)
]])

assert.error(function()
Expand Down
2 changes: 1 addition & 1 deletion lua/elixir/elixirls/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function M.compile(source_path, install_path, opts)
args = { install_path },
cwd = source_path,
on_start = function()
vim.notify("Compiling ElixirLS...")
vim.notify("[elixir-tools] Compiling ElixirLS...")
end,
on_stdout = do_sync and printer or vim.schedule_wrap(printer),
on_stderr = do_sync and printer or vim.schedule_wrap(printer),
Expand Down
4 changes: 2 additions & 2 deletions lua/elixir/elixirls/download.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function M.clone(dir, opts)
local rr = Utils.safe_path(opts.ref or "HEAD")
local dir_identifier = Path:new(r, rr).filename

vim.notify(string.format("Cloning ref %s from repo %s", opts.ref or "default", opts.repo))
vim.notify(string.format("[elixir-tools] Cloning ref %s from repo %s", opts.ref or "default", opts.repo))

local made_path = Path:new(dir):mkdir { parents = true, mode = 493 }
assert(made_path, "failed to make the path")
Expand All @@ -36,7 +36,7 @@ function M.clone(dir, opts)
assert(checkout.code == 0, "Failed to checkout ref " .. opts.ref)
end

vim.notify("Downloaded ElixirLS!")
vim.notify("[elixir-tools] Downloaded ElixirLS!")

return dir_identifier
end
Expand Down
12 changes: 6 additions & 6 deletions lua/elixir/elixirls/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ local function test(command)
if exit_code == 0 then
vim.api.nvim_buf_delete(term_buf_id, { force = true })
term_buf_id = nil_buf_id
vim.notify("Success: " .. cmd, vim.log.levels.INFO)
vim.notify("[elixir-tools] Success: " .. cmd, vim.log.levels.INFO)
else
vim.notify("Fail: " .. cmd, vim.log.levels.ERROR)
vim.notify("[elixir-tools] Fail: " .. cmd, vim.log.levels.ERROR)
end
end,
})
Expand Down Expand Up @@ -228,15 +228,15 @@ local function install_elixir_ls(opts)
end)
end

vim.notify("Finished compiling ElixirLS!")
vim.notify("Reloading buffer")
vim.notify("[elixir-tools] Finished compiling ElixirLS!")
vim.notify("[elixir-tools] Reloading buffer")
vim.api.nvim_command("edit")
vim.notify("Restarting LSP client")
vim.notify("[elixir-tools] Restarting LSP client")
vim.api.nvim_command("LspRestart")
vim.fn.jobstart({ "rm", "-rf", download_dir:absolute() }, {
on_exit = vim.schedule_wrap(function(_, rm_code)
if rm_code == 0 then
vim.notify("Cleaned up elixir-tools.nvim download directory")
vim.notify("[elixir-tools] Cleaned up elixir-tools.nvim download directory")
else
vim.api.nvim_err_writeln("Failed to clean up elixir-tools.nvim download directory")
end
Expand Down
4 changes: 2 additions & 2 deletions lua/elixir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local define_user_command = function()
local subcommand = args:next()
if "uninstall" == subcommand then
vim.fn.delete(nextls.default_bin)
vim.notify(string.format("Uninstalled Next LS from %s", nextls.default_bin), vim.lsp.log_levels.INFO)
vim.notify(string.format("[elixir-tools] Uninstalled Next LS from %s", nextls.default_bin), vim.lsp.log_levels.INFO)
elseif "to-pipe" == subcommand then
local row, col = get_cursor_position()
local uri = vim.uri_from_bufnr(0)
Expand All @@ -66,7 +66,7 @@ local define_user_command = function()
not_found = true
end
if not_found then
vim.notify("elixir-tools: unknown command: " .. opts.name .. " " .. opts.args, vim.lsp.log_levels.WARN)
vim.notify("[elixir-tools] Unknown command: " .. opts.name .. " " .. opts.args, vim.lsp.log_levels.WARN)
end
end, {
desc = "elixir-tools main command",
Expand Down
25 changes: 8 additions & 17 deletions lua/elixir/nextls/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ M.default_bin = vim.g.next_ls_default_bin or (vim.env.HOME .. "/.cache/elixir-to
M.default_data = vim.g.next_ls_data_dir or (vim.env.HOME .. "/.data/elixir-tools/nextls")

function M.setup(opts)
vim.print(opts)
local nextls_group = vim.api.nvim_create_augroup("elixir-tools.nextls", { clear = true })

vim.api.nvim_create_autocmd("User", {
Expand Down Expand Up @@ -106,27 +105,19 @@ function M.setup(opts)
})
end

local force_download = not vim.uv.fs_stat(M.default_data .. "/.next-ls-force-update-v1")
vim.fn.mkdir(M.default_data, "p")
local force_download_file = M.default_data .. "/.next-ls-force-update-v1"
local force_download = not vim.uv.fs_stat(force_download_file)
vim.print(M.default_data)

if
(force_download and opts.auto_update)
or (
not vim.b.elixir_tools_prompted_nextls_install
and type(opts.port) ~= "number"
and (opts.auto_update and not vim.uv.fs_stat(opts.cmd))
)
or (type(opts.port) ~= "number" and (opts.auto_update and not vim.uv.fs_stat(opts.cmd)))
then
vim.ui.select({ "Yes", "No" }, { prompt = "Install Next LS?" }, function(choice)
if choice == "Yes" then
utils.download_nextls()
activate()
else
vim.b["elixir_tools_prompted_nextls_install"] = true
end
end)
else
vim.schedule_wrap(activate)()
utils.download_nextls()
vim.fn.writefile({ "" }, force_download_file)
end
vim.schedule_wrap(activate)()
end
end,
})
Expand Down
5 changes: 3 additions & 2 deletions lua/elixir/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ local arch = {
}

function M.download_nextls(opts)
vim.notify("[elixir-tools] Downloading latest version of Next LS")
local default_cache_dir = vim.g.next_ls_cache_dir or vim.env.HOME .. "/.cache/elixir-tools/nextls/bin"
opts = opts or {}
local cache_dir = opts.cache_dir or default_cache_dir
Expand All @@ -61,7 +62,7 @@ function M.download_nextls(opts)

if not vim.v.shell_error == 0 then
vim.notify(
"Failed to fetch the latest release of Next LS from GitHub.\n\n"
"[elixir-tools] Failed to fetch the latest release of Next LS from GitHub.\n\n"
.. "Using the command `"
.. table.concat(curl, " ")
.. "`"
Expand Down Expand Up @@ -106,7 +107,7 @@ function M.latest_release(owner, repo, opts)
return vim.fn.readfile(latest_version_file)[1]
else
vim.notify(
"Failed to fetch the current "
"[elixir-tools] Failed to fetch the current "
.. repo
.. " version from GitHub or the cache.\n"
.. "You most likely do not have an internet connection / exceeded\n"
Expand Down

0 comments on commit c26139d

Please sign in to comment.