Dec 07, 2017 | Zabil Maliackal

Language server protocol and DSL’s

Language server protocol and DSL’s

Gauge is a external DSL to express test behavior and data outside code. Unlike other external DSL’s for testing, Gauge is non-prescriptive because it uses Markdown. We’ve talked about this earlier.

Despite benefits of an external DSL like lesser code, readability, re-usability, etc., teams prefer building internal DSL’s with a programming language along with their IDE’s because it’s easier to manage code with code completions, refactoring, executions etc.

But it’s hard to write acceptance tests using internal DSL’s. As requirements change and test suites grow the need for uniformity and re-usability force teams to build custom frameworks that are tough to read or maintain.

Gauge wants to solve this problem, by bringing all the features you expect from an IDE to external DSL’s but without vendor lock-in. So we’ve designed Gauge to run for all popular languages, provided hooks to extend for a new language, created plug-ins for Visual Studio and Intellij IDEA.

But developing plug-ins for these IDE’s or working with their plug-in development SDK’s is, to put it mildly, a pain in the bum. We’ve duplicated features across IDE’s. It’s like re-writing something as complex as a compiler for every IDE. There’s got to be a better way.

Turns out there is. The team behind VS Code solved this by creating the Language Server Protocol. We can implement IDE features like code completion, jump to definition, references, diagnostics etc. outside VS Code. The protocol is an open standard that’s actively developed and adopted by other IDE’s and languages. With the latest Gauge release all IDE features are now built into Gauge instead of separate IDE plug-ins!

A new breed of plug-ins

With first class support for LSP, we also announce our new VS Code plug-in and official support for Gauge JavaScript plug-in. The new plug-in talks to Gauge as an LSP client delivering a great experience for authoring and maintaining tests.

To get started, install VS code, Gauge and run the following.

$ gauge init js
$ code --install-extension getgauge.gauge
$ code .

Let’s explore these LSP features!

Code lens

A code lens displays actionable info on Gauge specifications and implementations.

For e.g. opening example.spec in the sample project shows “Run Spec” and “Run Scenario” as a link above specifications and scenario headings. Clicking on it runs the specification or scenario and displays the result on the output pane. It’s a runnable (or executable) document!

Run specifications and scenariosRun specifications and scenarios

We’ve also added a code lens see all references of a step implementation across spec files. Use this to see how the step is used and quickly jump to specifications to modify or understand usage.

Diagnostics

The LSP diagnostics end point shows errors and warnings against a specification for quick feedback on parse or validation errors, unimplemented steps etc.

Code action

Fix errors using code actions, e.g. generating stubs for steps that are not implemented yet.

Code completion

Get suggestions via code completion while editing specs. The language server auto completes, steps, concepts, parameters (step, table and file) etc.

Goto to definition

The goto to definition LSP end point, associates a step to it’s implementation for quick navigation or peek into the code behind a step.

Formatting

Tidy up specs and concepts using the format end point.

Other editors

It’s easy to hook up your favorite editor with Gauge. The community are writing clients and tools for all popular editor. The Visual Studio team (not to be confused with VS Code) just released a preview for version 2017.

We tested these features on vim/neovim using a language client plug-in and it worked out of the box!

The future

Over the coming months, we are adding a bunch of useful features to Gauge and expose them via LSP. We appreciate your feedback, please log issues or suggestions!

Happy testing.

Gauge is a free and open source test automation framework that takes the pain out of acceptance testing. Download it or read documentation to get started!

Language Server Protocols and DSLs from r/getgauge