skip to Main Content

I am writing a CLI tool that will have a fairly complex YAML configuration, so I wanted to create a VS Code extension to support that with completion provided by the JSON Schema and some snippets, but it seems not to work. I thought it would be useful to define a custom extension ".lake" for my config file.

This is my package.json:

{
  "name": "lake-config",
  "displayName": "Lake Configuration Helper",
  "publisher": "essay97",
  "description": "Provides schema validation and snippets to configure Lake",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.80.0"
  },
  "categories": [
    "Other"
  ],
  "activationEvents": [],
  "main": "./extension.js",
  "contributes": {
    "languages": [
      {
        "id": "yaml",
        "extensions": [
          ".lake"
        ],
        "aliases": [
          "Lake Config"
        ]
      }
    ],
    "jsonValidation": [
      {
        "fileMatch": "**/*.lake",
        "url": "./lake-schema.json"
      }
    ]
  },
  "scripts": {
    "lint": "eslint .",
    "pretest": "npm run lint",
    "test": "node ./test/runTest.js"
  },
  "devDependencies": {
    "@types/vscode": "^1.84.0",
    "@types/mocha": "^10.0.3",
    "@types/node": "18.x",
    "eslint": "^8.52.0",
    "glob": "^10.3.10",
    "mocha": "^10.2.0",
    "typescript": "^5.2.2",
    "@vscode/test-electron": "^2.3.6"
  }
}

When I try to open an extension development host with F5 and open a .lake file, I get the YAML syntax highlighting, but not the JSON Schema, the bottom bar says "no json schema".

What am I missing? I even tried to set the jsonValidation.url to a random JSON schema from the internet to make sure it was not a problem in my schema but it’s still not working.

Also: I’m not sure if I should depend on redhat.vscode-yaml. extension and what extensionDependencies does exactly.

2

Answers


  1. Chosen as BEST ANSWER

    I ended up finding out that since the file I am trying to validate is YAML, it is handled by the YAML extension. In oreder to make it work I added to the package.json the yamlValidation block inside the contributes. The syntax is the exact same of jsonValidation.


  2. If you’re using an extension based on Red Hat’s YAML Language Server such as redhat.vscode-yaml, then use the yamlValidation contribution point. The contribution point in the extension manifest has the same shape as VS Code’s builtin jsonValidation contribution point.

    The relevant issue ticket which tracked this feature is Consider providing a ‘yamlValidation’ contribution point for registering a schema #37. The feature was implemented by commit 9fdaa7f and released in version 0.0.3.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search