Skip to content

Commit 39a99e7

Browse files
committed
No longer depend on nvim-lspconfig
Revert "Revert "feat: no longer require nvim-lspconfig (#27)" (#30)" This reverts commit 67bb9a1. This reverts the #30, which is a revert of #27. We can merge this when `vim.fs` and `vim.lsp.start` make it into stable. Closes #5 Lose dependency on lspconfig
1 parent 67bb9a1 commit 39a99e7

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ jobs:
5454
}
5555
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
5656
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
57-
git clone --depth 1 https://github.com/neovim/nvim-lspconfig ~/.local/share/nvim/site/pack/vendor/start/nvim-lspconfig
5857
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
5958
6059
- name: Run tests

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Requires 0.7+.
1010

1111
```lua
12-
use({ "mhanberg/elixir.nvim", requires = { "neovim/nvim-lspconfig", "nvim-lua/plenary.nvim" }})
12+
use({ "mhanberg/elixir.nvim", requires = { "nvim-lua/plenary.nvim" }})
1313
```
1414

1515
## Getting Started
@@ -31,7 +31,7 @@ elixir.setup({
3131
-- specify a repository and branch
3232
repo = "mhanberg/elixir-ls", -- defaults to elixir-lsp/elixir-ls
3333
branch = "mh/all-workspace-symbols", -- defaults to nil, just checkouts out the default branch, mutually exclusive with the `tag` option
34-
tag = "v0.9.0", -- defaults to nil, mutually exclusive with the `branch` option
34+
tag = "v0.10.0", -- defaults to nil, mutually exclusive with the `branch` option
3535

3636
-- default settings, use the `settings` function to override settings
3737
settings = elixir.settings({

lua/elixir/init.lua

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
local uv = vim.loop
22

3-
local lspconfig = require("lspconfig")
4-
local lsputil = require("lspconfig.util")
5-
63
local Job = require("plenary.job")
74
local Path = require("plenary.path")
85
local popup = require("plenary.popup")
@@ -12,7 +9,6 @@ local Download = require("elixir.download")
129
local Compile = require("elixir.compile")
1310
local Utils = require("elixir.utils")
1411

15-
local default_config = require("lspconfig.server_configurations.elixirls").default_config
1612
local capabilities = vim.lsp.protocol.make_client_capabilities()
1713
capabilities.textDocument.completion.completionItem.snippetSupport = true
1814

@@ -157,15 +153,14 @@ local function test(command)
157153
end
158154

159155
local root_dir = function(fname)
160-
local path = lsputil.path
161-
local child_or_root_path = lsputil.root_pattern({ "mix.exs", ".git" })(fname)
162-
local maybe_umbrella_path = lsputil.root_pattern({ "mix.exs" })(
163-
uv.fs_realpath(path.join({ child_or_root_path, ".." }))
164-
)
156+
local child_or_root_path = vim.fs.dirname(vim.fs.find({ "mix.exs", ".git" }, { upward = true, path = fname })[1])
157+
local maybe_umbrella_path =
158+
vim.fs.dirname(vim.fs.find({ "mix.exs" }, { upward = true, path = child_or_root_path })[1])
165159

166-
local has_ancestral_mix_exs_path = vim.startswith(child_or_root_path, path.join({ maybe_umbrella_path, "apps" }))
167-
if maybe_umbrella_path and not has_ancestral_mix_exs_path then
168-
maybe_umbrella_path = nil
160+
if maybe_umbrella_path then
161+
if not vim.startswith(child_or_root_path, Path:joinpath(maybe_umbrella_path, "apps"):absolute()) then
162+
maybe_umbrella_path = nil
163+
end
169164
end
170165

171166
local path = maybe_umbrella_path or child_or_root_path or vim.loop.os_homedir()
@@ -185,13 +180,8 @@ M.settings = function(opts)
185180
end
186181

187182
function M.command(params)
188-
local install_path = Path:new(
189-
params.path,
190-
params.repo,
191-
Utils.safe_path(params.ref),
192-
params.versions,
193-
"language_server.sh"
194-
)
183+
local install_path =
184+
Path:new(params.path, params.repo, Utils.safe_path(params.ref), params.versions, "language_server.sh")
195185

196186
return install_path
197187
end
@@ -247,40 +237,55 @@ end
247237

248238
function M.setup(opts)
249239
opts = opts or {}
250-
lspconfig.elixirls.setup(vim.tbl_extend("keep", {
251-
on_init = lsputil.add_hook_after(default_config.on_init, function(client)
252-
client.commands["elixir.lens.test.run"] = test
253-
end),
254-
on_new_config = function(new_config, new_root_dir)
255-
new_opts = make_opts(opts)
256-
257-
local cmd = M.command({
258-
path = tostring(install_dir),
259-
repo = new_opts.repo,
260-
ref = new_opts.ref,
261-
versions = Version.get(),
262-
})
263-
264-
if not cmd:exists() then
265-
vim.ui.select({ "Yes", "No" }, { prompt = "Install ElixirLS" }, function(choice)
266-
if choice == "Yes" then
267-
install_elixir_ls(vim.tbl_extend("force", new_opts, { install_path = cmd:parent() }))
240+
local elixir_group = vim.api.nvim_create_augroup("elixirnvim", { clear = true })
241+
242+
local start_elixir_ls = function(arg)
243+
fname = Path.new(arg.file):absolute()
244+
245+
local root_dir = opts.root_dir and opts.root_dir(fname) or root_dir(fname)
246+
local new_opts = make_opts(opts)
247+
248+
local cmd = M.command({
249+
path = tostring(install_dir),
250+
repo = new_opts.repo,
251+
ref = new_opts.ref,
252+
versions = Version.get(),
253+
})
254+
255+
if not cmd:exists() then
256+
vim.ui.select({ "Yes", "No" }, { prompt = "Install ElixirLS" }, function(choice)
257+
if choice == "Yes" then
258+
install_elixir_ls(vim.tbl_extend("force", new_opts, { install_path = cmd:parent() }))
259+
end
260+
end)
261+
262+
return
263+
elseif root_dir then
264+
vim.lsp.start(vim.tbl_extend("keep", {
265+
name = "ElixirLS",
266+
cmd = { tostring(cmd) },
267+
commands = {
268+
["elixir.lens.test.run"] = test,
269+
},
270+
settings = opts.settings or settings,
271+
capabilities = opts.capabilities or capabilities,
272+
root_dir = root_dir,
273+
on_attach = function(...)
274+
if opts.on_attach then
275+
opts.on_attach(...)
268276
end
269-
end)
270277

271-
return
272-
else
273-
local updated_config = new_config
274-
updated_config.cmd = { tostring(cmd) }
278+
M.on_attach(...)
279+
end,
280+
}, opts))
281+
end
282+
end
275283

276-
return updated_config
277-
end
278-
end,
279-
settings = opts.settings or settings,
280-
capabilities = opts.capabilities or capabilities,
281-
root_dir = opts.root_dir or root_dir,
282-
on_attach = lsputil.add_hook_before(opts.on_attach, M.on_attach),
283-
}, opts))
284+
vim.api.nvim_create_autocmd({ "FileType" }, {
285+
group = elixir_group,
286+
pattern = { "elixir" },
287+
callback = start_elixir_ls,
288+
})
284289
end
285290

286291
return M

0 commit comments

Comments
 (0)