Skip to content

Commit

Permalink
feat: add alias-refactor command (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
NJichev authored Apr 20, 2024
1 parent 4d003f4 commit 2ee9274
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ elixir.setup {
```
### Full List

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

## Next LS

Expand Down
18 changes: 8 additions & 10 deletions lua/elixir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ local define_user_command = function()
local args = vim.iter(opts.fargs)
local command = args:next()
local not_found = false
local workspace_commands = {
["to-pipe"] = true,
["from-pipe"] = true,
["alias-refactor"] = true,
}

if "nextls" == command then
local subcommand = args:next()
Expand All @@ -48,18 +53,11 @@ local define_user_command = function()
string.format("[elixir-tools] Uninstalled Next LS from %s", nextls.default_bin),
vim.lsp.log_levels.INFO
)
elseif "to-pipe" == subcommand then
elseif workspace_commands[subcommand] then
local row, col = get_cursor_position()
local uri = vim.uri_from_bufnr(0)
vim.lsp.buf.execute_command {
command = "to-pipe",
arguments = { { position = { line = row, character = col }, uri = uri } },
}
elseif "from-pipe" == subcommand then
local row, col = get_cursor_position()
local uri = vim.uri_from_bufnr(0)
vim.lsp.buf.execute_command {
command = "from-pipe",
command = subcommand,
arguments = { { position = { line = row, character = col }, uri = uri } },
}
else
Expand All @@ -77,7 +75,7 @@ local define_user_command = function()
complete = function(_, cmd_line)
local cmd = vim.trim(cmd_line)
if vim.startswith(cmd, "Elixir nextls") then
return { "uninstall", "to-pipe", "from-pipe" }
return { "alias-refactor", "to-pipe", "from-pipe", "uninstall" }
elseif vim.startswith(cmd, "Elixir") then
return { "nextls" }
end
Expand Down

0 comments on commit 2ee9274

Please sign in to comment.