From cf5e9938b14007ca3e72b3ce5fdfd6866c0157e8 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Tue, 13 May 2025 17:13:16 -0700 Subject: [PATCH 1/4] Add options for renamer --- doc/nvui.txt | 24 +++++++++++++++++++++++- lua/nvchad/lsp/renamer.lua | 29 +++++++++++++++++++++-------- lua/nvconfig.lua | 10 ++++++++++ nvchad_types/chadrc.lua | 17 +++++++++++++++++ 4 files changed, 71 insertions(+), 9 deletions(-) diff --git a/doc/nvui.txt b/doc/nvui.txt index cadc7c97..e77cc017 100644 --- a/doc/nvui.txt +++ b/doc/nvui.txt @@ -165,6 +165,16 @@ nvconfig file : |https://github.com/NvChad/ui/blob/v3.0/lua/nvconfig.lua| modules = nil, bufwidth = 21, }, + + renamer = { + border = "single", + border_hl_group = "Removed", + right_padding = 15, + title = "Renamer", + title_hl_group = "@comment.danger", + mode = "insert", + show_original = true, + }, }, nvdash = { @@ -643,10 +653,22 @@ 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 changing options in your chadrc +>lua + renamer = { + border = "single", -- single/double/bold/rounded/solid/string[] + border_hl_group = "Removed", + right_padding = 15, + title = "Renamer", + title_hl_group = "@comment.danger", + mode = "insert", -- insert/normal + show_original = true, -- set to false if you don't want to autofill + }, + ============================================================================== 8. Colorify *nvui.colorify* diff --git a/lua/nvchad/lsp/renamer.lua b/lua/nvchad/lsp/renamer.lua index 488ec4a8..e4ef9b76 100644 --- a/lua/nvchad/lsp/renamer.lua +++ b/lua/nvchad/lsp/renamer.lua @@ -1,5 +1,6 @@ local lsp = vim.lsp local api = vim.api +local opts = require("nvconfig").ui.renamer local function get_text_at_range(range, position_encoding) return api.nvim_buf_get_text( @@ -60,26 +61,38 @@ return function() 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() + if opts.mode == "insert" then + vim.api.nvim_input "A" + else + vim.api.nvim_input "$" + end + + local exitMapModes = { "n" } + if opts.mode == "insert" then + exitMapModes = { "i", "n" } + end + vim.keymap.set(exitMapModes, "", function() api.nvim_buf_delete(buf, { force = true }) end, { buffer = buf }) diff --git a/lua/nvconfig.lua b/lua/nvconfig.lua index 11b7ae10..98836eec 100644 --- a/lua/nvconfig.lua +++ b/lua/nvconfig.lua @@ -39,6 +39,16 @@ local options = { modules = nil, bufwidth = 21, }, + + renamer = { + border = "single", + border_hl_group = "Removed", + right_padding = 15, + title = "Renamer", + title_hl_group = "@comment.danger", + mode = "insert", + show_original = true, + }, }, nvdash = { 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 From a21af4f8ee547f73d42796b4c618b0c6f000496c Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 15 May 2025 15:52:09 -0700 Subject: [PATCH 2/4] Change Reamer UI options to funciton args --- doc/nvui.txt | 33 ++++++++++++--------------------- lua/nvchad/lsp/renamer.lua | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/doc/nvui.txt b/doc/nvui.txt index e77cc017..12f2fcf6 100644 --- a/doc/nvui.txt +++ b/doc/nvui.txt @@ -165,16 +165,6 @@ nvconfig file : |https://github.com/NvChad/ui/blob/v3.0/lua/nvconfig.lua| modules = nil, bufwidth = 21, }, - - renamer = { - border = "single", - border_hl_group = "Removed", - right_padding = 15, - title = "Renamer", - title_hl_group = "@comment.danger", - mode = "insert", - show_original = true, - }, }, nvdash = { @@ -657,17 +647,18 @@ This function renames the variable under the cursor. >lua require "nvchad.lsp.renamer"() -UI can be customized by changing options in your chadrc ->lua - renamer = { - border = "single", -- single/double/bold/rounded/solid/string[] - border_hl_group = "Removed", - right_padding = 15, - title = "Renamer", - title_hl_group = "@comment.danger", - mode = "insert", -- insert/normal - show_original = true, -- set to false if you don't want to autofill - }, +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", + mode = "insert", -- insert/normal + show_original = true, -- set to false if you don't want to autofill + }) ============================================================================== 8. Colorify *nvui.colorify* diff --git a/lua/nvchad/lsp/renamer.lua b/lua/nvchad/lsp/renamer.lua index e4ef9b76..e1569b5a 100644 --- a/lua/nvchad/lsp/renamer.lua +++ b/lua/nvchad/lsp/renamer.lua @@ -1,6 +1,5 @@ local lsp = vim.lsp local api = vim.api -local opts = require("nvconfig").ui.renamer local function get_text_at_range(range, position_encoding) return api.nvim_buf_get_text( @@ -54,10 +53,21 @@ 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", + mode = "insert", + } + opts = vim.tbl_deep_extend('force', default_opts, opts or {}) + local winopts = { height = 1, style = "minimal", From ab38027b75af53967352e766ad63680d7f37acde Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 15 May 2025 15:54:56 -0700 Subject: [PATCH 3/4] forgot to remove changes to nvconfig.lua --- lua/nvconfig.lua | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lua/nvconfig.lua b/lua/nvconfig.lua index 98836eec..11b7ae10 100644 --- a/lua/nvconfig.lua +++ b/lua/nvconfig.lua @@ -39,16 +39,6 @@ local options = { modules = nil, bufwidth = 21, }, - - renamer = { - border = "single", - border_hl_group = "Removed", - right_padding = 15, - title = "Renamer", - title_hl_group = "@comment.danger", - mode = "insert", - show_original = true, - }, }, nvdash = { From a52da6f545108d135d95be5ec0844b94083cae37 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Mon, 26 May 2025 16:24:08 -0700 Subject: [PATCH 4/4] Simplified mode option -> allow_normal boolean --- doc/nvui.txt | 2 +- lua/nvchad/lsp/renamer.lua | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/doc/nvui.txt b/doc/nvui.txt index 12f2fcf6..1d11297b 100644 --- a/doc/nvui.txt +++ b/doc/nvui.txt @@ -656,8 +656,8 @@ are listed in the example. right_padding = 15, title = "Renamer", title_hl_group = "@comment.danger", - mode = "insert", -- insert/normal 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 }) ============================================================================== diff --git a/lua/nvchad/lsp/renamer.lua b/lua/nvchad/lsp/renamer.lua index e1569b5a..9e86cc52 100644 --- a/lua/nvchad/lsp/renamer.lua +++ b/lua/nvchad/lsp/renamer.lua @@ -63,8 +63,8 @@ return function(opts) title = "Rename", title_hl_group = "@comment.danger", border_hl_group = "Removed", - show_original = "true", - mode = "insert", + show_original = true, + allow_normal = false, } opts = vim.tbl_deep_extend('force', default_opts, opts or {}) @@ -92,17 +92,16 @@ return function(opts) vim.bo[buf].buftype = "prompt" vim.fn.prompt_setprompt(buf, "") - if opts.mode == "insert" then - vim.api.nvim_input "A" - else - vim.api.nvim_input "$" - end - local exitMapModes = { "n" } - if opts.mode == "insert" then - exitMapModes = { "i", "n" } + vim.api.nvim_input "A" + + local modes + if opts.allow_normal then + modes = { "n" } + else + modes = { "n", "i" } end - vim.keymap.set(exitMapModes, "", function() + vim.keymap.set(modes, "", function() api.nvim_buf_delete(buf, { force = true }) end, { buffer = buf })