Skip to content

Commit 451925e

Browse files
committed
feat: :Elixir command with subcommands and completions
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 451925e

3 files changed

Lines changed: 71 additions & 8 deletions

File tree

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 & 0 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,52 @@ 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(
40+
string.format("Uninstalled Next LS from %s", nextls.default_bin),
41+
vim.lsp.log_levels.INFO
42+
)
43+
else
44+
not_found = true
45+
end
46+
else
47+
not_found = true
48+
end
49+
if not_found then
50+
vim.notify("elixir-tools: unknown command: " .. opts.name .. " " .. opts.args, vim.lsp.log_levels.WARN)
51+
end
52+
end, {
53+
desc = "elixir-tools main command",
54+
nargs = "+",
55+
complete = function(_, cmd_line)
56+
local cmd = vim.trim(cmd_line)
57+
if vim.startswith(cmd, "Elixir nextls") then
58+
return { "uninstall" }
59+
elseif vim.startswith(cmd, "Elixir") then
60+
return { "nextls" }
61+
end
62+
end,
63+
})
64+
end
65+
2566
function M.setup(opts)
2667
opts = opts or {}
2768

2869
opts.elixirls = opts.elixirls or {}
2970
opts.credo = opts.credo or {}
3071
opts.nextls = opts.nextls or {}
3172

73+
define_user_command()
74+
3275
if not opts.credo.cmd then
3376
opts.credo.cmd = M.credo.default_bin
3477
end

lua/elixir/nextls/init.lua

Lines changed: 0 additions & 4 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)

0 commit comments

Comments
 (0)