Language Server Protocol for Robot Framework
What is the Language Server Protocol (LSP), and why is it useful?
Language Server Protocol (LSP) provides developers with an open protocol for programming language support in integrated development environments (IDE) and source code editors. LSP allows that support to be created and distributed outside any specific type of IDE or editor. The Language Server Protocol is used between an editing tool (client) and the language support provider (server) to integrate various types of useful features. Some common feature examples integrated through LSP are tooltips, code completion, find-references, and jump-to-definitions. Having a separate language server for LSP allows other communities that specialize in client or editor development to concentrate on delivering better extensions or plugins.
How can I start using LSP with Robot Framework?
Getting started with LSP and Robot Framework can be done using Visual Studio Code’s robotframework-lsp extension. This requires Python 3.7 or higher, and Robot Framework 3.2. After you have installed Visual Studio Code editor, go to the Marketplace website or look for it in the Extensions search bar.
Note: If you have other Robot Framework extensions enabled, it might be a good idea to try and disable them if you are having issues with getting
robotframework-lsp
to work.
Configuration
Once you have installed the extension, you need to configure it properly. Go to the Extension Settings by clicking the gear button on the robotframework-lsp extension. From the Settings window fill in the field marked Robot > Language-server: Python
with the full path to your Python executable.
If your robot script imports resources from other directories (keyword files, Python library files), you can add those directories to the Python path by configuring the Robot: Pythonpath
setting. This makes the imported resources available for auto-completion and run configurations. In the following example, we are adding three directories to the Python path in the settings.json
file.:
...
"robot.pythonpath": [
"/path/to/my/robot/libraries",
"/path/to/my/robot/resources",
"/path/to/my/robot/variables"
],
...
How does robotframework-lsp
make things easier?
The features include code completion, syntax highlighting and validation, code formatting, go-to-definition, signature help, and more!
Keywords code completion
Syntax highlighting and validation
Section settings code completion
Section headers code completion
Signature help
Launch .robot
files with the Run button:
Using the Run button to launch your Robot Framework script requires the following steps to be configured properly.
- From the top menu, select
Run
->Add Configuration...
. Alaunch.json
file is opened in the editor. - Select the
{} Robot: Launch .robot file
option in the pop up. - Save the changes made to
launch.json
. - Open your main
.robot
script file, or select the tab for that file, if it is already open. - In the icon toolbar on the left, click on the Run icon (fourth from the top).
- Click the green Run button next to
Robot: Current File
dropdown. - After clicking the green Run button, the Debug Console should display similar output shown in the following screenshot.
Summary
The Language Server Protocol provides software robot developers with Robot Framework language support for various editors and IDEs. This can be a helpful addition to your task automation toolbox while you are experimenting with different keywords.