Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSON Schema for YAML files #1176

Closed
mohsen1 opened this issue Dec 10, 2015 · 15 comments
Closed

Support JSON Schema for YAML files #1176

mohsen1 opened this issue Dec 10, 2015 · 15 comments
Labels
feature-request Request for new features or functionality json JSON support issues
Milestone

Comments

@mohsen1
Copy link

mohsen1 commented Dec 10, 2015

It's getting more common to use YAML for configuration. For example docker-compose.yml or Swagger files are usually written in YAML. The JSON Schema based autocomplete for JSON files is a neat feature, please enable that for YAML files also.

@mohsen1 mohsen1 changed the title Support JSON Schema for YAML files also Support JSON Schema for YAML files Dec 10, 2015
@egamma egamma added the feature-request Request for new features or functionality label Dec 11, 2015
@egamma egamma added this to the Backlog milestone Dec 11, 2015
@egamma
Copy link
Member

egamma commented Dec 11, 2015

@aeschli fyi

@mohsen1
Copy link
Author

mohsen1 commented Feb 9, 2016

I'm eager to implement this. Can you point me to where can I start?

@aeschli
Copy link
Contributor

aeschli commented Feb 9, 2016

You basically have to implement an extension that adds a validation support for YAML.
In there you can implement the validation logic yourself, as JSON does it, or delegate to another executable. If you implement the validation logic yourself in TypeScript/JavaScipt, you'd do that as a language server. A language server performs the validation in it's own process.

To see that in action, have a look at the JSON extension at (https://github.com/Microsoft/vscode/tree/master/extensions/json).
To try it out:

  • open a VSCode window on the extensions/json folder, also run npm install in that folder, press the 'run' button in the debug viewlet
  • a new VSCode window opens, where you can open a JSON file and associate a schema to it
  • to debug the validation code, additionally open a VSCode window on the 'server' folder, and use the 'attach' option in the debug viewlet.
  • Check out the jsonParser.ts code that creates an AST out of the JSON document and contains the 'validate' functions that verify a node against the JSON schema.

@djabraham
Copy link

@mohsen1 Have you done any work in this regard yet?

@mohsen1
Copy link
Author

mohsen1 commented Apr 15, 2016

@djabraham no. Never found the time to do this

@djabraham
Copy link

I Friken Love YAML

..so I gave it a try.

https://github.com/djabraham/vscode-yaml-validation

https://marketplace.visualstudio.com/items?itemName=djabraham.vscode-yaml-validation

Uses the well known js-yaml parser with some TS types added, converts the returned structures to their JSON AST Equivalent, and then uses the standard JSON validation already built into VS Code. The excellent example cited above, is actually the source for that validation.

This still needs some work, because the completions aren't being returned. But basic validation seems to be working. I will put some more time into it, when I can.

screen shot 04-21-16 at 08 31 pm

screen shot 04-21-16 at 08 30 pm

@aeschli
Copy link
Contributor

aeschli commented Apr 22, 2016

@djabraham Awesome! Let me know if I can help!

@adamvoss
Copy link

adamvoss commented Jun 20, 2017

@djabraham Thanks for showing this is possible!!

I wanted to add more functionality, but thought more good could come long-term with less forking. The result was that I wrote vscode-yaml (marketplace) (GitHub).

From the user perspective, I believe it provides all the functionality of vscode-yaml-validation plus:

I kept the same design decision to use the json.schemas setting key, so it should function as a drop-in replacement for vscode-yaml-validator.

Sadly, no completion in this extension either. It was more-or-less working, but all the suggestions generated JSON. While the JSON was valid YAML, it was not what anyone would want, so I disabled it. My determination was that it would be best to write the suggestion code from scratch rather than trying to "patch" the code from vscode-json-languageservice. I spent more time on this than I anticipated and I'm not sure I am not sure I will ever get around to completion. (PRs welcome of course).

Out of convenience it forks vscode-json, which is just the piece that wires the service to the VS Code client. It takes a source-level dependency on vscode-json-languageservice to be access some internal types. Otherwise, it doesn't fork its dependencies. This caused submitting one upstream bug fix microsoft/vscode-json-languageservice#7 and I have submitted the scalar classification code written for this to the upstream parser library possible future inclusion (mulesoft-labs/yaml-ast-parser#14).

@djabraham
Copy link

@adamvoss

I like the fact that validation is integrated with completion and formatting. That makes perfect sense. It's good to see major progress, cause I love the YAML format. Especially for schema files and Kubernetes configs.

One Q, do you plan to eventually add support for multiple yaml (concatenated) files? That seems to be a major pain point for advanced users. I started restructuring the repo in another branch, per the latest JSON validation project and the MS example for newer Language Server; but a new position currently demands focus and I kept putting it off.

djabraham/vscode-yaml-validation#2

Thanks regardless, and nice work!

@adamvoss
Copy link

@djabraham Thanks! To avoid spamming this thread, I'll respond on your linked issue.

@purefan
Copy link

purefan commented Oct 6, 2017

Good stuff! My use-case is however slightly different, Im looking for a serverless intellisense formatter, its basically yaml + keywords that start with !Ref, for example:
Timeout: !Ref DefaultLambdaTimeout

Is there a quick way to add this to the current yaml formatter?

@adamvoss
Copy link

@purefan see adamvoss/vscode-yaml#16, specifically this comment.

@Dominik-K
Copy link

Dominik-K commented Mar 26, 2018

FYI: Another option would be the YAML Support by Red Hat extension. The underlying yaml-language-server integrates all schemas from the JSON Schema Store. Kubernetes schema is currently included from a Gist.

@adamvoss @djabraham You want to share forces with them, maybe?

@djabraham
Copy link

My extension was retired a while back. It looks like the vscode-yaml extension of Adam's was also recently retired. The RedHat extension was a possible factor: adamvoss/vscode-yaml#23

@adamvoss You guys did great work in a much needed area. I hope experience gained from growing a team and any new skills you've acquired, serve you well into the future.

Many thanks to those who create new inroads for technology, and to those who broaden them. You've helped great many travelers, from getting mired down.

@aeschli
Copy link
Contributor

aeschli commented Oct 28, 2019

No plans on our side to add this functionality given that there are extensions implementing it already. I'll continue to open up the vscode-json-languageservice so it can also be used for other parsers that the JSON parser. If there's anything missing please file issues!

@aeschli aeschli closed this as completed Oct 28, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality json JSON support issues
Projects
None yet
Development

No branches or pull requests

8 participants