From 700801b3131af63970a9c6091bb0b5e34c7347ce Mon Sep 17 00:00:00 2001 From: siduck Date: Tue, 7 Jun 2022 11:11:55 +0530 Subject: [PATCH] avoid overriding default vim.lsp functions read https://github.com/NvChad/NvChad/discussions/1180 --- lua/core/mappings.lua | 2 +- lua/plugins/configs/others.lua | 58 -------------------------------- lua/ui/renamer.lua | 60 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 59 deletions(-) create mode 100644 lua/ui/renamer.lua diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index bc804fa..ac3eb10 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -147,7 +147,7 @@ M.lspconfig = { ["ra"] = { function() - vim.lsp.buf.rename.float() + require("ui.renamer").open() end, " lsp rename", }, diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 777f1bf..41e9714 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -201,64 +201,6 @@ 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 "" .. " " - - local win = require("plenary.popup").create(currName, { - title = "Renamer", - 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 "normal w" - vim.cmd "startinsert" - - vim.api.nvim_buf_set_keymap(0, "i", "", "stopinsert | q!", map_opts) - vim.api.nvim_buf_set_keymap(0, "n", "", "stopinsert | q!", map_opts) - - vim.api.nvim_buf_set_keymap( - 0, - "i", - "", - "stopinsert | lua vim.lsp.buf.rename.apply(" .. currName .. "," .. win .. ")", - map_opts - ) - - vim.api.nvim_buf_set_keymap( - 0, - "n", - "", - "stopinsert | lua vim.lsp.buf.rename.apply(" .. currName .. "," .. win .. ")", - 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() diff --git a/lua/ui/renamer.lua b/lua/ui/renamer.lua new file mode 100644 index 0000000..dcad896 --- /dev/null +++ b/lua/ui/renamer.lua @@ -0,0 +1,60 @@ +-- 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 + +local M = {} + +M.open = function() + local currName = vim.fn.expand "" .. " " + + local win = require("plenary.popup").create(currName, { + title = "Renamer", + 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 "normal w" + vim.cmd "startinsert" + + vim.api.nvim_buf_set_keymap(0, "i", "", "stopinsert | q!", map_opts) + vim.api.nvim_buf_set_keymap(0, "n", "", "stopinsert | q!", map_opts) + + vim.api.nvim_buf_set_keymap( + 0, + "i", + "", + "stopinsert | lua require'ui.renamer'.apply(" .. currName .. "," .. win .. ")", + map_opts + ) + + vim.api.nvim_buf_set_keymap( + 0, + "n", + "", + "stopinsert | lua require'ui.renamer'.apply(" .. currName .. "," .. win .. ")", + map_opts + ) +end + +M.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 + +return M