Skip to content

[QUESTION] Hovering over imported dictionary variables in VSCode #673

Open

Description

@ruedrot

Hello!

I have a question about using dictionary variables in our tests.

In our project, we use a YAML file containing variables and import it in the Settings section using:

Test.robot

*** Settings ***  
Variables    Variables.yaml

Variables.yaml

FIRST_MESSAGE_TRANSMITTED: 5
HA:
   UNIT_ID_MASTER: 1
   UNIT_ID_SLAVE: 2

These variables are often dictionaries. However, when hovering over them in VS Code, their contents are not resolved and displayed. We also cannot navigate to their definitions in the YAML file using F12 (Go to Definition).

What would be the preferred way to model such variable structures so that their contents can be displayed on hover in VSCode and navigation to their definitions?

Best regards

  • VS Code [1.142.0]
  • RobotCode Extension [2.7.0]
  • OS: [Debian 13]
  • Python [3.13.5]
  • RobotFramework [7.4.2]
  • Robocop [8.2.10]

Activity

  1. d-biehl commented on Oct 19, 2026

    @d-biehl
    Member

    What you see are limitations of RobotCode:

    • Hover: From variable files (YAML, JSON and Python alike), RobotCode only shows simple values: strings, numbers, booleans and None. Dictionaries and lists can hold anything and get arbitrarily large and deeply nested, so for stability and security reasons RobotCode deliberately doesn't keep their values. That's why ${FIRST_MESSAGE_TRANSMITTED} shows 5, but ${HA} shows no value.
    • Go to Definition: RobotCode reads variable files with Robot Framework's own importer, so they behave exactly as in a real run. That importer only returns names and values, no line numbers, so F12 opens the YAML file, but always at the first line instead of at the key (see also [BUG] Using variables from Python files in Robot Framework does not navigate to the correct line #428).
    • Completion: RobotCode doesn't complete dictionary items, or attributes and methods of objects. So far that has been too much work to implement; I work on RobotCode alone in my spare time.

    The better way is to use plain variables with sensible names, using _ to group them:

    HA_UNIT_ID_MASTER: 1
    HA_UNIT_ID_SLAVE: 2

    RobotCode completes these and shows their value on hover. If you also want F12 to jump to the exact line, define them in the *** Variables *** section of a resource file instead.

    Whether that fits depends on what's in your data and what you do with it. For long lists such as web locators, there may also be designs that don't need variables at all.

    What do your YAML files actually contain, and what do you use the values for?

  2. ruedrot commented on Oct 20, 2026

    @ruedrot
    Author

    First of all, thank you very much for your quick response.

    Defining the variables as plain variables seems to be the most practical solution if we want their contents to be displayed when hovering over them. However, defining them in the Variables section is not an option for us because we reuse them across many different test suites. The values may also change in the future, and our goal is to have a single source of truth so that any changes only need to be made in one place. We use these variables to improve the readability of our test cases when evaluating Python expressions as well, for example:

    path/to/value/1 == ${HA}[UNIT_ID_MASTER]
    

    Thanks to RobotCode's syntax highlighting, the variables are displayed in a very readable way, and this notation has certain advantages over plain variables, although that may ultimately come down to personal preference.

    Image

    However, defining complex data structures as dictionaries is very useful, as it significantly improves readability in YAML or Python files. Combined with RobotCode's syntax highlighting, it results in a very elegant solution. If there is no way to display the contents of these variables in VS Code, we will probably have to follow your suggestion and switch to plain variables instead.

    Of course, it is understandable that implementing such functionality would require a significant amount of effort, and we are aware that you maintain RobotCode on your own. By the way, you're doing a great job. I have personally been using your extension for years, and I really appreciate your work. Thank you for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions