Skip to content

Commit c4e1db5

Browse files
authored
feat: :Elixir command with subcommands and completions (#160)
Closes #141 Doesn't fully fix it, but starts it and I don't think I'll migrate the ElixirLS ones to it.
1 parent 24ca12a commit c4e1db5

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,45 @@ elixir.setup {
147147

148148
# Features
149149

150+
## Commands
151+
152+
:Elixir {command} [{subcommand}]
153+
154+
: The main elixir-tools command
155+
156+
```vim
157+
:Elixir nextls uninstall
158+
```
159+
### Full List
160+
161+
| Command | Subcommand | Description |
162+
|---------|------------|------------------------------------------------------------------------------------------------------|
163+
| nextls | uninstall | Removes the `nextls` executable from the default location: `~/.cache/elixir-tools/nextls/bin/nextls` |
164+
150165
## Next LS
151166

152167
> **Note**
153168
> Next LS is **disabled** by default. Once it reaches feature parity with ElixirLS, it will switch to enabled by default.
154169
155170
> **Note**
156-
> Next LS integration utilizes `Mix.install/2`, so you must be running Elixir >= 1.12
157-
158-
> **Note**
159-
> Next LS creates a `.elixir-tools` directory in your project root. You'll want to add that to your gitignore.
171+
> Next LS creates a `.elixir-tools` directory in your project root, but it's automatically ignored by git.
160172
161173
The language server for Elixir that just works. 😎
162174

163175
You can read more about it at https://www.elixir-tools.dev/next-ls.
164176

177+
### Automatic Installation
178+
179+
Next LS is distributed as pre-compiled binaries, which are available from the Next LS GitHub releases page. elixir-tools.nvim will prompt you to install it if it is not found, and then
180+
will consequently download it from GitHub.
181+
182+
If you are using a package manager like [Mason](https://github.com/williamboman/mason.nvim), you can set the `cmd` property of the `nextls` setup table
183+
and it will not prompt you to install and use it from there.
184+
185+
### Commands
186+
187+
Next LS command are available as subcommands of the `:Elixir` command
188+
165189
## Credo Language Server
166190

167191
> **Note**

lua/elixir/init.lua

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if not vim.iter then
2+
vim.iter = require("elixir.iter")
3+
end
4+
15
local elixirls = require("elixir.elixirls")
26
local credo = require("elixir.credo")
37
local nextls = require("elixir.nextls")
@@ -22,13 +26,49 @@ local enabled = function(value)
2226
return value == nil or value == true
2327
end
2428

29+
local define_user_command = function()
30+
vim.api.nvim_create_user_command("Elixir", function(opts)
31+
local args = vim.iter(opts.fargs)
32+
local command = args:next()
33+
local not_found = false
34+
35+
if "nextls" == command then
36+
local subcommand = args:next()
37+
if "uninstall" == subcommand then
38+
vim.fn.delete(nextls.default_bin)
39+
vim.notify(string.format("Uninstalled Next LS from %s", nextls.default_bin), vim.lsp.log_levels.INFO)
40+
else
41+
not_found = true
42+
end
43+
else
44+
not_found = true
45+
end
46+
if not_found then
47+
vim.notify("elixir-tools: unknown command: " .. opts.name .. " " .. opts.args, vim.lsp.log_levels.WARN)
48+
end
49+
end, {
50+
desc = "elixir-tools main command",
51+
nargs = "+",
52+
complete = function(_, cmd_line)
53+
local cmd = vim.trim(cmd_line)
54+
if vim.startswith(cmd, "Elixir nextls") then
55+
return { "uninstall" }
56+
elseif vim.startswith(cmd, "Elixir") then
57+
return { "nextls" }
58+
end
59+
end,
60+
})
61+
end
62+
2563
function M.setup(opts)
2664
opts = opts or {}
2765

2866
opts.elixirls = opts.elixirls or {}
2967
opts.credo = opts.credo or {}
3068
opts.nextls = opts.nextls or {}
3169

70+
define_user_command()
71+
3272
if not opts.credo.cmd then
3373
opts.credo.cmd = M.credo.default_bin
3474
end
@@ -37,14 +77,12 @@ function M.setup(opts)
3777
opts.credo.version = utils.latest_release("elixir-tools", "credo-language-server")
3878
end
3979

80+
local nextls_auto_update
4081
if not opts.nextls.cmd then
4182
opts.nextls.cmd = nextls.default_bin
83+
nextls_auto_update = true
4284
end
4385

44-
-- if opts.nextls.enable and not opts.nextls.version then
45-
-- opts.nextls.version = utils.latest_release("elixir-tools", "next-ls")
46-
-- end
47-
4886
mix.setup()
4987
projectionist.setup()
5088
if enabled(opts.elixirls.enable) then
@@ -56,7 +94,7 @@ function M.setup(opts)
5694
end
5795

5896
if opts.nextls.enable == true then
59-
nextls.setup(opts.nextls)
97+
nextls.setup(vim.tbl_extend("force", opts.nextls, { auto_update = nextls_auto_update }))
6098
end
6199
end
62100

lua/elixir/nextls/init.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ if not vim.uv then
55
vim.uv = vim.loop
66
end
77

8-
if not vim.iter then
9-
vim.iter = require("elixir.iter")
10-
end
11-
128
M.default_bin = vim.env.HOME .. "/.cache/elixir-tools/nextls/bin/nextls"
139

1410
function M.setup(opts)
@@ -19,14 +15,15 @@ function M.setup(opts)
1915
group = nextls_group,
2016
callback = function(event)
2117
local cmd = event.data.cmd
18+
local auto_update = event.auto_update
2219
local options = event.data.opts
2320
local root_dir = event.data.root_dir
2421
vim.lsp.start({
2522
name = "NextLS",
2623
cmd = cmd,
2724
cmd_env = {
2825
NEXTLS_VERSION = options.version,
29-
NEXTLS_AUTO_UPDATE = true,
26+
NEXTLS_AUTO_UPDATE = auto_update,
3027
},
3128
settings = {},
3229
capabilities = options.capabilities or vim.lsp.protocol.make_client_capabilities(),
@@ -76,6 +73,7 @@ function M.setup(opts)
7673
data = {
7774
root_dir = root_dir,
7875
cmd = cmd,
76+
auto_update = opts.auto_update,
7977
opts = opts,
8078
},
8179
})

0 commit comments

Comments
 (0)