Skip to content

Writing Robot Framework Code in VS Code

RobotCode analyzes your files the way Robot Framework reads them: it knows the libraries, resource files and variable files a file imports, and with them every keyword and variable the file can use. While you type, it uses that knowledge to complete, explain and check your code.

Completion appears as you type, or with Ctrl+Space. It offers what fits at the cursor:

  • Keywords of the file itself and of everything it imports, with the keyword's arguments and documentation beside the list.
  • Arguments of the keyword being called, such as named arguments like express=.
  • Variables after ${, @{ and &{, and environment variables after %{.
  • Imports: library names, the paths of resource and variable files, and the arguments of a library.
  • Section headers, settings and reserved tags such as robot:skip.
The completion list for 'Cart' in a test, with the keyword Cart Should Contain selected and its arguments and documentation shown beside the list.
The completion list for 'Cart' in a test, with the keyword Cart Should Contain selected and its arguments and documentation shown beside the list.

Keywords that are tagged robot:private and defined in another file are not offered, and deprecated keywords are offered struck through. The settings robotcode.completion.hidePrivateKeywords and robotcode.completion.hideDeprecatedKeywords change that.

While you type the arguments of a keyword call, the signature help shows the keyword's arguments and its documentation, and highlights the argument at the cursor. Ctrl+Shift+Space (Shift+Cmd+Space on macOS) opens it at any argument.

The signature help of the keyword Create Order above a call, with the argument quantity highlighted.
The signature help of the keyword Create Order above a call, with the argument quantity highlighted.

Hover over a keyword call to see the keyword's arguments and documentation, over a variable to see what kind of variable it is and, where RobotCode can resolve it, its value, and over the name of a library or resource file, for example in its import, to see its documentation.

The hover of the keyword Create Order, with its arguments product, quantity and express and its documentation.
The hover of the keyword Create Order, with its arguments product, quantity and express and its documentation.

A link in the hover opens the documentation in the Documentation Viewer.

Inlay hints show what the code leaves unsaid: the names of the arguments of a keyword call and the library or resource file a keyword comes from. By default, VS Code shows them only while you hold Ctrl+Alt (Ctrl+Option on macOS). To see them all the time, set editor.inlayHints.enabled to on for Robot Framework files:

settings.json
"[robotframework]": {
"editor.inlayHints.enabled": "on"
}
Two tests with inlay hints: the namespace orders. before the keyword calls and argument names such as product= and expected= before their values.
Two tests with inlay hints: the namespace orders. before the keyword calls and argument names such as product= and expected= before their values.

robotcode.inlayHints.parameterNames and robotcode.inlayHints.namespaces switch the two kinds of hints off separately.

RobotCode colors the code by its meaning: keyword calls, their arguments, variables, settings and comments each get their own color, and the namespace part of orders.Create Order differs from the keyword name. The colors come from your color theme. To change them, see Customizing Robot Framework Highlighting in VS Code.

A light bulb, or Ctrl+. (Cmd+. on macOS), offers quick fixes and refactorings at the cursor:

  • Create Keyword for a call of a keyword that does not exist: adds the keyword to the file.
  • Create local variable, Create suite variable and Add argument for a variable that is not found.
  • Assign keyword result to variable for a keyword call whose result is not assigned yet.
  • Extract keyword moves the lines selected in a test or keyword into a new keyword and calls it.
  • Surround with TRY...EXCEPT, TRY...FINALLY or TRY...EXCEPT..FINALLY wraps the lines selected in a test or keyword.
The quick fix menu at the misspelt keyword call Submit Ordr, offering Create Keyword 'Submit Ordr' and Assign keyword result to variable.
The quick fix menu at the misspelt keyword call Submit Ordr, offering Create Keyword 'Submit Ordr' and Assign keyword result to variable.

Refactor... in the context menu of the editor lists only the refactorings, for example Extract keyword and the Surround with entries for the selected lines.

Rename Symbol in the context menu of the editor, or F2, renames the keyword or variable at the cursor, at its definition and at every use RobotCode finds in the workspace. Keywords with embedded arguments cannot be renamed. For a keyword of a library and for built-in, imported, command-line and environment variables, RobotCode renames only the uses and tells you so.

Format Document (Shift+Alt+F on Windows, Ctrl+Shift+I on Linux, Shift+Option+F on macOS) and Format Selection, both also in the context menu of the editor, use the formatter of Robocop, with the Robocop configuration of your project. Install robotframework-robocop 6.0 or later into the Python environment of the project; without it, RobotCode reports that no formatter is available.

RobotCode: New Robot Framework File, also New Robot Framework File in the context menu of a folder in the Explorer and Robot Framework File under File → New File..., creates a suite file, a resource file or an __init__.robot file. In Robot Framework files, Tab inserts four spaces; robotcode.editor.4SpacesTab switches that off.

Released under the Apache-2.0. Copyright © 2022-present Daniel Biehl