microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.45k stars 1.53k forks source link

Implement prepareRename so rename isn't invoked on comments/strings/etc. #12619

Open mehlian opened 3 weeks ago

mehlian commented 3 weeks ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: When you try to fix typo in variable name or in comment using 'Code Spell Checker' extension then 'A definition for the selected symbol could not be loaded.' error popup shows up.

Steps to reproduce:

  1. Install 'Code Spell Checker' extension version 3.0.1
  2. Install 'C/C++' extension version 1.21.6
  3. open any .cpp or .h file
  4. create any comment with spelling mistake
  5. try to fix spelling mistake using bulb icon or ctrl+. shortcut
  6. pick correct word from popup
  7. error popup appears but spelling mistake is fixed
  8. repeat steps for any variable with spelling mistake

Expected behavior: No error popup should appear.

Configuration and Logs

none

Other Extensions

'Code Spell Checker' version 3.0.1

Additional context

No response

sean-mcmanus commented 2 weeks ago

I would say this is at least partially bug with the Code Spell Checker extension, because it seems like it's triggering a rename, which causes our extension's rename provider to be invoked. Do you get this error on a valid C++ variable?

However, it seems like this could also be partly our bug, because in TypeScript it shows a different error message saying that a comment or string cannot be renamed, while our extension pops up the rename dialog and then shows the "A definition for the selected symbol could not be located.".

sean-mcmanus commented 2 weeks ago

I just looked into our implementation -- we need to implement the vscode.RenameProvider.prepareRename at https://github.com/microsoft/vscode-cpptools/blob/main/Extension/src/LanguageServer/Providers/renameProvider.ts#L20 .

mehlian commented 2 weeks ago

I would say this is at least partially bug with the Code Spell Checker extension, because it seems like it's triggering a rename, which causes our extension's rename provider to be invoked.

This is a feature of 'Code Spell Checker' extension. It fixes spelling mistakes for variables, functions etc. by invoking 'Rename Symbol' function to fix all instances of this symbol in source code.