robotcodedev / robotcode

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

[BUG] argument shown as "variable not found" in keyword documentation #240

Closed gohierf closed 6 months ago

gohierf commented 8 months ago

Describe the bug A "variable not found warning" is shown when referring to a keyword argument in the keyword's documentation.

To Reproduce It only appears if [Arguments] is defined after [Documentation] (which is by default enforced by tidy).

*** Keywords ***
My Keyword ${embedded argument}
    [Documentation]    This keyword has an ${embedded argument} and a ${regular argument}
    [Arguments]    ${regular argument}
    Log    ${embedded argument}
    Log    ${regular argument}

Another Keyword ${embedded argument}
    [Arguments]    ${regular argument}
    [Documentation]    This keyword has an ${embedded argument} and a ${regular argument}
    Log    ${embedded argument}
    Log    ${regular argument}

Expected behavior Even if the [Arguments] is defined after [Documentation], the variable should be shown as "(argument) | ${regular argument}". Which is the case when [Arguments] is defined before [Documentation].

Screenshots/ Videos image

Desktop (please complete the following information):

gohierf commented 8 months ago

It is not just for [Documentation], I get the same error with a "configurable user timeout", where the timeout of a keyword is provided as an argument of this keyword.

Robotidy sets the [Timeout] before the [Arguments] entry, which results in both "variable not found" error and "argument not used" warning from RobotCode.

image

Configurable Timeout Before
    [Documentation]    Timeout entry before Arguments entry (enforced by Robotidy)
    [Timeout]    ${timeout}
    [Arguments]    ${arg}    ${timeout}
    Log    ${arg}

Configurable Timeout After
    [Documentation]    Timeout entry after Arguments entry
    [Arguments]    ${arg}    ${timeout}
    [Timeout]    ${timeout}
    Log    ${arg}
d-biehl commented 6 months ago

ok, after some investigation, this is a little bit tricky, arguments from keywords in documentation and tags are not resolved by robotframework, here are only global or suite variables allowed.

All other settings are resolved at runtime after parsing, need to think how to implement this.

in the meantime, do you know the robotidy OrderSettings setting, maybe that helps.

Regardless of the bug, I'm not sure if the default order of robotidy is a good order, I think the arguments should be at the top and then the documentation and all other things. In Python you also have to specify the name of the function and the parameters first and only then comes the documentation

gohierf commented 6 months ago

Thanks for the tip, setting arguments before any other keyword settings did fix my issue.

[tool.robotidy]
configure = [
    "OrderSettings : keyword_before = arguments,documentation,tags,timeout"
]
bhirsz commented 6 months ago

I personally like documentation first, then arguments, but it may be personal preference :) I will think about it, but I will for sure update the default order for timeout to avoid such issues in the future (and put some explanation in the documentation why exactly I chose that order).