Question

LookML VSCode Extension - Syntax Highlighter

  • 22 March 2021
  • 1 reply
  • 69 views

Userlevel 6
Badge

After having read this topic: 

 many times, I decided to give it a shot. I was told by Looker Staff that they can’t share the regular expressions for the grammar for internal reasons and, as suspected, the red tape due to being sold to Google. 

I tried to do it on my own in my spare time since it seemed like a cool project. I did it with the help of the code that Ladvien has already written (https://github.com/Ladvien/vscode-looker)

 

This is just a first try and proof of concept. The colours are crazy just so that I can easily differentiate between different patterns :) In terms of grammar recognition I believe It’s close to what we have in the LookML editor, and perhaps slightly more. (recognising the SQL in SQL parameters (where we could use SQL grammar recognition that I think Ladvien had in mind), values in arrays, and so on)

Let me know what other things would be useful in terms of syntax highlighting and here is a list of what I’ve done so far:

  1. Scopes (anything that has opening and closing bracket {}) - would apply to view,  explore, parameter, dimension, measure, set
    1. Type - yellow
    2. Name  green
  2. SQL Parameters - any line that starts with sql and finishes with ;;
    1. Name of the parameter - orange
    2. Value - red
      1. Liquid - pink
      2. LookML variable or field reference - purple
  3. Parameters - all other parameters
    1. Name - blue
    2. Value - lighter blue
      1. Strings - brown
      2. Yesno - Pink-ish
      3. Array - light purple
      4. Variable - purple

Did not colourise the parenthesis as I’m using a separate extension called Bracket Pair Colorizer 2 that works in all languages and helps me identify matching parenthesis.

 

Let me know if there’s anything else that would be useful in the syntax highlighting and whether it’s a plugin that you would be useful for you. I’m still learning the grammar and how to name and reference it properly. 

 

These are the settings that then can be used to change colours of the different part of the syntax:

 


1 reply

I’d be interested in contributing to this if you have a public repo!

Reply