Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add refactor alias command #206

Merged
merged 6 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
mhanberg marked this conversation as resolved.
Show resolved Hide resolved
| 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
Loading