robotcodedev / robotcode

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

[BUG] VariableNotFound warning in keyword documentation section #135

Closed kivipe closed 1 year ago

kivipe commented 1 year ago

When I add Documentation section to a keyword, I get VariableNotFound error in examples. Documentation should be exempt from code analysis

Here is a sample resource file:

*** Keywords ***
MyKeyword
    [Documentation]    Sample keyword
    ...
    ...                *Examples*
    ...                | ${result}= | MyKeyword | Hello World |
    ...                | ${result}= | MyKeyword | ${logtext} |
    [Arguments]        ${message}
    Log                ${message}
    [Return]           OK

${result} and ${logtext} have three dots and hovering over them shows VariableNotFound.

Desktop

d-biehl commented 1 year ago

Hi Pekka,

sorry, this is not a bug, this hint is there to protect you from unexpected behavior. According to RobotFramework documentation (here and here), variables in the [Documentation] tag are replaced with the content at runtime, if the variable does not exist, the text remains as it is. This is to extend the documentation at runtime. To avoid accidentally replacing a variable in the documentation you should mask variables with a \ backslash.

I have extended your example and added screenshots to illustrate this...

This is what you get when somewhere a variable ${result} is defined (in the suite file or a global variable).

image

or this:

image

This is the correct way to define variables examples:

image

If you don't want to mask the variable, you can disable the hint, as well as all other error messages for a line by adding the comment # robotcode: ignore to the end of the line.

Something like this:

*** Keywords ***
MyKeyword
    [Documentation]    Sample keyword
    ...                *Examples*
    ...                | ${result}= | MyKeyword | Hello World |    # robotcode: ignore
    ...                | ${result}= | MyKeyword | ${logtext}  |    # robotcode: ignore
    [Arguments]        ${message}
    Log                ${message}
    [Return]           OK

but you should only do this if you really know what you are doing there.

I am currently in the process of completely reworking the code analyzer, there will then also be a finer settings to turn certain messages on and off.

If you have any other ideas about this...?

kivipe commented 1 year ago

Hi Daniel,

I have been using RF for a while and never noticed that feature. RF has dynamic features and they might cause unexpected behavior. It is good that RobotCode warns about this, and your workarounds are good. The only wish left is a bit better documentation for the next user.

d-biehl commented 1 year ago

Ok, then I close this issue and I will do my best, to write a "bit" more documentation :-)