smjonas / inc-rename.nvim

Incremental LSP renaming based on Neovim's command-preview feature.
MIT License
637 stars 8 forks source link

Expose Lua API rename function #33

Closed mawkler closed 1 year ago

mawkler commented 1 year ago

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.

smjonas commented 1 year ago

Great points!

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.

This is actually a limitation of Neovim itself. The plugin uses the command preview feature (:h command-preview) which handles restoration of the buffer to the original state when the user exits the command line. It currently only works in command-line mode (I actually created an issue on this a while ago: https://github.com/neovim/neovim/issues/19856).

However, when using a floating-window setup like dressing.nvim for instance, and triggering the plugin with the mapping [...] the text that you type appears both in the floating window and in the command-line down in the bottom left corner.

Afaik there's no way around this when using dressing.nvim. With noice.nvim, however, that is actually possible since noice hides the UI for the command line. Please check out the noice.nvim support section in the readme for details.

That should solve the issue you mentioned ("[...] 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."`)

Let me know if you have any further questions or suggestions!

mawkler commented 1 year ago

I see. Thanks for clarifying!