You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Masahiro Miyashiro (3846masa), Kelvin Jones, Denis Barushev, vandalouze, Dominik K., Alexander Trauzzi, Adam Voss, Dean Sofer, David Op de Beeck, Vojtěch Habarta and 40 more
Reacted by Willian Krueger, Kelvin Jones, Denis Barushev, vandalouze, Pascal Iske, Mick Dekkers, Osman Zeki, Mat Simon, Jakub Čábera, Doug Tangren and 2 more
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 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.
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.
Reacted by Mohsen Azimi, Karel Jakubec, Leif Shackelford, Alexander Trauzzi, J.P. Illanes, Kevin Wiesmüller and Nathan Friend
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:
better validation handling of null values
document symbol search (ctrl+shit+o)
description hover information (when provided by schema)
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).
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.
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?
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
Adam Voss (@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.
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!
Activity
[-]Support JSON Schema for YAML files also[/-][+]Support JSON Schema for YAML files[/+]egamma commentedon Dec 11, 2015
Martin Aeschlimann (@aeschli) fyi
mohsen1 commentedon Feb 9, 2016
I'm eager to implement this. Can you point me to where can I start?
aeschli commentedon 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:
extensions/jsonfolder, also runnpm installin that folder, press the 'run' button in the debug viewletdjabraham commentedon Apr 15, 2016
Mohsen Azimi (@mohsen1) Have you done any work in this regard yet?
mohsen1 commentedon Apr 15, 2016
Daniel Abraham (@djabraham) no. Never found the time to do this
djabraham commentedon Apr 22, 2016
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.
aeschli commentedon Apr 22, 2016
Daniel Abraham (@djabraham) Awesome! Let me know if I can help!
adamvoss commentedon Jun 20, 2017
Daniel Abraham (@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.schemassetting 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 commentedon Jun 20, 2017
Adam Voss (@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 commentedon Jun 20, 2017
Daniel Abraham (@djabraham) Thanks! To avoid spamming this thread, I'll respond on your linked issue.
purefan commentedon 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 DefaultLambdaTimeoutIs there a quick way to add this to the current yaml formatter?
adamvoss commentedon Oct 19, 2017
Miguel Espinoza (@purefan) see adamvoss/vscode-yaml#16, specifically this comment.
Dominik-K commentedon 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.
Adam Voss (@adamvoss) Daniel Abraham (@djabraham) You want to share forces with them, maybe?
djabraham commentedon Mar 27, 2018
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
Adam Voss (@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 commentedon 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!