extending-language-services-configure-json-defaults.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!DOCTYPE html>
  2. <!-- THIS IS A GENERATED FILE VIA gulp generate-test-samples -->
  3. <html>
  4. <head>
  5. <base href="..">
  6. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  7. </head>
  8. <body>
  9. <style>
  10. /*----------------------------------------SAMPLE CSS START*/
  11. /*----------------------------------------SAMPLE CSS END*/
  12. </style>
  13. <a class="loading-opts" href="playground.generated/index.html">[&lt;&lt; BACK]</a> <br/>
  14. THIS IS A GENERATED FILE VIA gulp generate-test-samples
  15. <div id="bar" style="margin-bottom: 6px;"></div>
  16. <div style="clear:both"></div>
  17. <div id="outer-container" style="width:800px;height:450px;border: 1px solid grey">
  18. <!-- ----------------------------------------SAMPLE HTML START-->
  19. <div id="container" style="height:100%;"></div>
  20. <!-- ----------------------------------------SAMPLE HTML END-->
  21. </div>
  22. <div style="clear:both"></div>
  23. <script src="../metadata.js"></script>
  24. <script src="dev-setup.js"></script>
  25. <script>
  26. loadEditor(function() {
  27. /*----------------------------------------SAMPLE JS START*/
  28. // Configures two JSON schemas, with references.
  29. var jsonCode = [
  30. '{',
  31. ' "p1": "v3",',
  32. ' "p2": false',
  33. "}"
  34. ].join('\n');
  35. var modelUri = monaco.Uri.parse("a://b/foo.json"); // a made up unique URI for our model
  36. var model = monaco.editor.createModel(jsonCode, "json", modelUri);
  37. // configure the JSON language support with schemas and schema associations
  38. monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
  39. validate: true,
  40. schemas: [{
  41. uri: "http://myserver/foo-schema.json", // id of the first schema
  42. fileMatch: [modelUri.toString()], // associate with our model
  43. schema: {
  44. type: "object",
  45. properties: {
  46. p1: {
  47. enum: ["v1", "v2"]
  48. },
  49. p2: {
  50. $ref: "http://myserver/bar-schema.json" // reference the second schema
  51. }
  52. }
  53. }
  54. }, {
  55. uri: "http://myserver/bar-schema.json", // id of the second schema
  56. schema: {
  57. type: "object",
  58. properties: {
  59. q1: {
  60. enum: ["x1", "x2"]
  61. }
  62. }
  63. }
  64. }]
  65. });
  66. monaco.editor.create(document.getElementById("container"), {
  67. model: model
  68. });
  69. /*----------------------------------------SAMPLE JS END*/
  70. });
  71. </script>
  72. </body>
  73. </html>