Skip to content

Commit 2ee9274

Browse files
authored
feat: add alias-refactor command (#206)
1 parent 4d003f4 commit 2ee9274

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,12 @@ elixir.setup {
166166
```
167167
### Full List
168168

169-
| Command | Subcommand | Description |
170-
|---------|------------|------------------------------------------------------------------------------------------------------|
171-
| nextls | uninstall | Removes the `nextls` executable from the default location: `~/.cache/elixir-tools/nextls/bin/nextls` |
172-
| nextls | to-pipe | Extracts the first argument to a pipe call |
173-
| nextls | from-pipe | Inlines the pipe call to a function call the first argument to a pipe |
169+
| Command | Subcommand | Description |
170+
|---------|----------------|------------------------------------------------------------------------------------------------------|
171+
| nextls | alias-refactor | Aliases the module under the cursor, refactoring similar calls as well |
172+
| nextls | to-pipe | Extracts the first argument to a pipe call |
173+
| nextls | from-pipe | Inlines the pipe call to a function call inlining the first argument |
174+
| nextls | uninstall | Removes the `nextls` executable from the default location: `~/.cache/elixir-tools/nextls/bin/nextls` |
174175

175176
## Next LS
176177

lua/elixir/init.lua

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ local define_user_command = function()
3939
local args = vim.iter(opts.fargs)
4040
local command = args:next()
4141
local not_found = false
42+
local workspace_commands = {
43+
["to-pipe"] = true,
44+
["from-pipe"] = true,
45+
["alias-refactor"] = true,
46+
}
4247

4348
if "nextls" == command then
4449
local subcommand = args:next()
@@ -48,18 +53,11 @@ local define_user_command = function()
4853
string.format("[elixir-tools] Uninstalled Next LS from %s", nextls.default_bin),
4954
vim.lsp.log_levels.INFO
5055
)
51-
elseif "to-pipe" == subcommand then
56+
elseif workspace_commands[subcommand] then
5257
local row, col = get_cursor_position()
5358
local uri = vim.uri_from_bufnr(0)
5459
vim.lsp.buf.execute_command {
55-
command = "to-pipe",
56-
arguments = { { position = { line = row, character = col }, uri = uri } },
57-
}
58-
elseif "from-pipe" == subcommand then
59-
local row, col = get_cursor_position()
60-
local uri = vim.uri_from_bufnr(0)
61-
vim.lsp.buf.execute_command {
62-
command = "from-pipe",
60+
command = subcommand,
6361
arguments = { { position = { line = row, character = col }, uri = uri } },
6462
}
6563
else
@@ -77,7 +75,7 @@ local define_user_command = function()
7775
complete = function(_, cmd_line)
7876
local cmd = vim.trim(cmd_line)
7977
if vim.startswith(cmd, "Elixir nextls") then
80-
return { "uninstall", "to-pipe", "from-pipe" }
78+
return { "alias-refactor", "to-pipe", "from-pipe", "uninstall" }
8179
elseif vim.startswith(cmd, "Elixir") then
8280
return { "nextls" }
8381
end

0 commit comments

Comments
 (0)