From c26139dec04f1cf823327ce331de41d5ebc02902 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Thu, 7 Mar 2024 20:22:02 -0500 Subject: [PATCH] fixup! fix(nextls): force a download --- busted/nextls/install_spec.lua | 14 -------------- lua/elixir/elixirls/compile.lua | 2 +- lua/elixir/elixirls/download.lua | 4 ++-- lua/elixir/elixirls/init.lua | 12 ++++++------ lua/elixir/init.lua | 4 ++-- lua/elixir/nextls/init.lua | 25 ++++++++----------------- lua/elixir/utils.lua | 5 +++-- 7 files changed, 22 insertions(+), 44 deletions(-) diff --git a/busted/nextls/install_spec.lua b/busted/nextls/install_spec.lua index 3a793a15..9ea99008 100644 --- a/busted/nextls/install_spec.lua +++ b/busted/nextls/install_spec.lua @@ -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) @@ -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() diff --git a/lua/elixir/elixirls/compile.lua b/lua/elixir/elixirls/compile.lua index 328867b8..53ff5c91 100644 --- a/lua/elixir/elixirls/compile.lua +++ b/lua/elixir/elixirls/compile.lua @@ -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), diff --git a/lua/elixir/elixirls/download.lua b/lua/elixir/elixirls/download.lua index fd76412a..71a9e7d9 100644 --- a/lua/elixir/elixirls/download.lua +++ b/lua/elixir/elixirls/download.lua @@ -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") @@ -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 diff --git a/lua/elixir/elixirls/init.lua b/lua/elixir/elixirls/init.lua index 6fa0f81c..fe7812f5 100644 --- a/lua/elixir/elixirls/init.lua +++ b/lua/elixir/elixirls/init.lua @@ -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, }) @@ -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 diff --git a/lua/elixir/init.lua b/lua/elixir/init.lua index 1f12ceed..b619d1ff 100644 --- a/lua/elixir/init.lua +++ b/lua/elixir/init.lua @@ -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) @@ -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", diff --git a/lua/elixir/nextls/init.lua b/lua/elixir/nextls/init.lua index d91fdd24..ca3eb819 100644 --- a/lua/elixir/nextls/init.lua +++ b/lua/elixir/nextls/init.lua @@ -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", { @@ -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, }) diff --git a/lua/elixir/utils.lua b/lua/elixir/utils.lua index 6b38766d..5338a547 100644 --- a/lua/elixir/utils.lua +++ b/lua/elixir/utils.lua @@ -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 @@ -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, " ") .. "`" @@ -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"