Skip to content

Commit a28a922

Browse files
committed
Add pipe subcommands
1 parent 83d3b79 commit a28a922

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ elixir.setup {
169169
| Command | Subcommand | Description |
170170
|---------|------------|------------------------------------------------------------------------------------------------------|
171171
| 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 |
172174

173175
## Next LS
174176

lua/elixir/init.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ local enabled = function(value)
2626
return value == nil or value == true
2727
end
2828

29+
local get_cursor_position = function()
30+
local rowcol = vim.api.nvim_win_get_cursor(0)
31+
local row = rowcol[1] - 1
32+
local col = rowcol[2]
33+
34+
return row, col
35+
end
36+
2937
local define_user_command = function()
3038
vim.api.nvim_create_user_command("Elixir", function(opts)
3139
local args = vim.iter(opts.fargs)
@@ -37,6 +45,14 @@ local define_user_command = function()
3745
if "uninstall" == subcommand then
3846
vim.fn.delete(nextls.default_bin)
3947
vim.notify(string.format("Uninstalled Next LS from %s", nextls.default_bin), vim.lsp.log_levels.INFO)
48+
elseif "to-pipe" == subcommand then
49+
local row, col = get_cursor_position()
50+
local uri = vim.uri_from_bufnr(0)
51+
vim.lsp.buf.execute_command { command = "to-pipe", arguments = {{position = {line = row, character = col}, uri = uri}} }
52+
elseif "from-pipe" == subcommand then
53+
local row, col = get_cursor_position()
54+
local uri = vim.uri_from_bufnr(0)
55+
vim.lsp.buf.execute_command { command = "from-pipe", arguments = {{position = {line = row, character = col}, uri = uri}} }
4056
else
4157
not_found = true
4258
end
@@ -52,7 +68,7 @@ local define_user_command = function()
5268
complete = function(_, cmd_line)
5369
local cmd = vim.trim(cmd_line)
5470
if vim.startswith(cmd, "Elixir nextls") then
55-
return { "uninstall" }
71+
return { "uninstall", "to-pipe", "from-pipe" }
5672
elseif vim.startswith(cmd, "Elixir") then
5773
return { "nextls" }
5874
end

0 commit comments

Comments
 (0)