robotcodedev / robotcode

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

[ENHANCEMENT] Python Syntax Highlighting in Robot Framework Files #230

Open gohierf opened 4 months ago

gohierf commented 4 months ago

Is your enhancement request related to a problem? Please describe. The absence of syntax highlighting for Python statements in Robot Framework files hinders code readability and increases the likelihood of errors.

Describe the solution you'd like Integrate syntax highlighting for Python statements in Robot files, using a distinctive color scheme to enhance visibility and comprehension.

Note Partially related to #229

gohierf commented 4 months ago

Python Syntax Highlightning in special keywords like Evaluate, Run Keyword If, etc.

It is implicitly mentioned in "etc." but it looks like most of the keyword ending by If can receive a python expression. As well as Should Be True and Should Not Be True.

But what about the keywords which are not in BuiltIn? Like for Browser library assertions, or even custom libraries. Could this be implemented?

Python Syntax Highlightning in IF Statements

No "etc." here, so I would like to add that WHILE is also evaluating python expression.

d-biehl commented 4 months ago

@gohierf and @touchedthecode published a new version with support for python syntax in IF and WHILE expressions. Can you please test it and give me a short feedback?

I have released a new version with support for Python syntax highlighting in IF and WHILE expressions. Can you please test it and give me some feedback?

I'm not sure how to do the highlighting for keywords yet, it might take a while. Because I have to find out whether the keyword is really the keyword, these can also be nested arbitrarily, i.e. Run Keyword If $a==1 Should Be True $b==2 ELSE Should Be False $c==3 this has a significant performance impact on the highlighting.

As a workaround you can also use an inline python expression variable, something like this:

*** Test Cases ***
forth
    VAR  ${a_var}  1
    Should Be True     ${{ $a_var == '1' }}
gohierf commented 4 months ago

Hei Daniel, nice work! It looks good on my side. I will keep an eye open on the topic, but so far no problem!

gohierf commented 4 months ago

Well actually here is something: image

In IF statements the $ has a different color than the variable name.

In ${{}} expressions the $ has the same color than the variable name.

It is somewhat disturbing and would be better if homogeneous.

gohierf commented 4 months ago

Also, I see that you have fixed the ${{}} being red sometimes (and thanks for that too).

But it was nice when all five characters of ${{...}} had the same color, it was more obvious that it was the same "symbol", now it is a bit heavier to read...

Sorry to be picky, I hope it reads as constructive feedback.

d-biehl commented 4 months ago

I cannot really do this, because that's depending of VSCode editor.bracketPairColorization.enabled setting, wich is enabled by default, and also by the color theme you are use. one of the main problems is that VSCode's Bracket Pair Colorization algorithm does only work with single characters, if I define a bracket pair like ["${{", "}}"] then it works not correctly.