From 4df8785330477d06d5f812d21a4d98e0361ae48d Mon Sep 17 00:00:00 2001 From: Adam Olsen Date: Sun, 29 Dec 2024 04:14:23 -0700 Subject: [PATCH] feat: update to refactorex 0.1.29 The [stdio PR](https://github.com/gp-pereira/refactorex/pull/19) has been accepted and merged for 0.1.29, so the now unnecessary patch code has been removed. --- lua/refactorex.lua | 131 +++++++------------------------------ patches/stdio-0.1.28.patch | 53 --------------- refactorex-version.txt | 2 +- 3 files changed, 24 insertions(+), 162 deletions(-) delete mode 100644 patches/stdio-0.1.28.patch diff --git a/lua/refactorex.lua b/lua/refactorex.lua index ba8b06a..f629f85 100644 --- a/lua/refactorex.lua +++ b/lua/refactorex.lua @@ -8,6 +8,10 @@ local refactorex_version = vim.fn.readfile(vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h:h") .. "/refactorex-version.txt")[1] local github_url = "https://github.com/gp-pereira/refactorex" +local install_dir = Path:new(vim.fn.stdpath("data")):joinpath("refactorex") +local install_path = Path:new(install_dir):joinpath("refactorex-" .. refactorex_version) +local start_script = install_path:joinpath("bin/start") + local M = { config = { filetypes = { "elixir" }, @@ -23,64 +27,8 @@ local M = { pending_server_starts = {}, } -local function get_install_dir() - return Path:new(vim.fn.stdpath("data")):joinpath("refactorex") -end - -local function apply_stdio_patch(install_path, callback) - local patch_source = Path:new(vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h")) - :joinpath("../patches/stdio-0.1.28.patch") - - if not patch_source:exists() then - if callback then - callback(false) - end - return - end - - ---@diagnostic disable-next-line: missing-fields - Job:new({ - command = "patch", - args = { "-p1", "-d", install_path:absolute() }, - writer = patch_source:read(), - on_exit = function(j, return_val) - if return_val == 0 and j:result()[1]:match("patching file") then - local start_stdio_script = install_path:joinpath("bin/start-stdio") - if start_stdio_script:exists() then - ---@diagnostic disable-next-line: missing-fields - Job:new({ - command = "chmod", - args = { "+x", start_stdio_script:absolute() }, - on_exit = function(_, retval) - if retval ~= 0 then - vim.notify( - "RefactorEx: Failed to make start-stdio script executable", - vim.log.levels.ERROR - ) - end - if callback then - callback(retval == 0) - end - end, - }):start() - else - vim.notify("RefactorEx: start-stdio script not found", vim.log.levels.ERROR) - if callback then - callback(false) - end - end - else - vim.notify("RefactorEx: Failed to apply stdio patch", vim.log.levels.ERROR) - if callback then - callback(false) - end - end - end, - }):start() -end - local function check_dependencies() - local required_commands = { "nc", "curl", "tar", "mix", "patch", "chmod" } + local required_commands = { "nc", "curl", "tar", "mix" } for _, cmd in ipairs(required_commands) do if vim.fn.executable(cmd) ~= 1 then error(string.format("Required command '%s' not found in PATH", cmd)) @@ -124,7 +72,7 @@ local function setup_server_config(opts) end local function download_refactorex(tar_file, callback) - vim.notify("RefactorEx: downloading and installing release source...", vim.log.levels.INFO) + vim.notify("RefactorEx: downloading and installing updated release source...", vim.log.levels.INFO) ---@diagnostic disable-next-line: missing-fields Job:new({ @@ -148,7 +96,7 @@ local function download_refactorex(tar_file, callback) }):start() end -local function extract_tarball(tar_file, install_dir, callback) +local function extract_tarball(tar_file, callback) ---@diagnostic disable-next-line: missing-fields Job:new({ command = "tar", @@ -165,7 +113,7 @@ local function extract_tarball(tar_file, install_dir, callback) }):start() end -local function install_mix_dependencies(install_path, callback) +local function install_mix_dependencies(callback) ---@diagnostic disable-next-line: missing-fields Job:new({ command = "mix", @@ -182,7 +130,7 @@ local function install_mix_dependencies(install_path, callback) }):start() end -local function compile_refactorex(install_path, callback) +local function compile_refactorex(callback) ---@diagnostic disable-next-line: missing-fields Job:new({ command = "mix", @@ -202,7 +150,6 @@ local function compile_refactorex(install_path, callback) end function M.ensure_refactorex(callback, force_reinstall) - local install_dir = get_install_dir() local tar_file = install_dir:joinpath(string.format("refactorex-%s.tar.gz", refactorex_version)) local refactorex_path = install_dir:joinpath(string.format("refactorex-%s", refactorex_version)) @@ -232,23 +179,16 @@ function M.ensure_refactorex(callback, force_reinstall) M.installing = true download_refactorex(tar_file, function() - extract_tarball(tar_file, install_dir, function() - local install_path = install_dir:joinpath(string.format("refactorex-%s", refactorex_version)) - install_mix_dependencies(install_path, function() - apply_stdio_patch(install_path, function(success) - if not success then - M.installing = false - return + extract_tarball(tar_file, function() + install_mix_dependencies(function() + compile_refactorex(function() + if callback then + callback() end - compile_refactorex(install_path, function() - if callback then - callback() - end - for _, pending_callback in ipairs(M.pending_server_starts) do - pending_callback() - end - M.pending_server_starts = {} - end) + for _, pending_callback in ipairs(M.pending_server_starts) do + pending_callback() + end + M.pending_server_starts = {} end) end) end) @@ -263,22 +203,17 @@ local function create_commands() }) vim.api.nvim_create_user_command("RefactorExPatch", function() - local install_dir = get_install_dir() - local install_path = install_dir:joinpath(string.format("refactorex-%s", refactorex_version)) - if not install_path:exists() then vim.notify("RefactorEx installation not found", vim.log.levels.ERROR) return end - - apply_stdio_patch(install_path) end, { desc = "Apply stdio patch to existing RefactorEx installation", }) end -local function start_lsp_server(opts, start_stdio_script) - opts.cmd = { start_stdio_script:absolute() } +local function start_lsp_server(opts) + opts.cmd = { start_script:absolute(), "--stdio" } setup_server_config(opts) vim.schedule(function() @@ -303,32 +238,12 @@ function M.setup(opts) pattern = "elixir", callback = function() if not server_started then - local install_path = Path:new(get_install_dir()):joinpath("refactorex-" .. refactorex_version) - local start_stdio_script = install_path:joinpath("bin/start-stdio") - local start_script = install_path:joinpath("bin/start") - - if start_stdio_script:exists() then - start_lsp_server(opts, start_stdio_script) - elseif start_script:exists() then - -- this is only required for the 0.1.28 version that may have already been installed for some neovim users - - -- I switched from tcp transport to patching refactorex to use the stdio transport, however, some people may - -- already have 0.1.28 downloaded and installed. If `bin/start-stdio` doesn't exist, then it means that the - -- source hasn't been patched and it needs to be done. - -- - -- When there's a new version of refactorex, this can be removed, because patching will be done as a part of - -- the new version installation process (or, possibly might not be needed at all, see: - -- https://github.com/gp-pereira/refactorex/pull/19) - apply_stdio_patch(install_path, function(success) - if success then - start_lsp_server(opts, start_stdio_script) - else - vim.notify("RefactorEx: Failed to apply stdio patch", vim.log.levels.ERROR) - end - end) + if start_script:exists() then + start_lsp_server(opts) else M.ensure_refactorex(function() vim.notify("RefactorEx: installed successfully, starting server...", vim.log.levels.INFO) - start_lsp_server(opts, start_stdio_script) + start_lsp_server(opts) end) end diff --git a/patches/stdio-0.1.28.patch b/patches/stdio-0.1.28.patch deleted file mode 100644 index 7bdec76..0000000 --- a/patches/stdio-0.1.28.patch +++ /dev/null @@ -1,53 +0,0 @@ -diff --git c/bin/start-stdio w/bin/start-stdio -new file mode 100755 -index 0000000..7f95ae1 ---- /dev/null -+++ w/bin/start-stdio -@@ -0,0 +1,7 @@ -+#!/usr/bin/env bash -+ -+# used for mason.nvim -+ -+cd "$(dirname "$0")"/.. || exit 1 -+ -+./bin/start --stdio "$0" -diff --git c/lib/refactorex/application.ex w/lib/refactorex/application.ex -index b726e4b..76d4f12 100644 ---- c/lib/refactorex/application.ex -+++ w/lib/refactorex/application.ex -@@ -9,7 +9,7 @@ defmodule Refactorex.Application do - [ - { - GenLSP.Buffer, -- [communication: {GenLSP.Communication.TCP, [port: port()]}] -+ [communication: communication_config()] - }, - {Refactorex.Logger, []}, - {Refactorex.NameCache, []}, -@@ -20,10 +20,24 @@ defmodule Refactorex.Application do - ) - end - -- defp port do -+ defp parse_opts do - System.argv() -- |> OptionParser.parse(strict: [port: :integer]) -+ |> OptionParser.parse(strict: [port: :integer, stdio: :boolean]) - |> elem(0) -+ end -+ -+ defp port do -+ parse_opts() - |> Keyword.get(:port, @default_port) - end -+ -+ defp communication_config do -+ opts = parse_opts() -+ -+ if Keyword.get(opts, :stdio, false) do -+ {GenLSP.Communication.Stdio, []} -+ else -+ {GenLSP.Communication.TCP, [port: port()]} -+ end -+ end - end diff --git a/refactorex-version.txt b/refactorex-version.txt index baec65a..5ef49d2 100644 --- a/refactorex-version.txt +++ b/refactorex-version.txt @@ -1 +1 @@ -0.1.28 +0.1.29