smjonas / inc-rename.nvim

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

[Feature] Show a preview window listing all of the files and occurrences where the symbol will be replaced #19

Closed pidgeon777 closed 1 year ago

pidgeon777 commented 2 years ago

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");
smjonas commented 2 years ago

Seems like a nice feature to have! Did I understand you correctly that this preview window should be shown as a sort of confirmation dialog when you press enter? And then you would need to press enter (or y) again?

smjonas commented 1 year ago

Hey @pidgeon777, are you still interested in this feature?

pidgeon777 commented 1 year ago

Hey @pidgeon777, are you still interested in this feature?

Hi @smjonas sorry for the wait, somehow I missed the updates on this issue.

Well, yes, I would be highly interested.

Seems like a nice feature to have! Did I understand you correctly that this preview window should be shown as a sort of confirmation dialog when you press enter? And then you would need to press enter (or y) again?

What I meant, is that it could be used in two ways:

a. Show a live preview of the changes introduced with the LSP rename feature when typing the new variable name. b. Show a preview confirmation dialog just showing the new changes before applying them.

In both cases, it would be necessary to show the preview of the newly modified code before applying the changes.

And this could be a live preview (as expressed in case a) or just a confirmation (case b).

Also, it would be really nice to show all of those changes in the way I described them in my first post so that it would be possible to know in an easy way which files would get modified, for example.

pidgeon777 commented 1 year ago

I would be happy to help you beta-testing this new feature, if needed 👍.

folke commented 1 year ago

At least for the current file, this is already possible. See :h command-preview:

4. Return an integer (0, 1, 2) which controls how Nvim behaves as follows:
   0: No preview is shown.
   1: Preview is shown without preview window (even with "inccommand=split").
   2: Preview is shown and preview window is opened (if "inccommand=split").
      For "inccommand=nosplit" this is the same as 1.

You should probably return 2 at https://github.com/smjonas/inc-rename.nvim/blob/de322174a1adc8527b3805dd01e18a7f4ffec22b/lua/inc_rename/init.lua#L319

smjonas commented 1 year ago

At least for the current file, this is already possible. See :h command-preview:

Since https://github.com/neovim/neovim/pull/19360 the command preview does work across multiple files.

You should probably return 2 at https://github.com/smjonas/inc-rename.nvim/blob/de322174a1adc8527b3805dd01e18a7f4ffec22b/lua/inc_rename/init.lua#L319

I am already returning 2 (not in the function being executed but in the preview callback): https://github.com/smjonas/inc-rename.nvim/blob/ce0e1d795608dc567c8ae3cd56c44f0516ea3276/lua/inc_rename/init.lua#L244


That is why I am a bit confused what you mean by "Show a live preview of the changes introduced with the LSP rename feature when typing the new variable name." @pidgeon777. Isn't that already the case?

I think for your second suggestion with the preview window we can make use of inccommand=split (which if enabled will give us a buffer number in the preview callback) and then format the results nicely in that window.

folke commented 1 year ago

I am already returning 2 (not in the function being executed but in the preview callback):

My bad, looked at the wrong code :)

@pidgeon777 probably doens't have inccommand=split set.

pidgeon777 commented 1 year ago

I'm trying to test the branch but noice seems to crash when I select "Yes" "No" in the new user choice popup, or when I try to autocomplete, or when activating a previous command from the history etc.

pidgeon777 commented 1 year ago

In particular, in the new noice popup, when I digit :IncRename and then a space, Neovim (Neovide) crashes when pressing space.

smjonas commented 1 year ago

I can't reproduce the crash with noice (NVIM v0.9.0-dev-98-g1c478391c). Can you create an issue on the noice repo with the exact error message?

pidgeon777 commented 1 year ago

In the meanwhile I disabled noice and inc-rename.nvim doesn't lead Neovim to crash anymore. Here is the result when trying to rename a function:

image

Now I will test your PR.

EDIT: Tested, see:

https://github.com/smjonas/inc-rename.nvim/pull/25

folke commented 1 year ago

@pidgeon777 Neovide is not working properly with Noice. See the tracking issue on the noice github. Disable multigrid and use Neovim nightly is you want to use Noice.

pidgeon777 commented 1 year ago

Thanks @folke, I'll try to report any found issue in the Noice issue tracker 👍.