Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c++ rename destroys code (clangd) #4523

Open
2 of 3 tasks
cyberkm opened this issue Aug 5, 2024 · 3 comments
Open
2 of 3 tasks

c++ rename destroys code (clangd) #4523

cyberkm opened this issue Aug 5, 2024 · 3 comments
Labels

Comments

@cyberkm
Copy link

cyberkm commented Aug 5, 2024

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

When working on a multi file project, a lot of times I have to rename functions or variables across multiple files
I am doing it using lsp-rename, but unfortunately lsp rename destroys the code all over the project instead of just renaming the symbol, it adds random characters, and deletes random some other characters around the symbol to be renamed all over the project.
Can you please fix it?
Using clangd as a backend.

Steps to reproduce

Open multifile c++ code with compilation database and clangd backend
open one of the files, select a symbol, it can be a function or a variable that used in other files as well.
do lsp-rename, write a new name.
The code is now destroyed, new chars are added, some chars are deleted (for example it might delete opening brackets after the function name)

Expected behavior

The symbol name is correctly replaced all over the project without destroying anything.

Which Language Server did you use?

clangd

OS

Windows

Error callstack

No response

Anything else?

No response

@cyberkm cyberkm added the bug label Aug 5, 2024
@cyberkm cyberkm changed the title c++ rename destroy code (clangd) c++ rename destroys code (clangd) Aug 5, 2024
@dgutov
Copy link
Contributor

dgutov commented Sep 11, 2024

Just a heads up: the odds of such a bug getting fixed will go up if the report contains specific instructions for reproducing, e.g. a link to a sample C++ project where a rename breaks things. And maybe a recording of additional edits you have to do before to trigger this.

@0x6d6e647a
Copy link
Contributor

For what it's worth I've ran into this and it seems related to identifiers that are not namespace'd but are instead only separated by compilation unit. For example, I seen a project where there was enum foo { ... } specified in multiple compilation units but all in the global namespace. When renaming one of them all of them throughout the project were renamed. I don't think the issue is exclusive to the global namespace / compilation units though. In another instance I had two separate scoped enumerations: enum class Foo and enum class Bar but they both had an identifier BAZ in both. When I renamed BAZ using lsp-rename in Foo it was renamed in Bar as well.

If there is some interest I could produce some proof of concept demos to reproduce the behavior. I'm not sure if this is an lsp-mode issue or a clangd issue, as I have not used clangd in any other editors.

Since I've had this bite me a few times on a huge project, I tend to commit or stash my changes before attempting a rename. Not a real solution but an okay work around to not destroy work. However, as such the feature is still broken and unusable.

@dgutov
Copy link
Contributor

dgutov commented Oct 11, 2024

If there is some interest I could produce some proof of concept demos to reproduce the behavior.

Yes.

It might be useful to try to reproduce this in Eglot too, but PoC is the most important step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants