Snapcraft schema validation in VSCode

With a PR that I’ve added to snapcraft when merged, you’ll be able to use the defined schema to validate your snapcraft.yaml files as you write them in Visual Studio Code.

image

First, you need to install the YAML extension into visual studio. To do that, in Visual Studio Code, type ctrl+p and then ext install redhat.vscode-yaml followed by the enter or return key.

Next in VSCode type ctrl+shift+p and then open user settings followed by enter. In the new ssettings window click the {} symbol on the top-right of the window to open the JSON file. At the end of the file add the following code to use the copy of the schema that I have posted onto people.ubuntu.com (if there are entries already present then suffix the last one with a comma and add this snippet below that - it needs to be nested within the outermost { and }):

"yaml.schemas": {
    "https://people.ubuntu.com/~diddledan/snapcraft-schemas/snapcraft-master.json": "**/snapcraft.yaml"
}

This copy of the schema is from the master branch so it might include some syntax that is not currently supported by mainline snapcraft.

7 Likes

I love this soooo much.

1 Like

You should not need that setting anymore.

One last tidbit, if using PyCharm, or I suspect any of the following:

  • IntelliJ IDEA
  • PhpStorm
  • Rider
  • RubyMine
  • WebStorm

things should work out of the box, take this fresh installation of https://snapcraft.io/pycharm-community: imagen

2 Likes

What magic is this? Just wondering if I can adapt it…

if it doesn’t work out of the box for your chosen editor without manually added the schema location, I advise that you don’t configure with the people.ubuntu.com address I posted above. Instead, use the local file path to your snapcraft installation - e.g. if you have the snap the schema is at /snap/snapcraft/current/share/snapcraft/schema/snapcraft.json.