robotcode icon indicating copy to clipboard operation
robotcode copied to clipboard

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

Open gohierf opened this issue 1 year ago • 1 comments

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):

  • VS Code Version 1.87
  • RobotCode Version 0.78.0
  • OS: Windows
  • Python Version 3.11.8
  • RobotFramework Version 7.0
  • robocop 5.0.3
  • robotidy 4.9.0

gohierf avatar Mar 14 '24 14:03 gohierf

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}

gohierf avatar Apr 04 '24 11:04 gohierf

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

d-biehl avatar May 09 '24 20:05 d-biehl

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"
]

gohierf avatar May 10 '24 06:05 gohierf

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).

bhirsz avatar May 10 '24 07:05 bhirsz