extending-language-services-configure-javascript-defaults.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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="X-UA-Compatible" content="IE=edge" />
  7. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  8. </head>
  9. <body>
  10. <style>
  11. /*----------------------------------------SAMPLE CSS START*/
  12. /*----------------------------------------SAMPLE CSS END*/
  13. </style>
  14. <a class="loading-opts" href="playground.generated/index.html">[&lt;&lt; BACK]</a> <br/>
  15. THIS IS A GENERATED FILE VIA gulp generate-test-samples
  16. <div id="bar" style="margin-bottom: 6px;"></div>
  17. <div style="clear:both"></div>
  18. <div id="outer-container" style="width:800px;height:450px;border: 1px solid grey">
  19. <!-- ----------------------------------------SAMPLE HTML START-->
  20. <div id="container" style="height:100%;"></div>
  21. <!-- ----------------------------------------SAMPLE HTML END-->
  22. </div>
  23. <div style="clear:both"></div>
  24. <script src="../metadata.js"></script>
  25. <script src="dev-setup.js"></script>
  26. <script>
  27. loadEditor(function() {
  28. /*----------------------------------------SAMPLE JS START*/
  29. // Add additonal d.ts files to the JavaScript language service and change.
  30. // Also change the default compilation options.
  31. // The sample below shows how a class Facts is declared and introduced
  32. // to the system and how the compiler is told to use ES6 (target=2).
  33. // validation settings
  34. monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
  35. noSemanticValidation: true,
  36. noSyntaxValidation: false
  37. });
  38. // compiler options
  39. monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
  40. target: monaco.languages.typescript.ScriptTarget.ES6,
  41. allowNonTsExtensions: true
  42. });
  43. // extra libraries
  44. monaco.languages.typescript.javascriptDefaults.addExtraLib([
  45. 'declare class Facts {',
  46. ' /**',
  47. ' * Returns the next fact',
  48. ' */',
  49. ' static next():string',
  50. '}',
  51. ].join('\n'), 'filename/facts.d.ts');
  52. var jsCode = [
  53. '"use strict";',
  54. '',
  55. "class Chuck {",
  56. " greet() {",
  57. " return Facts.next();",
  58. " }",
  59. "}"
  60. ].join('\n');
  61. monaco.editor.create(document.getElementById("container"), {
  62. value: jsCode,
  63. language: "javascript"
  64. });
  65. /*----------------------------------------SAMPLE JS END*/
  66. });
  67. </script>
  68. </body>
  69. </html>