diff --git a/doc/nvui.txt b/doc/nvui.txt index cadc7c97..1d11297b 100644 --- a/doc/nvui.txt +++ b/doc/nvui.txt @@ -643,10 +643,23 @@ It's preferred to put the dofile code in your plugin's config func ------------------------------------------------------------------------------ 7.2 Renamer *nvui.lsp.renamer* -This is a function will will rename variable under cursor +This function renames the variable under the cursor. >lua require "nvchad.lsp.renamer"() +UI can be customized by passing a table of options to this function. Defaults +are listed in the example. +>lua + require "nvchad.lsp.renamer"({ + border = "single", -- see :h winborder for additional options + border_hl_group = "Removed", + right_padding = 15, + title = "Renamer", + title_hl_group = "@comment.danger", + show_original = true, -- set to false if you don't want to autofill + allow_normal = false, -- set to true to access normal in renamer prompt + }) + ============================================================================== 8. Colorify *nvui.colorify* diff --git a/lua/nvchad/lsp/renamer.lua b/lua/nvchad/lsp/renamer.lua index 488ec4a8..9e86cc52 100644 --- a/lua/nvchad/lsp/renamer.lua +++ b/lua/nvchad/lsp/renamer.lua @@ -53,33 +53,55 @@ local function get_symbol_to_rename(cb) end end -return function() +return function(opts) get_symbol_to_rename(function(to_rename) local buf = api.nvim_create_buf(false, true) + local default_opts = { + border = "single", + right_padding = 15, + title = "Rename", + title_hl_group = "@comment.danger", + border_hl_group = "Removed", + show_original = true, + allow_normal = false, + } + opts = vim.tbl_deep_extend('force', default_opts, opts or {}) + local winopts = { height = 1, style = "minimal", - border = "single", + border = opts.border, row = 1, col = 1, relative = "cursor", - width = #to_rename + 15, - title = { { " Renamer ", "@comment.danger" } }, + width = #to_rename + opts.right_padding, + title = { { " " .. opts.title .. " ", opts.title_hl_group } }, title_pos = "center", } local win = api.nvim_open_win(buf, true, winopts) - vim.wo[win].winhl = "Normal:Normal,FloatBorder:Removed" + vim.wo[win].winhl = "Normal:Normal,FloatBorder:" .. opts.border_hl_group api.nvim_set_current_win(win) - api.nvim_buf_set_lines(buf, 0, -1, true, { " " .. to_rename }) + if opts.show_original then + api.nvim_buf_set_lines(buf, 0, -1, true, { " " .. to_rename }) + else + api.nvim_buf_set_lines(buf, 0, -1, true, { " " }) + end vim.bo[buf].buftype = "prompt" vim.fn.prompt_setprompt(buf, "") + vim.api.nvim_input "A" - vim.keymap.set({ "i", "n" }, "", function() + local modes + if opts.allow_normal then + modes = { "n" } + else + modes = { "n", "i" } + end + vim.keymap.set(modes, "", function() api.nvim_buf_delete(buf, { force = true }) end, { buffer = buf }) diff --git a/nvchad_types/chadrc.lua b/nvchad_types/chadrc.lua index a2b396e3..47ef4201 100644 --- a/nvchad_types/chadrc.lua +++ b/nvchad_types/chadrc.lua @@ -55,6 +55,7 @@ ---@field telescope? NvTelescopeConfig ---@field statusline? NvStatusLineConfig ---@field tabufline? NvTabLineConfig +---@field renamer? NvRenamerConfig --- Whether to enable LSP Semantic Tokens highlighting --- List of extras themes for other plugins not in NvChad that you want to compile @@ -117,6 +118,22 @@ --- ``` ---@field modules? table +---@class NvRenamerConfig +--- See h:api-win_config and h:winborder +---@field border? ("single"|"double"|"bold"|"rounded"|"solid") | string[] +--- Link the highlight group of the border characters +---@field border_hl_group? string +--- Width is calculated as the length of the symbol + this many chars +---@field right_padding? number +--- Text displayed atop window +---@field title? string +--- Link the highlight group of the title text +---@field title_hl_group? string +--- Optionally select a mode in the buffer after entering +---@field mode? ("normal"|"insert") +--- If false, do not copy the symbol name into the buffer +---@field show_original boolean + ---@class NvDashConfig --- Whether to open dashboard on opening nvim ---@field load_on_startup? boolean