extending-language-services-hover-provider-example.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. monaco.languages.register({ id: 'mySpecialLanguage' });
  29. monaco.languages.registerHoverProvider('mySpecialLanguage', {
  30. provideHover: function (model, position) {
  31. return xhr('../playground.html').then(function (res) {
  32. return {
  33. range: new monaco.Range(
  34. 1,
  35. 1,
  36. model.getLineCount(),
  37. model.getLineMaxColumn(model.getLineCount())
  38. ),
  39. contents: [
  40. { value: '**SOURCE**' },
  41. { value: '```html\n' + res.responseText.substring(0, 200) + '\n```' }
  42. ]
  43. };
  44. });
  45. }
  46. });
  47. monaco.editor.create(document.getElementById('container'), {
  48. value: '\n\nHover over this text',
  49. language: 'mySpecialLanguage'
  50. });
  51. function xhr(url) {
  52. var req = null;
  53. return new Promise(
  54. function (c, e) {
  55. req = new XMLHttpRequest();
  56. req.onreadystatechange = function () {
  57. if (req._canceled) {
  58. return;
  59. }
  60. if (req.readyState === 4) {
  61. if ((req.status >= 200 && req.status < 300) || req.status === 1223) {
  62. c(req);
  63. } else {
  64. e(req);
  65. }
  66. req.onreadystatechange = function () {};
  67. }
  68. };
  69. req.open('GET', url, true);
  70. req.responseType = '';
  71. req.send(null);
  72. },
  73. function () {
  74. req._canceled = true;
  75. req.abort();
  76. }
  77. );
  78. }
  79. /*----------------------------------------SAMPLE JS END*/
  80. });
  81. </script>
  82. </body>
  83. </html>