visual-studio-codeyamlvscode-extensionssyntax-highlighting

How to associate KQL syntax with a YAML property in VSCode


I often have scenarios where I have a file using a data format (e.g. YAML, JSON) within which I have some property that needs to store a code snippet (e.g. KQL, SQL, JS, etc). Is there a way for me to setup syntax support for both languages? I realise that may be contradictory since the inner code is just a string from the parent document's perspective, but perhaps I could specify where this string value is more than a string; e.g. for YAML documents I could use YAML tags to specificy language support requirements.

To make a less open ended question: How could I implement syntax support (e.g. syntax highlighting) for KQL within YAML?

As an example, my YAML may look like this (the !kql tag is just a suggestion of how I'd flag this field as requiring KQL support vs being an arbitrary string value).

name: stack overflow demo
description: |
  Lists all virtual machines
  Note: this is just an arbitrary multi-line string
query: !kql | 
  resources |
  where type =~ 'microsoft.compute/virtualmachines'
  // Note: this is a multi-line string which is also a valid KQL query

Solution

  • Theres a couple extensions providing that functionality.
    ruschaaf.extended-embedded-languages
    harrydowning.yaml-embedded-languages
    marketplace
    if they don't support your language, simply just ask them in their github repos