smjonas / inc-rename.nvim

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

Error on rename #53

Closed antoyo closed 2 months ago

antoyo commented 5 months ago

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.

smjonas commented 5 months ago

Hi, thanks for letting me know, I haven't seen this issue occur before. Do you perhaps remember which language server was active during the rename? If it occurs again, please don't hesitate to send me more details as you offered. Thank you!

antoyo commented 5 months ago

This is rust-analyzer.

Here's the output of :LspInfo:

Language client log: /home/user/.local/state/nvim/lsp.log
Detected filetype:   rust

1 client(s) attached to this buffer:

Client: rust_analyzer (id: 1, bufnr: [4, 12, 6])
 filetypes:       rust
 autostart:       true
 root directory:  /home/user/Ordinateur/Programmation/Rust/Projets/nox-lang/nox
 cmd:             /home/user/.cargo/bin/rust-analyzer

Configured servers list: clangd, pylsp, rust_analyzer
Moerliy commented 4 months ago

I'm encountering this one too, but only on my larger projects. I think it doesn't matter which language server it is because I have the same behavior with tsserver, clangd and pyright. My guess is the issue lies with the live preview when renaming. It can handle one character change but with the next one there is no preview anymore. On confirming the rename the following error pops up:

      "[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: .../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:328: Invalid 'end_col': out of range
stack traceback:
    [C]: in function 'nvim_buf_set_text'
    .../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:328: in function 'apply_highlights_fn'
    .../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:374: in function <.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:278>
Active language servers: { "tsserver" }
Buffer name: MY_CURRENT_BUFFER
smjonas commented 4 months ago

@Moerliy Do you have an example project I can try to reproduce this with? I am unable to reproduce this error with tsserver. Please also let me know in which file the error occurred and on what identifier if possible.

Moerliy commented 4 months ago

@smjonas the projects I encountered it are unfortunately locked behind company policies. If I have some time tomorrow I will dig into it and try to find one that I can share.

Moerliy commented 4 months ago

@smjonas as promised a way of getting the issue consistently. If it doesn't work just let me know and we try something else.

  1. Use the zod project written in typescript. So you will need the tsserver as a lsp.
  2. Open up src/types.ts
  3. move down to line 93 and try renaming SyncParseReturnType.
  4. After deleting 3 characters the preview buffer closes and if you confirm the rename with enter you will get the error message from above.

Something I noticed and could have the same root problem:

  1. Same project, same file
  2. line 92 and try renaming ParseContext.
  3. Add a couple of characters and have a look at the preview. With every new character added to the rename, the previously added characters should appear again with every new character you add. Hard to describe but the number of characters shown in the preview is the factorial of the number of characters added to the rename. (not sure if you can reproduce it tho because that behavior is a bit less predictable)
smjonas commented 4 months ago

@Moerliy Thanks a lot for the detailed instructions! That should help greatly with debugging. I will try to have a look at this next week :)

dsully commented 4 months ago

I'm also seeing this with rust-analyzer. Using nightly and noice.nvim if that matters.

smjonas commented 4 months ago

Hi @Moerliy, unfortunately I could not reproduce the issue you described: image When renaming SyncParseReturnType, it looks just fine, too.

Which version of tsserver are you using? I installed it with mason and am on the latest version (4.3.3).

Moerliy commented 4 months ago

I'm using mason too so the same version.

Maybe there are some issues with other plugins i installed. If you want you can have a look at my nvim dotfiles. The should work out of the box if you ignore the chatgpt warning.

marcomayer commented 3 months ago

I get the same error sporadically but much more often since updating to nvim 0.10. Using the latest gopls language server.

joaomendoncaa commented 3 months ago

Using lua_ls (neovim 0.10.0) and getting the same issue.

"[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: .../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:337: Invalid 'end_col': out of range
stack traceback:
^I[C]: in function 'nvim_buf_set_text'
^I.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:337: in function 'apply_highlights_fn'
^I.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:383: in function <.../share/nvim/lazy/inc-rename.nvim/lua/inc_rename/init.lua:287>
Active language servers: { "lua_ls" }

Maybe isolate this temporarily by falling back to LSP rename in case it fails? Thanks to anyone who jumps on this.

smjonas commented 3 months ago

@joaomendoncaa thanks for reporting, would you mind sharing the file contents where this error occurred?

joaomendoncaa commented 3 months ago

@joaomendoncaa thanks for reporting, would you mind sharing the file contents where this error occurred?

I tried to re-open the directory where it happened and sadly couldn't reproduce it again (cwd was in config.git's root). But I've had this issue on other ocasions with other LSPs. (hope that helps)

Meanwhile, I found another quirk when renaming certain namespaces and recorded it. (also happened before with other LSPs, but this is on lua_ls) See video bellow on how :IncRename is somehow infinitely repeating the characters I'm typing:

https://github.com/smjonas/inc-rename.nvim/assets/57664150/24df4bee-abaf-4b1e-aee6-dfd23d498d50

This might be happening for a thousand different reasons so, if needed, you can message me to help you debugging this, I don't have a lot of time to investigate it myself sadly.

Twitter: https://x.com/joaomendoncaaaa Telegram: https://t.me/joaomendoncaaa

smjonas commented 3 months ago

Thank you, I was now able to produce the error with your dotfiles. I could also reproduce the other error with inccommand=split which I will look into.

joaomendoncaa commented 3 months ago

Awesome! Thank you for all your work Jonas. 🙏

smjonas commented 3 months ago

@joaomendoncaa I fixed a bug that only occurred with inccommand=split (that might explain the fact that I never noticed any issues). This suspicion is also supported by the fact that antoyo and Moerliy also have set inccommand=split in their config.

Can you update the plugin and let me know if you can still reproduce the errors you mentioned? Thanks for your help.

Moerliy commented 3 months ago

@smjonas I just saw this and did some quick tests. Both, the example I mentioned earlier in the thread and and other in my bigger project seem to work. The lsp's I tested were tsserver, clangd and pyright. I did some load tests in c++ too. Did renaming for symbols with 100+ mentions across 10 files.

joaomendoncaa commented 3 months ago

@joaomendoncaa I fixed a bug that only occurred with inccommand=split (that might explain the fact that I never noticed any issues). This suspicion is also supported by the fact that antoyo and Moerliy also have set inccommand=split in their config.

Can you update the plugin and let me know if you can still reproduce the errors you mentioned? Thanks for your help.

Hey! Awesome news! 🙌

I roughly tested it aswell and the renaming feature seems to be working with only 2 minor issues:

Quick demo

https://github.com/smjonas/inc-rename.nvim/assets/57664150/98408013-c139-44a3-bb20-41ea23bc4c00

smjonas commented 3 months ago

@joaomendoncaa Thank you for testing as well! I also noticed this other issue - at least there is no crash now though ;) I will try to fix it this week.

joaomendoncaa commented 3 months ago

Hey @smjonas! Hope you're safe and sound but I'm yet again the bearer of bad news! 😂

Found another bug on renaming where it doesn't replace the correct characters at all. This time around I have 3 clients attached to the buffer (tsserver, typescript-tools and tailwindcss).

The demo bellow will try to replace initialSettings to initial in 2 places with the following errors:

So it both deletes more than the length of the replaced characters and sometimes leaves unwanted characters in place. I can't share the repo but let me know if I can give you anything else useful to debug the issue.

https://github.com/smjonas/inc-rename.nvim/assets/57664150/06c816bf-15d7-48b9-ba84-6dcb23c25521

image

smjonas commented 3 months ago

@joaomendoncaa

inccommand=split quickfix list is only updating the last item correctly (although all of them get correctly renamed)

This issue should now be fixed, I added a test and can't reproduce it anymore

Found another bug on renaming where it doesn't replace the correct characters at all. This time around I have 3 clients attached to the buffer (tsserver, typescript-tools and tailwindcss).

The issue seems to be that you're using typescript-tools and tsserver at the same time. Make sure to uninstall tsserver (this is also stated in the typescript-tools readme).

Let me know if there are any remaining issues and thanks for all the great feedback and help! :)

joaomendoncaa commented 3 months ago

🫶 🫵 @smjonas

image

image

smjonas commented 2 months ago

Since there hasn't been any activity in this thread since the last commits, I will close this issue assuming the bugs have been fixed :) Please open a new issue if anyone still experiences similar issues.