@difizen/libro-codemirror 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/es/auto-complete/closebrackets.d.ts +12 -0
  2. package/es/auto-complete/closebrackets.d.ts.map +1 -0
  3. package/es/auto-complete/completion.d.ts +57 -0
  4. package/es/auto-complete/completion.d.ts.map +1 -0
  5. package/es/auto-complete/config.d.ts +22 -0
  6. package/es/auto-complete/config.d.ts.map +1 -0
  7. package/es/auto-complete/filter.d.ts +13 -0
  8. package/es/auto-complete/filter.d.ts.map +1 -0
  9. package/es/auto-complete/filter.js +1 -7
  10. package/es/auto-complete/index.d.ts.map +1 -1
  11. package/es/auto-complete/index.js +5 -9
  12. package/es/auto-complete/snippet.d.ts +14 -0
  13. package/es/auto-complete/snippet.d.ts.map +1 -0
  14. package/es/auto-complete/snippet.js +2 -2
  15. package/es/auto-complete/state.d.ts +63 -0
  16. package/es/auto-complete/state.d.ts.map +1 -0
  17. package/es/auto-complete/state.js +5 -16
  18. package/es/auto-complete/theme.d.ts +6 -0
  19. package/es/auto-complete/theme.d.ts.map +1 -0
  20. package/es/auto-complete/tooltip.d.ts +5 -0
  21. package/es/auto-complete/tooltip.d.ts.map +1 -0
  22. package/es/auto-complete/view.d.ts +43 -0
  23. package/es/auto-complete/view.d.ts.map +1 -0
  24. package/es/auto-complete/view.js +2 -13
  25. package/es/auto-complete/word.d.ts +3 -0
  26. package/es/auto-complete/word.d.ts.map +1 -0
  27. package/es/completion.js +1 -1
  28. package/es/config.d.ts +15 -10
  29. package/es/config.d.ts.map +1 -1
  30. package/es/config.js +15 -6
  31. package/es/editor-contribution.d.ts +8 -0
  32. package/es/editor-contribution.d.ts.map +1 -0
  33. package/es/editor-contribution.js +30 -0
  34. package/es/editor.d.ts +40 -10
  35. package/es/editor.d.ts.map +1 -1
  36. package/es/editor.js +241 -45
  37. package/es/hyperlink.d.ts +15 -0
  38. package/es/hyperlink.d.ts.map +1 -0
  39. package/es/indentation-markers/config.d.ts +17 -0
  40. package/es/indentation-markers/config.d.ts.map +1 -0
  41. package/es/indentation-markers/index.d.ts +3 -0
  42. package/es/indentation-markers/index.d.ts.map +1 -0
  43. package/es/indentation-markers/map.d.ts +77 -0
  44. package/es/indentation-markers/map.d.ts.map +1 -0
  45. package/es/indentation-markers/utils.d.ts +27 -0
  46. package/es/indentation-markers/utils.d.ts.map +1 -0
  47. package/es/index.d.ts +3 -1
  48. package/es/index.d.ts.map +1 -1
  49. package/es/index.js +3 -1
  50. package/es/libro-icon.d.ts +3 -0
  51. package/es/libro-icon.d.ts.map +1 -0
  52. package/es/libro-icon.js +2 -2
  53. package/es/lsp/completion.d.ts +5 -0
  54. package/es/lsp/completion.d.ts.map +1 -0
  55. package/es/lsp/completion.js +245 -0
  56. package/es/lsp/format.d.ts +7 -0
  57. package/es/lsp/format.d.ts.map +1 -0
  58. package/es/lsp/format.js +193 -0
  59. package/es/lsp/index.d.ts +7 -0
  60. package/es/lsp/index.d.ts.map +1 -0
  61. package/es/lsp/index.js +6 -0
  62. package/es/lsp/lint.d.ts +3 -0
  63. package/es/lsp/lint.d.ts.map +1 -0
  64. package/es/lsp/lint.js +114 -0
  65. package/es/lsp/protocol.d.ts +7 -0
  66. package/es/lsp/protocol.d.ts.map +1 -0
  67. package/es/lsp/protocol.js +1 -0
  68. package/es/lsp/tooltip.d.ts +3 -0
  69. package/es/lsp/tooltip.d.ts.map +1 -0
  70. package/es/lsp/tooltip.js +113 -0
  71. package/es/lsp/util.d.ts +15 -0
  72. package/es/lsp/util.d.ts.map +1 -0
  73. package/es/lsp/util.js +58 -0
  74. package/es/mode.d.ts.map +1 -1
  75. package/es/module.d.ts +3 -0
  76. package/es/module.d.ts.map +1 -0
  77. package/es/module.js +4 -0
  78. package/es/monitor.d.ts +32 -0
  79. package/es/monitor.d.ts.map +1 -0
  80. package/es/python-lang.d.ts +3 -0
  81. package/es/python-lang.d.ts.map +1 -0
  82. package/es/theme.d.ts +35 -0
  83. package/es/theme.d.ts.map +1 -0
  84. package/es/theme.js +4 -5
  85. package/es/tooltip.d.ts +1 -1
  86. package/es/tooltip.d.ts.map +1 -1
  87. package/es/tooltip.js +2 -4
  88. package/package.json +7 -5
  89. package/src/auto-complete/filter.ts +5 -7
  90. package/src/auto-complete/index.ts +6 -7
  91. package/src/auto-complete/snippet.ts +8 -2
  92. package/src/auto-complete/state.ts +13 -18
  93. package/src/auto-complete/view.ts +7 -13
  94. package/src/completion.ts +2 -2
  95. package/src/config.ts +40 -28
  96. package/src/editor-contribution.ts +17 -0
  97. package/src/editor.ts +226 -50
  98. package/src/hyperlink.ts +1 -1
  99. package/src/indentation-markers/index.ts +3 -3
  100. package/src/indentation-markers/map.ts +9 -9
  101. package/src/index.ts +4 -1
  102. package/src/libro-icon.tsx +4 -0
  103. package/src/lsp/completion.ts +175 -0
  104. package/src/lsp/format.ts +144 -0
  105. package/src/lsp/index.ts +6 -0
  106. package/src/lsp/lint.ts +125 -0
  107. package/src/lsp/protocol.ts +8 -0
  108. package/src/lsp/tooltip.ts +76 -0
  109. package/src/lsp/util.ts +69 -0
  110. package/src/mode.ts +1 -1
  111. package/src/module.ts +8 -0
  112. package/src/theme.ts +4 -4
  113. package/src/tooltip.ts +2 -4
  114. package/src/libro-icon.ts +0 -4
@@ -0,0 +1,193 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
13
+ /* eslint-disable @typescript-eslint/no-parameter-properties */
14
+ /* eslint-disable @typescript-eslint/parameter-properties */
15
+
16
+ import { StateEffect } from '@codemirror/state';
17
+ import { ViewPlugin } from '@codemirror/view';
18
+ import { insertCompletionText } from "../auto-complete/index.js";
19
+ import { offsetToPos, posToOffset } from "./util.js";
20
+ export var startFormatEffect = StateEffect.define();
21
+ export var formatCell = function formatCell(view) {
22
+ view.dispatch({
23
+ effects: startFormatEffect.of(true)
24
+ });
25
+ return true;
26
+ };
27
+ export var formatKeymap = [{
28
+ key: 'Alt-f',
29
+ run: formatCell
30
+ }];
31
+ var FormatPlugin = /*#__PURE__*/function () {
32
+ function FormatPlugin(view, options) {
33
+ _classCallCheck(this, FormatPlugin);
34
+ this.view = view;
35
+ this.options = options;
36
+ }
37
+ _createClass(FormatPlugin, [{
38
+ key: "update",
39
+ value: function update(_update) {
40
+ var _iterator = _createForOfIteratorHelper(_update.transactions),
41
+ _step;
42
+ try {
43
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
44
+ var tr = _step.value;
45
+ var _iterator2 = _createForOfIteratorHelper(tr.effects),
46
+ _step2;
47
+ try {
48
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
49
+ var effect = _step2.value;
50
+ if (effect.is(startFormatEffect)) {
51
+ this.doFormat();
52
+ }
53
+ }
54
+ } catch (err) {
55
+ _iterator2.e(err);
56
+ } finally {
57
+ _iterator2.f();
58
+ }
59
+ }
60
+ } catch (err) {
61
+ _iterator.e(err);
62
+ } finally {
63
+ _iterator.f();
64
+ }
65
+ }
66
+ }, {
67
+ key: "doFormat",
68
+ value: function () {
69
+ var _doFormat = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
70
+ var _this$options$lspProv,
71
+ _this$options,
72
+ _this = this;
73
+ var lspProvider, editor, virtualDocument, lspConnection, virtualStartPos, end, virtualEndPos;
74
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
75
+ while (1) switch (_context.prev = _context.next) {
76
+ case 0:
77
+ _context.next = 2;
78
+ return (_this$options$lspProv = (_this$options = this.options).lspProvider) === null || _this$options$lspProv === void 0 ? void 0 : _this$options$lspProv.call(_this$options);
79
+ case 2:
80
+ lspProvider = _context.sent;
81
+ if (lspProvider) {
82
+ _context.next = 5;
83
+ break;
84
+ }
85
+ return _context.abrupt("return");
86
+ case 5:
87
+ // const { state } = this.view;
88
+ // const currentLine = state.doc.lineAt(state.selection.main.head).number;
89
+ editor = lspProvider.editor, virtualDocument = lspProvider.virtualDocument, lspConnection = lspProvider.lspConnection;
90
+ virtualStartPos = virtualDocument.transformEditorToVirtual(editor, {
91
+ line: 0,
92
+ ch: 0,
93
+ isEditor: true
94
+ });
95
+ end = offsetToPos(this.view.state.doc, this.view.state.doc.length);
96
+ virtualEndPos = virtualDocument.transformEditorToVirtual(editor, {
97
+ line: end.line,
98
+ ch: end.character,
99
+ isEditor: true
100
+ });
101
+ if (!(!virtualStartPos || !virtualEndPos)) {
102
+ _context.next = 11;
103
+ break;
104
+ }
105
+ return _context.abrupt("return");
106
+ case 11:
107
+ lspConnection.clientRequests['textDocument/rangeFormatting'].request({
108
+ textDocument: {
109
+ uri: virtualDocument.uri
110
+ },
111
+ range: {
112
+ start: {
113
+ line: virtualStartPos.line,
114
+ character: virtualStartPos.ch
115
+ },
116
+ end: {
117
+ line: virtualEndPos.line,
118
+ character: virtualEndPos.ch
119
+ }
120
+ },
121
+ options: {
122
+ tabSize: this.view.state.tabSize,
123
+ insertSpaces: true
124
+ }
125
+ }).then(function (result) {
126
+ if (result && result !== null && result !== void 0 && result.length) {
127
+ var _this$view;
128
+ var items = result;
129
+ var transaction = [];
130
+ items.forEach(function (item) {
131
+ var _virtualDocument$tran, _virtualDocument$tran2;
132
+ var defaultNewLine = {
133
+ line: end.line + 1,
134
+ ch: 0
135
+ };
136
+ var editorStart = (_virtualDocument$tran = virtualDocument.transformVirtualToEditor({
137
+ line: item.range.start.line,
138
+ ch: item.range.start.character,
139
+ isVirtual: true
140
+ })) !== null && _virtualDocument$tran !== void 0 ? _virtualDocument$tran : defaultNewLine;
141
+ var editorEnd = (_virtualDocument$tran2 = virtualDocument.transformVirtualToEditor({
142
+ line: item.range.end.line,
143
+ ch: item.range.end.character,
144
+ isVirtual: true
145
+ })) !== null && _virtualDocument$tran2 !== void 0 ? _virtualDocument$tran2 : defaultNewLine;
146
+ if (!editorStart || !editorEnd) {
147
+ return;
148
+ }
149
+ var from = posToOffset(_this.view.state.doc, {
150
+ line: editorStart.line,
151
+ character: editorStart.ch
152
+ });
153
+ var to = posToOffset(_this.view.state.doc, {
154
+ line: editorEnd.line,
155
+ character: editorEnd.ch
156
+ });
157
+ // FIXME: 需要处理新增行的情况,目前在virtualdocument无法处理
158
+ // console.log('format', item.range, editorStart, editorEnd, from, to);
159
+ if (from !== undefined && to !== undefined) {
160
+ var trans = insertCompletionText(_this.view.state, item.newText, from, to);
161
+ transaction.push(trans);
162
+ }
163
+ });
164
+ // console.log(transaction, 'format trans');
165
+
166
+ (_this$view = _this.view).dispatch.apply(_this$view, transaction);
167
+ }
168
+ return;
169
+ }).catch(console.error);
170
+ case 12:
171
+ case "end":
172
+ return _context.stop();
173
+ }
174
+ }, _callee, this);
175
+ }));
176
+ function doFormat() {
177
+ return _doFormat.apply(this, arguments);
178
+ }
179
+ return doFormat;
180
+ }()
181
+ }, {
182
+ key: "destroy",
183
+ value: function destroy() {
184
+ //
185
+ }
186
+ }]);
187
+ return FormatPlugin;
188
+ }();
189
+ export var lspFormat = function lspFormat(options) {
190
+ return [ViewPlugin.define(function (view) {
191
+ return new FormatPlugin(view, options);
192
+ })];
193
+ };
@@ -0,0 +1,7 @@
1
+ export * from './lint.js';
2
+ export * from './protocol.js';
3
+ export * from './tooltip.js';
4
+ export * from './util.js';
5
+ export * from './completion.js';
6
+ export * from './format.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lsp/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./lint.js";
2
+ export * from "./protocol.js";
3
+ export * from "./tooltip.js";
4
+ export * from "./util.js";
5
+ export * from "./completion.js";
6
+ export * from "./format.js";
@@ -0,0 +1,3 @@
1
+ import type { CMLSPExtension } from './protocol.js';
2
+ export declare const lspLint: CMLSPExtension;
3
+ //# sourceMappingURL=lint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/lsp/lint.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAuB,MAAM,eAAe,CAAC;AAyGzE,eAAO,MAAM,OAAO,EAAE,cAErB,CAAC"}
package/es/lsp/lint.js ADDED
@@ -0,0 +1,114 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ import { setDiagnostics } from '@codemirror/lint';
9
+ import { ViewPlugin } from '@codemirror/view';
10
+ import { DiagnosticSeverity } from '@difizen/libro-lsp';
11
+ import { posToOffset } from "./util.js";
12
+ var LintPlugin = /*#__PURE__*/function () {
13
+ function LintPlugin(view, options) {
14
+ _classCallCheck(this, LintPlugin);
15
+ this.view = view;
16
+ this.options = options;
17
+ this.processDiagnostic();
18
+ }
19
+ _createClass(LintPlugin, [{
20
+ key: "processDiagnostic",
21
+ value: function processDiagnostic() {
22
+ var _this = this;
23
+ if (!this.options.lspProvider) {
24
+ return;
25
+ }
26
+ this.options.lspProvider().then(function (_ref) {
27
+ var lspConnection = _ref.lspConnection,
28
+ virtualDocument = _ref.virtualDocument,
29
+ editor = _ref.editor;
30
+ if (!lspConnection) {
31
+ return;
32
+ }
33
+ lspConnection.serverNotifications['textDocument/publishDiagnostics'].event(function (e) {
34
+ var diagnostics = e.diagnostics.map(function (_ref2) {
35
+ var _DiagnosticSeverity$E;
36
+ var range = _ref2.range,
37
+ message = _ref2.message,
38
+ _ref2$severity = _ref2.severity,
39
+ severity = _ref2$severity === void 0 ? DiagnosticSeverity.Information : _ref2$severity;
40
+ var currentEditor = virtualDocument.getEditorAtVirtualLine({
41
+ line: range.start.line,
42
+ ch: range.start.character,
43
+ isVirtual: true
44
+ });
45
+
46
+ // the diagnostic range must be in current editor
47
+ if (editor !== currentEditor) {
48
+ return;
49
+ }
50
+ var editorStart = virtualDocument.transformVirtualToEditor({
51
+ line: range.start.line,
52
+ ch: range.start.character,
53
+ isVirtual: true
54
+ });
55
+ var offset;
56
+ if (editorStart) {
57
+ offset = posToOffset(_this.view.state.doc, {
58
+ line: editorStart.line,
59
+ character: editorStart.ch
60
+ });
61
+ }
62
+ var editorEnd = virtualDocument.transformVirtualToEditor({
63
+ line: range.end.line,
64
+ ch: range.end.character,
65
+ isVirtual: true
66
+ });
67
+ var end;
68
+ if (editorEnd) {
69
+ end = posToOffset(_this.view.state.doc, {
70
+ line: editorEnd.line,
71
+ character: editorEnd.ch
72
+ });
73
+ }
74
+ return {
75
+ from: offset,
76
+ to: end,
77
+ severity: (_DiagnosticSeverity$E = {}, _defineProperty(_DiagnosticSeverity$E, DiagnosticSeverity.Error, 'error'), _defineProperty(_DiagnosticSeverity$E, DiagnosticSeverity.Warning, 'warning'), _defineProperty(_DiagnosticSeverity$E, DiagnosticSeverity.Information, 'info'), _defineProperty(_DiagnosticSeverity$E, DiagnosticSeverity.Hint, 'info'), _DiagnosticSeverity$E)[severity],
78
+ message: message
79
+ };
80
+ }).filter(isDiagnostic).sort(function (a, b) {
81
+ switch (true) {
82
+ case a.from < b.from:
83
+ return -1;
84
+ case a.from > b.from:
85
+ return 1;
86
+ }
87
+ return 0;
88
+ });
89
+ _this.view.dispatch(setDiagnostics(_this.view.state, diagnostics));
90
+ });
91
+ return;
92
+ }).catch(console.error);
93
+ }
94
+ }, {
95
+ key: "update",
96
+ value: function update() {
97
+ //
98
+ }
99
+ }, {
100
+ key: "destroy",
101
+ value: function destroy() {
102
+ //
103
+ }
104
+ }]);
105
+ return LintPlugin;
106
+ }();
107
+ export var lspLint = function lspLint(options) {
108
+ return [ViewPlugin.define(function (view) {
109
+ return new LintPlugin(view, options);
110
+ })];
111
+ };
112
+ function isDiagnostic(item) {
113
+ return item !== undefined && item !== null && item.from !== null && item.to !== null && item.from !== undefined && item.to !== undefined;
114
+ }
@@ -0,0 +1,7 @@
1
+ import type { Extension } from '@codemirror/state';
2
+ import type { LSPProvider } from '@difizen/libro-lsp';
3
+ export interface LSPExtensionOptions {
4
+ lspProvider?: LSPProvider;
5
+ }
6
+ export type CMLSPExtension = (option: LSPExtensionOptions) => Extension;
7
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/lsp/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,mBAAmB,KAAK,SAAS,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { CMLSPExtension } from './protocol.js';
2
+ export declare const lspTooltip: CMLSPExtension;
3
+ //# sourceMappingURL=tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/lsp/tooltip.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,eAAO,MAAM,UAAU,EAAE,cAsExB,CAAC"}
@@ -0,0 +1,113 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ import { hoverTooltip } from '@codemirror/view';
6
+ import { offsetToPos, posToOffset, renderMarkupContent } from "./util.js";
7
+ export var lspTooltip = function lspTooltip(options) {
8
+ return hoverTooltip( /*#__PURE__*/function () {
9
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(view, pos) {
10
+ var _yield$options$lspPro, connection, doc, editor, _offsetToPos, line, character, virtualPos, result, contents, range, offset, end, editorStart, editorEnd, dom;
11
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
12
+ while (1) switch (_context.prev = _context.next) {
13
+ case 0:
14
+ if (options.lspProvider) {
15
+ _context.next = 2;
16
+ break;
17
+ }
18
+ return _context.abrupt("return", null);
19
+ case 2:
20
+ _context.next = 4;
21
+ return options.lspProvider();
22
+ case 4:
23
+ _yield$options$lspPro = _context.sent;
24
+ connection = _yield$options$lspPro.lspConnection;
25
+ doc = _yield$options$lspPro.virtualDocument;
26
+ editor = _yield$options$lspPro.editor;
27
+ if (!(!connection || !connection.isReady || !connection.provides('hoverProvider'))) {
28
+ _context.next = 10;
29
+ break;
30
+ }
31
+ return _context.abrupt("return", null);
32
+ case 10:
33
+ _offsetToPos = offsetToPos(view.state.doc, pos), line = _offsetToPos.line, character = _offsetToPos.character;
34
+ virtualPos = doc.transformEditorToVirtual(editor, {
35
+ line: line,
36
+ ch: character,
37
+ isEditor: true
38
+ });
39
+ if (virtualPos) {
40
+ _context.next = 14;
41
+ break;
42
+ }
43
+ return _context.abrupt("return", null);
44
+ case 14:
45
+ _context.next = 16;
46
+ return connection.clientRequests['textDocument/hover'].request({
47
+ position: {
48
+ line: virtualPos.line,
49
+ character: virtualPos.ch
50
+ },
51
+ textDocument: {
52
+ uri: doc.documentInfo.uri
53
+ }
54
+ });
55
+ case 16:
56
+ result = _context.sent;
57
+ if (result) {
58
+ _context.next = 19;
59
+ break;
60
+ }
61
+ return _context.abrupt("return", null);
62
+ case 19:
63
+ contents = result.contents, range = result.range;
64
+ offset = posToOffset(view.state.doc, {
65
+ line: line,
66
+ character: character
67
+ });
68
+ if (range) {
69
+ editorStart = doc.transformVirtualToEditor({
70
+ line: range.start.line,
71
+ ch: range.start.character,
72
+ isVirtual: true
73
+ });
74
+ if (editorStart) {
75
+ offset = posToOffset(view.state.doc, {
76
+ line: editorStart.line,
77
+ character: editorStart.ch
78
+ });
79
+ }
80
+ editorEnd = doc.transformVirtualToEditor({
81
+ line: range.end.line,
82
+ ch: range.end.character,
83
+ isVirtual: true
84
+ });
85
+ if (editorEnd) {
86
+ end = posToOffset(view.state.doc, {
87
+ line: editorEnd.line,
88
+ character: editorEnd.ch
89
+ });
90
+ }
91
+ }
92
+ dom = renderMarkupContent(contents);
93
+ return _context.abrupt("return", {
94
+ pos: offset,
95
+ end: end,
96
+ create: function create() {
97
+ return {
98
+ dom: dom
99
+ };
100
+ },
101
+ above: false
102
+ });
103
+ case 24:
104
+ case "end":
105
+ return _context.stop();
106
+ }
107
+ }, _callee);
108
+ }));
109
+ return function (_x, _x2) {
110
+ return _ref.apply(this, arguments);
111
+ };
112
+ }());
113
+ };
@@ -0,0 +1,15 @@
1
+ import type { Text } from '@codemirror/state';
2
+ import type * as lsp from 'vscode-languageserver-protocol';
3
+ import 'highlight.js/styles/github.css';
4
+ export declare function posToOffset(doc: Text, pos: {
5
+ line: number;
6
+ character: number;
7
+ }): number | undefined;
8
+ export declare function offsetToPos(doc: Text, offset: number): {
9
+ line: number;
10
+ character: number;
11
+ };
12
+ export declare function formatContents(contents: lsp.MarkupContent | lsp.MarkedString | lsp.MarkedString[]): string;
13
+ export declare const renderMarkdownContent: (val: string) => string;
14
+ export declare const renderMarkupContent: (contents: lsp.MarkupContent | lsp.MarkedString | lsp.MarkedString[]) => HTMLDivElement;
15
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/lsp/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,KAAK,KAAK,GAAG,MAAM,gCAAgC,CAAC;AAC3D,OAAO,gCAAgC,CAAC;AAExC,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,sBAS9E;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM;;;EAMpD;AAED,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,GAAG,CAAC,aAAa,GAAG,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,EAAE,GAClE,MAAM,CAQR;AAED,eAAO,MAAM,qBAAqB,QAAS,MAAM,WAoBhD,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,IAAI,aAAa,GAAG,IAAI,YAAY,GAAG,IAAI,YAAY,EAAE,mBAQpE,CAAC"}
package/es/lsp/util.js ADDED
@@ -0,0 +1,58 @@
1
+ import hljs from 'highlight.js';
2
+ import MarkdownIt from 'markdown-it';
3
+ import 'highlight.js/styles/github.css';
4
+ export function posToOffset(doc, pos) {
5
+ if (pos.line >= doc.lines) {
6
+ return;
7
+ }
8
+ var offset = doc.line(pos.line + 1).from + pos.character;
9
+ if (offset > doc.length) {
10
+ return;
11
+ }
12
+ return offset;
13
+ }
14
+ export function offsetToPos(doc, offset) {
15
+ var line = doc.lineAt(offset);
16
+ return {
17
+ line: line.number - 1,
18
+ character: offset - line.from
19
+ };
20
+ }
21
+ export function formatContents(contents) {
22
+ if (Array.isArray(contents)) {
23
+ return contents.map(function (c) {
24
+ return formatContents(c) + '\n\n';
25
+ }).join('');
26
+ } else if (typeof contents === 'string') {
27
+ return contents;
28
+ } else {
29
+ return contents.value;
30
+ }
31
+ }
32
+ export var renderMarkdownContent = function renderMarkdownContent(val) {
33
+ var render = new MarkdownIt({
34
+ html: true,
35
+ linkify: true,
36
+ breaks: true,
37
+ highlight: function highlight(str, lang) {
38
+ if (lang && hljs.getLanguage(lang)) {
39
+ try {
40
+ var hl = hljs.highlight(lang, str).value;
41
+ return hl;
42
+ } catch (__) {
43
+ //
44
+ }
45
+ }
46
+ return ''; // use external default escaping
47
+ }
48
+ });
49
+
50
+ return render.render(val);
51
+ };
52
+ export var renderMarkupContent = function renderMarkupContent(contents) {
53
+ var dom = document.createElement('div');
54
+ dom.classList.add('documentation');
55
+ var res = renderMarkdownContent(formatContents(contents));
56
+ dom.innerHTML = res;
57
+ return dom;
58
+ };
package/es/mode.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mode.d.ts","sourceRoot":"","sources":["../src/mode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAQ5D;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;IACtC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B;AA+BD;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,KAAK,EAAE,CAErC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CA8BzE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAgBrD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CAoB7E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAczD;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,QAAQ,UAAO,GAAG,KAAK,GAAG,IAAI,CAW5E;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAOxE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CAMlD;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAyBpE"}
1
+ {"version":3,"file":"mode.d.ts","sourceRoot":"","sources":["../src/mode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAS5D;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;IACtC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B;AA+BD;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,KAAK,EAAE,CAErC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CA8BzE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAgBrD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CAoB7E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAczD;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,QAAQ,UAAO,GAAG,KAAK,GAAG,IAAI,CAW5E;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAOxE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CAMlD;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAyBpE"}
package/es/module.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const CodeMirrorEditorModule: ManaModule;
3
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,eAAO,MAAM,sBAAsB,YAEN,CAAC"}
package/es/module.js ADDED
@@ -0,0 +1,4 @@
1
+ import { CodeEditorModule } from '@difizen/libro-code-editor';
2
+ import { ManaModule } from '@difizen/mana-app';
3
+ import { CodeMirrorEditorContribution } from "./editor-contribution.js";
4
+ export var CodeMirrorEditorModule = ManaModule.create().register(CodeMirrorEditorContribution).dependOn(CodeEditorModule);