We at GoodData are pioneering the concept of treating analytics as code. This lets you apply the identical rules, which Software program Engineers have practiced for a very long time.
We determined to make use of YAML as a cornerstone for our analytics code. All in favour of why? Then test my article 5 Causes Why to Write Your Semantic Layer in YAML.
The primary query for this text is: Is there a chance that YAML would really feel like a full-fledged programming language? We consider there may be with the VS Code extension we’ve developed. Let’s discover the extension collectively.
1. Semantic syntax highlighting
You would possibly ask what sort of syntax highlighting we may presumably add for the configuration format corresponding to YAML. Effectively, you bought some extent there, there are many YAML extensions already and a lot of the IDEs even assist YAML out of the field. However our syntax highlighting goes means past YAML. We’re utilizing Semantic highlighting for our Area-specific language (DSL), which we’re constructing utilizing the YAML format.

2. Semantic code validation
Our extension mechanically validates the YAML construction in opposition to our schemas, so VS Code can instantly notify the person when one thing is flawed.
However let’s not cease there. We’re additionally validating referential integrity, so that you don’t should be afraid of utilizing invalid or unsuitable variables or identifiers. VS Code calls this Diagnostics.

3. Interoperability with different languages
Mixing a number of languages collectively in a single file may not be a very good software program engineering follow, however let’s admit it: on the earth of analytics, it’s a frequent follow. Listed below are examples of utilizing SQL in Dice measures and Looker fields. We offer in-line assist for SQL and for our personal question language (MAQL), together with syntax highlighting and validations.
The interoperability may be improved even additional by shifting the SQL or MAQL code to a separate file after which referencing it.

4. IntelliSense
I personally contemplate IntelliSense (or autocompletion) as among the best productiveness boosters when coding. For our use case, we’ve added a extremely subtle model of IntelliSense to YAML. We didn’t cease at YAML buildings; we’ve additionally added assist for user-created entities (e.g., metrics and visualizations). Does it begin to really feel such as you would write in a full-fledged programming language as an alternative of YAML?

5. Preview
Let’s admit it, analytics are extremely visible and customers wish to see and validate their code as typically as doable. It jogs my memory of my time on the college after I was writing in LaTeX. Having a preview proper subsequent to the code is a pleasant function that reduces context switching whereas retaining the effectiveness of an IDE. Preview can also be invaluable when debugging the code.
For our preview, we used the Webview API.
To assist the discoverability of the preview, we’re utilizing a VS Code function known as CodeLens. This function shows the preview motion within the code, one click on away.

6. Go to definition
I assume you all know this performance out of your IDEs. Simply Ctrl+Click on on the variable identify to open its definition. To be trustworthy, we haven’t carried out this in our extension but. However we all know it’s doable and, based mostly on our exploration, it needs to be fairly simple.
7. Code snippets
Including a snippet is a simple option to effectively create a big chunk of code. VS Code snippets may be additional enhanced by:
- Tabstops for person enter.
- Placeholders with default values.
- Selection choices for these placeholders.
- Utilization of variables.
All of this may be packed and delivered as part of the extension. We first began with world snippets (project-scoped) however ultimately changed this implementation with context-aware snippets. Think about a mix of snippets and IntelliSense.
8. Command palette
IDEs are all in regards to the effectiveness of writing code. Together with including as a lot keyboard-accessibility as doable. A very powerful key mixture in VS Code is Ctrl+Shift+P, which brings up the Command Palette. From there, you could have entry to all the performance of VS Code, together with keyboard shortcuts for the commonest operations.
Due to this fact, including analytics-as-code associated instructions was solely pure and improved our developer expertise. Actually, most of our instructions mirror the code lifecycle – significantly cloning or deployment, which might in any other case require a CLI device.
Tip: Remember to clearly talk which instructions belong to your extension. We use the prefix “GoodData:” in all of the command names.
Conclusion
Doing a customized DSL is a difficult process that with out handy tooling can simply result in a nightmare. Luckily, these days, IDEs (particularly VS Code in our expertise) permit us to ship an expertise we’ve beforehand related solely with languages natively supported by IDEs.
A lot of the options introduced listed below are part of the language server extension we’ve carried out. All in favour of creating your personal DSL? Then test the Language Server Extension Information
Wish to take a look at what we’re cooking at our GoodData Labs? Join GoodData Labs! An area the place you’ll be able to take a look at and expertise superior analytics concepts and options which can be at present in improvement.