vscode-yaml
vscode-yaml copied to clipboard
Ability to specify schema as a comment in the YAML file
Is your enhancement related to a problem? Please describe.
A common problem with this extension is mis-detection of the correct schema. For example, a file named deploy.yml
is assumed to be a PHPDeployer file because this is the only match on JSON Schema Store.
Related issues:
- #397
- #354
- #123
- #62
The only way to override an incorrect schema is to set glob to schema mapping in the VS Code settings, but this means the settings can't easily be shared between developers or committed to version control.
Describe the solution you would like
It should be possible to insert a leading comment in a YAML file that declares its schema.
VS Code natively supports this for JSON files via a VS Code-specific $schema
property (because JSON doesn't support comments):
{
"$schema": "http://json-schema.org/draft-04/schema#",
...
}
In a YAML file, a comment could be used:
# $schema: https://json.schemastore.org/github-workflow
name: Foo
When this comment is present, this extension should skip fetching schemas from Schema Store and fetch the linked schema directly, if necessary.
Describe alternatives you have considered
I have no considered whether any other editors or IDEs support such a syntax for YAML file schema declaration. If they do, it would be worth trying to be compatible.
@johnbillion yaml-language-server already supports this Maybe we just need to add description in to vscode-yaml extension readme.
@evidolob Great! Thanks.
I just tried this and the schema wasn't detected correctly. It looks like #397 could be the same cause?
I can open a PR with updated docs for this once it's confirmed as working as expected.
I think yes, it could. As for #397 we have draft PR to fix schema selection https://github.com/redhat-developer/yaml-language-server/pull/362
Any PR is welcome.
Any updates on this? At this moment I even have zero feedback regarding which schema is used, if any at all. This extensions needs to expose the current schema being used on the status bar, so we would know if any was loaded or not, or if wrong one was used.
I even tried to see if there is any command exposed by YAML extension, that can be used to expose if something happened or not regarding validation but I was not able to find any.
While using the inline schema specifier, I seen that putting wrong url does correctly reports a failure to load the schema but I seen no proof of success when it worked, which is very important for those that are writing schemas.
Update: @johnbillion, @ssbarnea , I just tested this with an inline comment and it works. As mentioned by @evidolob , the comment format here works as expected.
I was able to make the language server recognise a specific format, overriding the auto-association based on the filename.
@evidolob, the impact that this issue is having is quite severe at the moment.
We currently don't have the ability to name our files with any name we want to because of #354 , as the language server reads the filename and incorrectly assumes a schema.
example,
create any valid yaml file and call it test.yaml. It will load just fine.
rename the file to noahsarc.yaml and it will try to load it as A JSON schema for OpenJS Architect (because it detects that the word arc
is in the filename.
This is really bad behaviour, as our users are complaining that yaml files aren't valid, and investigating bugs that don't exist.
Just disable the extension? I would, except that it's a dependency for the Visual Studio Code Kubernetes extension and has to be loaded.
There doesn't seem to be a way to tell the language server that the YAML file it is dealing with is a Kubernetes manifest
Could we also support something like ⬇️ ?
# yaml-language-server: $schema=none
to solve for:
- https://github.com/redhat-developer/vscode-yaml/discussions/768
Anything blocking this, considering there's an official representation of this?
There doesn't seem to be a way to tell the language server that the YAML file it is dealing with is a Kubernetes manifest
This seems to be still the case.
@madmalkav Please assign yourself and work on this. Thanks for taking this up.
Sorry, I’m not a native speaker and I think my comment was misleading, I have no knowledge to fix this myself. I have edited my comment to avoid further confusion.