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

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