add lsp rename popup window
thx to @LeonHeidelbach for fixing some outdated stuff in the original table : https://www.reddit.com/r/neovim/comments/ql4iuj/rename_hover_including_window_title_and/
This commit is contained in:
parent
f78dc30508
commit
d802e8e2a6
2 changed files with 58 additions and 1 deletions
|
@ -147,7 +147,7 @@ M.lspconfig = {
|
|||
|
||||
["<leader>ra"] = {
|
||||
function()
|
||||
vim.lsp.buf.rename()
|
||||
vim.lsp.buf.rename.float()
|
||||
end,
|
||||
" lsp rename",
|
||||
},
|
||||
|
|
|
@ -196,6 +196,63 @@ M.lsp_handlers = function()
|
|||
vim.api.nvim_echo({ { msg } }, true, {})
|
||||
end
|
||||
end
|
||||
|
||||
-- credits to @Malace : https://www.reddit.com/r/neovim/comments/ql4iuj/rename_hover_including_window_title_and/
|
||||
-- This is modified version of the above snippet
|
||||
vim.lsp.buf.rename = {
|
||||
float = function()
|
||||
local currName = vim.fn.expand "<cword>"
|
||||
|
||||
local win = require("plenary.popup").create(" ", {
|
||||
title = currName,
|
||||
style = "minimal",
|
||||
borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
|
||||
relative = "cursor",
|
||||
borderhighlight = "RenamerBorder",
|
||||
titlehighlight = "RenamerTitle",
|
||||
focusable = true,
|
||||
width = 25,
|
||||
height = 1,
|
||||
line = "cursor+2",
|
||||
col = "cursor-1",
|
||||
})
|
||||
|
||||
local map_opts = { noremap = true, silent = true }
|
||||
|
||||
vim.cmd "startinsert"
|
||||
|
||||
vim.api.nvim_buf_set_keymap(0, "i", "<Esc>", "<cmd>stopinsert | q!<CR>", map_opts)
|
||||
vim.api.nvim_buf_set_keymap(0, "n", "<Esc>", "<cmd>stopinsert | q!<CR>", map_opts)
|
||||
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
0,
|
||||
"i",
|
||||
"<CR>",
|
||||
"<cmd>stopinsert | lua vim.lsp.buf.rename.apply(" .. currName .. "," .. win .. ")<CR>",
|
||||
map_opts
|
||||
)
|
||||
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
0,
|
||||
"n",
|
||||
"<CR>",
|
||||
"<cmd>stopinsert | lua vim.lsp.buf.rename.apply(" .. currName .. "," .. win .. ")<CR>",
|
||||
map_opts
|
||||
)
|
||||
end,
|
||||
|
||||
apply = function(curr, win)
|
||||
local newName = vim.trim(vim.fn.getline ".")
|
||||
vim.api.nvim_win_close(win, true)
|
||||
|
||||
if #newName > 0 and newName ~= curr then
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
params.newName = newName
|
||||
|
||||
vim.lsp.buf_request(0, "textDocument/rename", params)
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
M.gitsigns = function()
|
||||
|
|
Loading…
Reference in a new issue