smjonas / inc-rename.nvim Goto Github PK
View Code? Open in Web Editor NEWIncremental LSP renaming based on Neovim's command-preview feature.
License: MIT License
Incremental LSP renaming based on Neovim's command-preview feature.
License: MIT License
I'm using the latest versions of Neovim and LazyVim. Using the standard typescript lsp enabled via mason and Extras and the cr (which invokes inc-rename), if I rename a property in a typescript type that exists in one file, it doesn't properly refactor in other files. For example, if I have a "Person" type with 'name' and 'age' as properties, a variable in a separate file which uses this type will not change it's property names if I change it in the type definition.
Is there a config setting or something I'm missing?
I like to use dressing
with insert_only = false
, but that doesn't work with inc-rename.nvim
(see #36). As a workaround, I tried using Ctrl+F
to use the command line window in order to edit my command before executing it.
I found that that works with input_buffer_type = nil
, but not with input_buffer_type = "dressing"
.
input_buffer_type = nil
input_buffer_type = "dressing"
IncRename <word>
command or I exited the command line window without executing the commandinc-rename.nvim
throws an error (pasted below) when exiting the command line window without running a commandCmdlineLeave Autocommands for "*":
Vim(append):Error executing lua callback: .../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:139
Vim:E11: Invalid in command-line window; <CR> executes, CTRL-C quits^@stack traceback:^@^I[C]:
in function 'nvim_set_current_win'^@^I.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:139:
in function <.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:132>
Hi, and thanks for creating this plugin! After trying it out I find the user experience a bit odd. The only way to trigger the plugin seems to be with the :IncRename
command, after you type a space after the command, which I find quite unconventional. My guess is that most users will create a keymap to trigger the plugin, like you mention in the README. However, when using a floating-window setup like dressing.nvim for instance, and triggering the plugin with the mapping
vim.keymap.set("n", "<leader>rn", ":IncRename ")
The text that you type appears both in the floating window and in the command-line down in the bottom left corner. I think that most people expect the text you type to only appear in the floating window.
What I suggest is to expose a Lua function that users can call with their keymap instead, for instance like this:
vim.keymap.set("n", "<leader>rn", require('inc_rename').rename)
and the function would only show the floating window (for instance by triggering vim.ui.input
), and no text would appear in the command-line when you type.
Given this markdown file:
# How To Contribute
## Installation
- `git clone <repository-url>`
- `cd @embroider/util`
- `yarn install`
## Linting
- `yarn lint:hbs`
- `yarn lint:js`
- `yarn lint:js --fix`
## Running tests
- `ember test` – Runs the test suite on the current Ember version
- `ember test --server` – Runs the test suite in "watch mode"
- `ember try:each` – Runs the test suite against multiple Ember versions
## Running the dummy application
- `ember serve`
- Visit the dummy application at [http://localhost:4200](http://localhost:4200).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
I tried to rename yarn
to pnpm
and got a bunch of errors
Here's my setup:
-- using lazy.nvim
return {
"smjonas/inc-rename.nvim",
dependencies = { "stevearc/dressing.nvim" },
config = function()
local inc_rename = require("inc_rename")
inc_rename.setup({ input_buffer_type = "dressing" })
vim.keymap.set("n", "<leader>rn", function()
return ":IncRename " .. vim.fn.expand("<cword>")
end, { expr = true })
end,
}
The keybinding puts me in command mode with :IncRename theword
, but:
[inc-rename] An error occurred in the preview function. Please report this error here: https://github.com/smjonas/inc-rename.nvim/issues:
E116: Invalid arguments for function dictwatcherdel
Additionally, it leaves me in a weird state where I have to hit Ctrl-C
for the error message to go away.
Neovim version:
~/.dotfiles => nvim --version
NVIM v0.9.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Is it possible to use this as a drop in handler for vim.lsp.buf.rename()
?
Renaming a variable with uninlined format args works as expected, however inlined format args are not affected.
let a = 5;
println!("{}", a);
println!("{a}");
becomes
let b = 5;
println!("{}", b);
println!("{a}");
I'll preface this with saying that I'm brand new to the command-preview
business so there's a chance this isn't even possible but here it goes:
It would be great to use vim.ui.input()
to get the new variable name instead of passing it as a command argument.
That way users would be able to render the input however they desire (by using dressing.nvim for example) which helps a lot by keeping your eyes at the current line you're working on
Hey I just found this, and it's exactly what I need but there would be one really awesome addition I think.
You have all the rest in place, and I feel like this might not be too difficult.
Is it possible to add other "modes" rather htan LSP rename? Specifically a simple find/replace in file? Everything else could remain exactly the same (dressing.nvim support, realtime updating, etc)
For example I'm using this keymap, and i actually made an issue in dressing.nvim on how to get it to update in realtime when doing a find/replace, and he directed me here.
-- find/replace word under cursor
-- vim.keymap.set('n', '<Leader>rn', [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]], { desc = 'Rename word under cursor'})
vim.keymap.set('n', '<Leader>rn', function()
local current_word = vim.fn.expand("<cword>")
vim.ui.input({
prompt = 'Rename ' .. current_word .. ': ',
default = current_word,
}, function(new_name)
if new_name then
local escaped_word = vim.fn.escape(current_word, '\\/|&')
local substitute_cmd = ":%s/\\<" .. escaped_word .. "\\>/" .. new_name .. "/g"
vim.cmd(substitute_cmd)
end
end)
end, { desc = 'Rename word under cursor' })
Here's my setup using lazy.nvim
:
{
"smjonas/inc-rename.nvim",
dependencies = { "stevearc/dressing.nvim" },
config = function()
local inc_rename = require("inc_rename")
inc_rename.setup({ input_buffer_type = "dressing" })
vim.keymap.set("n", "<leader>rn", function()
return ":IncRename " .. vim.fn.expand("<cword>")
end, { expr = true })
end,
},
inc-rename.nvim
works just fine. However, I like to use dressing
with these settings:
input = { insert_only = false }
(see the dressing
README)
It seems like dressing
's settings are ignored by inc-rename.nvim
. When I press escape, the prompt just exits.
Could inc-rename.nvim
inherit from the configuration passed to dressing
's setup
function? Or perhaps support passing an independent set of options?
Specifically on this branch: NullVoxPopuli/ember-resources#513
in ember-resources/src/core/resource.ts
around line 180, I tried renaming cache
.
And got this error:
2022-06-03T20:22:33 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:39 WARN No results from textDocument/references
2022-06-03T20:22:39 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
(history from nvim-notify)
which I think is from:
https://github.com/smjonas/inc-rename.nvim/blob/main/lua/inc_rename/init.lua#L23
the code that triggered the error:
class ResourceManager {
capabilities = helperCapabilities('3.23', {
hasValue: true,
hasDestroyable: true,
});
constructor(protected owner: unknown) {}
createHelper(Class: typeof Resource, args: ArgsWrapper) {
let owner = this.owner;
let instance: Resource<ArgsWrapper>;
// right here, I tried rename on `cache`
let cache: Cache = createCache(() => {
if (instance === undefined) {
instance = new Class(owner);
associateDestroyableChild(cache, instance);
}
if (instance.modify) {
instance.modify(args.positional, args.named);
}
return instance;
});
return cache;
}
in lua files, works as expected
fyi: Noice users can now configure IncRename
with config.presets.inc_rename=true
:)
when I activate IncRename, there is no text, is there a way to pre-fill with the text/token under the cursor?
Hi 👋🏿
This plugin is a fantastic idea @smjonas thanks for creating it
I've just started using it this morning and am occasionally hitting the following error whilst just testing this out
Error executing vim.schedule lua callback: ...ack/packer/start/inc-rename.nvim/lua/inc_rename/init.lua:38: Index out of bounds
stack traceback:
[C]: in function 'nvim_buf_get_lines'
...ack/packer/start/inc-rename.nvim/lua/inc_rename/init.lua:38: in function 'handler'
...r/neovim/HEAD-9961a97/share/nvim/runtime/lua/vim/lsp.lua:1173: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
Seems that on the following line
inc-rename.nvim/lua/inc_rename/init.lua
Line 38 in 800382c
Single word instances can be, although breaking for ::
delimiters, replaced (faster) with
map('n', ',', [["_diwP]], opts) -- keep pasting over the same thing, old map: C-p
map('n', '*', [[m`:keepjumps normal! *``<CR>]], opts) -- word boundary search, no autojump
map('n', 'g*', [[m`:keepjumps normal! g*``<CR>]], opts) -- no word boundary search no autojump
Additional usage of map('n', '<leader>sh', ':ClangdSwitchSourceHeader<CR>', opts) -- switch header_source
or harpoon/buffer navigation allows also to workaround many cases (though with lower editing speed):
map('n', '<leader>ff', [[<cmd>lua require('telescope.builtin').find_files()<CR>]], opts) -- find files
-- C-q
-- 1.
-- :cfdo :badd %
-- and :b buffername or :bBufNr with :ls ie as combined command
-- 2.
-- :cfdo lua require("harpoon.mark").add_file()
map('n', '<leader>cj', [[<cmd>lua require("harpoon.term").gotoTerminal(1)<CR>]], opts)
map('n', '<leader>j', [[<cmd>lua require("harpoon.ui").nav_file(1)<CR>]], opts)
It would be nice to mention those things with their advantages + shortcomings, as they are going into the same direction of fast + simple editings.
For example inc-rename is less appropriate for editings, which involve intentionally breaking things on changes.
Additional plus would be to mention the treesitter plugin one can use (with advantages + shortcomings).
I'm pressing escape to try to abort renaming in a typescript file. All the same info as here: #1 -- might be related.
Works as expected in lua files
Hi,
When I want to change a variable, I should type the whole name again plus the changes, while I was looking for a way to only type the required parts. For example address
to addressObj
, I'm looking for a way to have address
in the INC box when I run :IncRename
, and then I just type the Obj
part. But the INC box is empty all the time.
Do we have this functionality, or I missed a config?
Cheers,
Mort
Compared to VSCode, where pressing backspace multiple times doesn't close the popup / discard changes
I'm using latest LazyVim (noice.nvim).
Hello! I love this plugin!
There seems to be an issue when renaming variables that are longer than the indent, as shown in the video.
$ nvim --version
NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3
My neovim config at the time of reporting this issue: https://github.com/DrPoppyseed/config/tree/a88db7befae3985fcfd9998b10cf6f11998ad82d/dot_config/nvim
Hi.
Sometimes, when I try to rename an item, I get the following error:
[inc-rename] An error occurred in the preview function. Please report this error here: https://github.com/smjonas/inc-rename.nvim/issues:
Error executing Lua callback: ...are/nvim/plugged/inc-rename.nvim/lua/inc_rename/init.lua:264: Invalid 'end_col': out of range
stack traceback:
^I[C]: in function 'nvim_buf_set_text'
^I...are/nvim/plugged/inc-rename.nvim/lua/inc_rename/init.lua:264: in function 'apply_highlights_fn'
^I...are/nvim/plugged/inc-rename.nvim/lua/inc_rename/init.lua:306: in function <...are/nvim/plugged/inc-rename.nvim/lua/inc_rename/init.lua:210>
I'm not exactly sure how to reproduce the issue, though, but perhaps I could point you to a project of mine where this happens if needed.
Thanks to fix the issue.
Hello, I am having issues making it work on lua files, I've tested it on C,C++ and java and it worked well, but when trying to use it on lua files it doesn't work.
I have this sudggeste mapping:
vim.keymap.set("n", "<leader>rn", function()
return ":IncRename " .. vim.fn.expand("<cword>")
end, { expr = true, desc = "[R]e[n]ame" })
When trying to use it on lua files the dressing window appears for an instant and I get the following error: [inc_rename] Nothing to rename
Also if I try to use the command manually the command tries to trigger as soon asi I write :Inc
with the E471: Argument required
error
I tried with Lspsaga's rename and it works fine.
Lsp I use on Lua is stylua
Say I just rename a variable. Then, if I accidentally press<C-p>
(to get the last command I called) too many times, then the renaming prompt will show up again and give me an error:
folke/noice.nvim
, which might be related.restore_view_on_zoom_out
is the variable name I just named.This bug is really annoying since the LSP client will simply stop working after the error. I hope it could be fixed soon...
Error 14:03:00 msg_show.lua_error restore_view_on_zoom_out Error executing vim.schedule lua callback: BufEnter Autocommands for "*": Vim(lua):E5108: Error executing lua Vim:E903: Process failed to start: too many open files: "/usr/bin/git"
stack traceback:
[C]: in function 'jobstart'
...l/share/nvim/lazy/lualine.nvim/lua/lualine/utils/job.lua:9: in function 'start'
...zy/lualine.nvim/lua/lualine/components/diff/git_diff.lua:133: in function 'update_git_diff'
...zy/lualine.nvim/lua/lualine/components/diff/git_diff.lua:121: in function 'update_diff_args'
[string ":lua"]:1: in main chunk
[C]: in function 'bufload'
.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:55: in function 'cache_lines'
.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:121: in function 'handler'
/usr/local/share/nvim/runtime/lua/vim/lsp.lua:1390: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
[C]: in function 'bufload'
.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:55: in function 'cache_lines'
.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:121: in function 'handler'
/usr/local/share/nvim/runtime/lua/vim/lsp.lua:1390: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
Hi, thank you for this awesome plugin! I love the live-preview for renaming, and live-command.nvim that expands this to other commands like norm
.
Is there anyway to integrate this with filipdutescu/renamer.nvim for a VSCode-like input (see below images)?
I opened a similar issue in renamer.nvim
as well:
filipdutescu/renamer.nvim#137
When I call the rename command, the pop-up window for renaming opens in insert mode.
Quite often I just have to go to the letter and replace it to fix the typo. In insert mode, using the arrows is very inconvenient.
How to change the mode to normal when a pop-up window appears?
I use this plugin with LazyVim with default config:
https://www.lazyvim.org/extras/editor/inc-rename
I don't know how to describe this so here is a gif/recording:
It worked when I tried to rename parser
but it didn't work when I tried to rename argparse
. However, it does rename argparse
in the live preview.
Detected filetype: python
2 client(s) attached to this buffer:
Client: pyright (id: 1, bufnr: [1])
filetypes: python
autostart: true
root directory: /home/myxi/Documents/coding/python/glowl
cmd: /usr/bin/pyright-langserver --stdio
Client: ruff_lsp (id: 2, bufnr: [1])
filetypes: python
autostart: true
root directory: /home/myxi/Documents/coding/python/glowl
cmd: /home/myxi/.local/bin/ruff-lsp
Neovim version: 0.9.5
Python version: 3.12.2
Currently, if I use this plugin, the indent guidelines from indent-blankline.nvim are hidden.
How can I make it so that the indent lines are shown during the rename?
If the rename command is run before the LSP server has started, no highlighting is shown until the next character is typed after the server has started up.
Expected behavior: once the LSP server has started, show the highlights.
It would be great for this plugin to show a rename preview panel similar to the quick fix one, containing a row for each of the symbols which will be updated with the LSP rename.
Also, those rows should be grouped in files where the change will occur. Example:
-----------------
-- Preview Window
-----------------
[1] C:\Work\include.h [1 match]
17. int NEWSYMBOL;
[2] C:\Work\main.c [2 matches]
19. NEWSYMBOL = 12;
23. print("Today is &d", NEWSYMBOL\n");
When running a rename and there are multiple files affected, is there a way to auto safe all of them after the rename?
Hey, when I use the snippet provided in the config to rename a variable it works, as long as I don't completely remove the previous variable. Hopefully the video explains it better.
Also an aside question, does this use the AST for renaming?
This is how my config looks like right now. I'm using Lazy as my plugin manager
return {
"smjonas/inc-rename.nvim",
config = function()
require("inc_rename").setup()
vim.keymap.set("n", "<leader>rn", function()
return ":IncRename " .. vim.fn.expand("<cword>")
end, { expr = true })
end,
}
This is the neovim version I'm running
➜ nvim --version
NVIM v0.9.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
After installing the plugin I get the following error message when I open Neovim
packer.nvim: Error running config for inc-rename.nvim: ...ack/packer/start/inc-rename.nvim/lua/inc_rename/init.lua:364: invalid key: preview
I guess that's because it is actually modifying the buffer.
Really loving the plugin, but unfortunately I've been experiencing an issue since updating to Neovim 0.10 where the cursor in the command palette/noice (I tried both) does not visually respond to arrow keys, though it does in fact move, making it hard to rename things.
I have attached a short video illustrating the issue where <leader>rn
uses inc-rename.nvim
and <leader>lr
uses vim.buf.lsp.rename
, which works as expected.
I did not experience this issue with Neovim 0.9.5.
Any suggestions would be much appreciated.
return {
'folke/noice.nvim',
event = 'VeryLazy',
dependencies = {
'MunifTanjim/nui.nvim',
-- OPTIONAL:
-- `nvim-notify` is only needed, if you want to use the notification view.
-- If not available, we use `mini` as the fallback
'rcarriga/nvim-notify',
'hrsh7th/nvim-cmp',
},
config = function()
require('noice').setup {
lsp = {
hover = { enabled = true },
signature = { enabled = true },
},
presets = {
bottom_search = false, -- use a classic bottom cmdline for search
command_palette = true, -- position the cmdline and popupmenu together
long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = false, -- add a border to hover docs and signature help
},
override = {
['vim.lsp.util.convert_input_to_markdown_lines'] = true,
['vim.lsp.util.stylize_markdown'] = true,
['cmp.entry.get_documentation'] = true, -- requires hrsh7th/nvim-cmp
},
routes = {
{
view = 'notify',
filter = { event = 'msg_showmode' },
},
},
}
nmap('<leader>nd', '<cmd>NoiceDismiss<cr>', 'dismiss')
nmap('<leader>ne', '<cmd>NoiceErrors<cr>', 'errors')
nmap('<leader>nl', '<cmd>NoiceLast<cr>', 'last')
nmap('<leader>nn', '<cmd>Noice<cr>', 'noice')
nmap('<leader>nh', '<cmd>NoiceHistory<cr>', 'history')
nmap('<leader>nt', '<cmd>NoiceTelescope<cr>', 'telescope')
end,
}
return {
'smjonas/inc-rename.nvim',
-- enabled = false,
config = function()
require('inc_rename').setup {}
vim.keymap.set('n', '<leader>rn', function()
return ':IncRename ' .. vim.fn.expand '<cword>'
end, { expr = true, desc = 'rename word under cursor' })
end,
}
This didn't work:
function()
return ":IncRename " .. vim.fn.expand("<cword>")
end
It had no observable effect whatsoever.
vim.api.nvim_feedkeys()
to the rescue:
function()
local line = ":IncRename " .. vim.fn.expand("<cword>")
vim.api.nvim_feedkeys(line, "n", true)
end
I don't know if it was my Neovim version (0.9.2) or some other plugin interfering, but now it's working.
Normally, we can use up
and down
key to rotate the command in history after typing :
. But if we used IncRename
command we cannot do that
Hey 👋🏾
I think the title is pretty dump, but I fail to summarize the issue better. The problem is that if I use a keymap like from the README, the whole preview, coloring, ... process only starts once I type something. So the current word under the cursor gets inserted, but nothing happens. Only when I alternate the word it starts. I would expect (I think think it was like that in the past) to get all occurances highlighted immediately and also dressing.nvim
to pop-up right away. Right now it looks like it is hanging.
Am I doing something wrong?
I've a question, what if the LSP rename action involves updating references in buffers different from the actual one?
It would be nice to have a preview of the changes which would be applied to the other buffers (opened or not). Would something like that possible?
The keymap vim.keymap.set("n", "<leader>rn", ":IncRename ")
gives the error: E471: Argument required
When set up with noice.nvim inc-rename preset, :IncRename
, throws error E471: Argument required
. I'm opening this here since I presume the issue is with inc-rename, but if you think its a noice.nvim bug, I can open an issue there.
-- Shoutout to folke for providing a great minimal config for noice.nvim
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
"folke/tokyonight.nvim",
{
"folke/noice.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
"rcarriga/nvim-notify",
},
},
{
"smjonas/inc-rename.nvim",
cmd = "IncRename",
config = function()
require("inc_rename").setup()
end
},
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
-- add anything else here
vim.opt.termguicolors = true
vim.cmd([[colorscheme tokyonight]])
require("noice").setup({
presets = { inc_rename = true }
})
No LSP is needed to reproduce the error; in my config it happens regardless of the LSP attached.
Open any file, navigate to any word, and do :IncRename
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.