Skip to content

Commit 7753936

Browse files
committed
Allowing extension point for lsp specific actions
1 parent 6acc304 commit 7753936

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ elixir.setup {
138138
-- not currently supported by elixirls, but can be a table if you wish to pass other args `{"path/to/elixirls", "--foo"}`
139139
cmd = "/usr/local/bin/elixir-ls.sh",
140140

141+
-- extension point to link in to server specific commands
142+
-- by default, the codelens action below runs a default test runner in a terminal buffer
143+
-- replacing it as shown here will override default behavior, allow running a custom function instead
144+
-- `args` are anything the lsp command passes back to the callback function
145+
commands = {
146+
["elixir.lens.test.run"] = function(args)
147+
-- custom functionality here as needed
148+
end
149+
},
150+
141151
-- default settings, use the `settings` function to override settings
142152
settings = elixirls.settings {
143153
dialyzerEnabled = true,

lua/elixir/elixirls/init.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ end
164164

165165
function M.command(params)
166166
local install_path =
167-
Path:new(params.path, params.repo, Utils.safe_path(params.ref), params.versions, "language_server.sh")
167+
Path:new(params.path, params.repo, Utils.safe_path(params.ref), params.versions, "language_server.sh")
168168

169169
return install_path
170170
end
@@ -260,7 +260,7 @@ local function repo_opts(opts)
260260
else
261261
if opts.repo then -- if we specified a repo in our conifg, then let's default to HEAD
262262
ref = "HEAD"
263-
else -- else, let's checkout the latest stable release
263+
else -- else, let's checkout the latest stable release
264264
ref = default_install_tag
265265
end
266266
end
@@ -318,12 +318,15 @@ function M.setup(opts)
318318

319319
if root_dir then
320320
local log_message = vim.lsp.handlers["window/logMessage"]
321+
322+
local commands = vim.tbl_extend('force', {
323+
["elixir.lens.test.run"] = test,
324+
}, opts.commands or {})
325+
321326
vim.lsp.start(vim.tbl_extend("keep", {
322327
name = "ElixirLS",
323328
cmd = opts.cmd and wrap_in_table(opts.cmd) or { tostring(cmd) },
324-
commands = {
325-
["elixir.lens.test.run"] = test,
326-
},
329+
commands = commands,
327330
settings = opts.settings or M.settings {},
328331
capabilities = opts.capabilities or capabilities,
329332
root_dir = root_dir,
@@ -332,7 +335,7 @@ function M.setup(opts)
332335
log_message(err, result, ...)
333336

334337
local message =
335-
vim.split("[" .. vim.lsp.protocol.MessageType[result.type] .. "] " .. result.message, "\n")
338+
vim.split("[" .. vim.lsp.protocol.MessageType[result.type] .. "] " .. result.message, "\n")
336339

337340
pcall(vim.api.nvim_buf_set_lines, elixir_nvim_output_bufnr, -1, -1, false, message)
338341
end,

0 commit comments

Comments
 (0)