1
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html>
  2. <!-- THIS IS A GENERATED FILE VIA `npm run simpleserver` -->
  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 `npm run simpleserver`
  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. // Add additional d.ts files to the JavaScript language service and change.
  29. // Also change the default compilation options.
  30. // The sample below shows how a class Facts is declared and introduced
  31. // to the system and how the compiler is told to use ES6 (target=2).
  32. // validation settings
  33. monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
  34. noSemanticValidation: true,
  35. noSyntaxValidation: false
  36. });
  37. // compiler options
  38. monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
  39. target: monaco.languages.typescript.ScriptTarget.ES6,
  40. allowNonTsExtensions: true
  41. });
  42. // extra libraries
  43. var libSource = [
  44. 'declare class Facts {',
  45. ' /**',
  46. ' * Returns the next fact',
  47. ' */',
  48. ' static next():string',
  49. '}'
  50. ].join('\n');
  51. var libUri = 'ts:filename/facts.d.ts';
  52. monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
  53. // When resolving definitions and references, the editor will try to use created models.
  54. // Creating a model for the library allows "peek definition/references" commands to work with the library.
  55. monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(libUri));
  56. var jsCode = [
  57. '"use strict";',
  58. '',
  59. 'class Chuck {',
  60. ' greet() {',
  61. ' return Facts.next();',
  62. ' }',
  63. '}'
  64. ].join('\n');
  65. monaco.editor.create(document.getElementById('container'), {
  66. value: jsCode,
  67. language: 'javascript'
  68. });
  69. /*----------------------------------------SAMPLE JS END*/
  70. });
  71. </script>
  72. </body>
  73. </html>