Last active
January 20, 2024 20:24
-
-
Save linusdm/976dd5b9f6efdb452a3816086973b080 to your computer and use it in GitHub Desktop.
Execute "ManipulatePipes" command in LazyVim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Triggering these keymaps will transform code that uses the pipe operator to a regular call, and back again. | |
It's implemented by the command "manipulatePipes" that ElixirLS exposes through the executeCommand interface. | |
Add this code to a new or existing file under `lua/config/plugins` so it's picked up by LazyVim. | |
Change the triggering key combinations to your liking. | |
]]-- | |
local get_cursor_position = function() | |
local row, col = unpack(vim.api.nvim_win_get_cursor(0)) | |
-- vim.api.nvim_win_get_cursor() returns a (1,0)-indexed, buffer-relative cursor position for a given window | |
-- i.e. rows are 1-based, cols are 0-based | |
-- while the LSP expects a 0-based cursor position | |
return row - 1, col | |
end | |
local manipulate_pipes = function(direction) | |
return function() | |
local row, col = get_cursor_position() | |
vim.lsp.buf.execute_command({ | |
command = "manipulatePipes:serverid", | |
arguments = { direction, "file://" .. vim.api.nvim_buf_get_name(0), row, col }, | |
}) | |
end | |
end | |
return { | |
{ | |
"neovim/nvim-lspconfig", | |
opts = { | |
servers = { | |
elixirls = { | |
keys = { | |
{ "<leader>cp", manipulate_pipes("toPipe"), desc = "To Pipe" }, | |
{ "<leader>cP", manipulate_pipes("fromPipe"), desc = "From Pipe" }, | |
}, | |
}, | |
}, | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment