robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
168 stars 13 forks source link

[BUG] Rename Symbol resulting in invalid python code. #244

Open gohierf opened 3 months ago

gohierf commented 3 months ago

Describe the bug "Rename Symbol" (Right click on variable name, or F2) is a great feature, but it does not rename properly in Python evaluations: it removes underscores that are necessary to have valid python variables.

To Reproduce Steps to reproduce the behavior:

  1. Right click on a variable which is also used in a inline python statement elsewhere.
  2. Click on "Rename Symbol".
  3. Add a space in the new variable name.
  4. The python code variable is not found because python does not support space in variable names.

If possible add some example source code like:

*** Variables ***
${MY VARIABLE}      foo

*** Test Cases ***
A Test Case
    Log    ${MY VARIABLE}
    IF    len($MY_VARIABLE)>=3    No Operation

Expected behavior The spaces in the variable could be automatically converted to underscores in the resulting inline python code.

Screenshots/ Videos BEFORE image

AFTER image

DESIRABLE image

Desktop (please complete the following information): VS Code Version 1.87.2 RobotCode Version 0.78.4 OS: Windows Python Version 3.11.8 RobotFramework Version 7.0

Additional context As a side note, it might be useful to deny multiple space in these symbol renaming because it will result in RobotFramework considering it as multiple symbols rather than a single variable or keyword. It is then not possible to use rename symbol again to perform the rollback operation. Which could be fixed by a Ctrl+Z, except that the renaming is done on multiple files, while Ctrl+Z only works on the current file.

d-biehl commented 2 months ago

Sorry for the late answer, had some busy weeks...

Yes this is a bug and I will try to fix it.

At the moment I would say, dont use Spaces in Variable Name ;-)

About your additional context:

If you rename something that changes several files, Undo (Ctrl+Z) should work for all files changed before