From 775393680b3f404f30f492883d7eac33fb15a634 Mon Sep 17 00:00:00 2001 From: Nik FP Date: Mon, 13 Oct 2025 12:47:22 -0600 Subject: [PATCH 1/2] Allowing extension point for lsp specific actions --- README.md | 10 ++++++++++ lua/elixir/elixirls/init.lua | 15 +++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9e298ab7..e8da172f 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,16 @@ elixir.setup { -- not currently supported by elixirls, but can be a table if you wish to pass other args `{"path/to/elixirls", "--foo"}` cmd = "/usr/local/bin/elixir-ls.sh", + -- extension point to link in to server specific commands + -- by default, the codelens action below runs a default test runner in a terminal buffer + -- replacing it as shown here will override default behavior, allow running a custom function instead + -- `args` are anything the lsp command passes back to the callback function + commands = { + ["elixir.lens.test.run"] = function(args) + -- custom functionality here as needed + end + }, + -- default settings, use the `settings` function to override settings settings = elixirls.settings { dialyzerEnabled = true, diff --git a/lua/elixir/elixirls/init.lua b/lua/elixir/elixirls/init.lua index 814320b4..9b40630e 100644 --- a/lua/elixir/elixirls/init.lua +++ b/lua/elixir/elixirls/init.lua @@ -164,7 +164,7 @@ end function M.command(params) local install_path = - Path:new(params.path, params.repo, Utils.safe_path(params.ref), params.versions, "language_server.sh") + Path:new(params.path, params.repo, Utils.safe_path(params.ref), params.versions, "language_server.sh") return install_path end @@ -260,7 +260,7 @@ local function repo_opts(opts) else if opts.repo then -- if we specified a repo in our conifg, then let's default to HEAD ref = "HEAD" - else -- else, let's checkout the latest stable release + else -- else, let's checkout the latest stable release ref = default_install_tag end end @@ -318,12 +318,15 @@ function M.setup(opts) if root_dir then local log_message = vim.lsp.handlers["window/logMessage"] + + local commands = vim.tbl_extend('force', { + ["elixir.lens.test.run"] = test, + }, opts.commands or {}) + vim.lsp.start(vim.tbl_extend("keep", { name = "ElixirLS", cmd = opts.cmd and wrap_in_table(opts.cmd) or { tostring(cmd) }, - commands = { - ["elixir.lens.test.run"] = test, - }, + commands = commands, settings = opts.settings or M.settings {}, capabilities = opts.capabilities or capabilities, root_dir = root_dir, @@ -332,7 +335,7 @@ function M.setup(opts) log_message(err, result, ...) local message = - vim.split("[" .. vim.lsp.protocol.MessageType[result.type] .. "] " .. result.message, "\n") + vim.split("[" .. vim.lsp.protocol.MessageType[result.type] .. "] " .. result.message, "\n") pcall(vim.api.nvim_buf_set_lines, elixir_nvim_output_bufnr, -1, -1, false, message) end, From 04a9b67567113de6b8e4e060e3bed3d23c8fc5ae Mon Sep 17 00:00:00 2001 From: Nik FP Date: Tue, 14 Oct 2025 09:36:07 -0600 Subject: [PATCH 2/2] Ran stylua to fix formatting issues --- lua/elixir/elixirls/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/elixir/elixirls/init.lua b/lua/elixir/elixirls/init.lua index 9b40630e..8fbe7255 100644 --- a/lua/elixir/elixirls/init.lua +++ b/lua/elixir/elixirls/init.lua @@ -164,7 +164,7 @@ end function M.command(params) local install_path = - Path:new(params.path, params.repo, Utils.safe_path(params.ref), params.versions, "language_server.sh") + Path:new(params.path, params.repo, Utils.safe_path(params.ref), params.versions, "language_server.sh") return install_path end @@ -260,7 +260,7 @@ local function repo_opts(opts) else if opts.repo then -- if we specified a repo in our conifg, then let's default to HEAD ref = "HEAD" - else -- else, let's checkout the latest stable release + else -- else, let's checkout the latest stable release ref = default_install_tag end end @@ -319,7 +319,7 @@ function M.setup(opts) if root_dir then local log_message = vim.lsp.handlers["window/logMessage"] - local commands = vim.tbl_extend('force', { + local commands = vim.tbl_extend("force", { ["elixir.lens.test.run"] = test, }, opts.commands or {}) @@ -335,7 +335,7 @@ function M.setup(opts) log_message(err, result, ...) local message = - vim.split("[" .. vim.lsp.protocol.MessageType[result.type] .. "] " .. result.message, "\n") + vim.split("[" .. vim.lsp.protocol.MessageType[result.type] .. "] " .. result.message, "\n") pcall(vim.api.nvim_buf_set_lines, elixir_nvim_output_bufnr, -1, -1, false, message) end,