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
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 thecontributes
. The syntax is the exact same ofjsonValidation
.If you’re using an extension based on Red Hat’s YAML Language Server such as
redhat.vscode-yaml
, then use theyamlValidation
contribution point. The contribution point in the extension manifest has the same shape as VS Code’s builtinjsonValidation
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.