@difizen/libro-codemirror 0.1.1 → 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.
- package/es/auto-complete/filter.d.ts.map +1 -1
- package/es/auto-complete/filter.js +1 -7
- package/es/auto-complete/index.d.ts.map +1 -1
- package/es/auto-complete/index.js +5 -9
- package/es/auto-complete/snippet.d.ts.map +1 -1
- package/es/auto-complete/snippet.js +2 -2
- package/es/auto-complete/state.d.ts.map +1 -1
- package/es/auto-complete/state.js +5 -16
- package/es/auto-complete/view.d.ts +5 -0
- package/es/auto-complete/view.d.ts.map +1 -1
- package/es/auto-complete/view.js +2 -13
- package/es/completion.js +1 -1
- package/es/config.d.ts +15 -10
- package/es/config.d.ts.map +1 -1
- package/es/config.js +15 -6
- package/es/editor-contribution.d.ts +8 -0
- package/es/editor-contribution.d.ts.map +1 -0
- package/es/editor-contribution.js +30 -0
- package/es/editor.d.ts +40 -10
- package/es/editor.d.ts.map +1 -1
- package/es/editor.js +241 -45
- package/es/indentation-markers/map.d.ts +9 -9
- package/es/indentation-markers/map.d.ts.map +1 -1
- package/es/index.d.ts +3 -1
- package/es/index.d.ts.map +1 -1
- package/es/index.js +3 -1
- package/es/libro-icon.d.ts +2 -2
- package/es/libro-icon.d.ts.map +1 -1
- package/es/libro-icon.js +2 -2
- package/es/lsp/completion.d.ts +5 -0
- package/es/lsp/completion.d.ts.map +1 -0
- package/es/lsp/completion.js +245 -0
- package/es/lsp/format.d.ts +7 -0
- package/es/lsp/format.d.ts.map +1 -0
- package/es/lsp/format.js +193 -0
- package/es/lsp/index.d.ts +7 -0
- package/es/lsp/index.d.ts.map +1 -0
- package/es/lsp/index.js +6 -0
- package/es/lsp/lint.d.ts +3 -0
- package/es/lsp/lint.d.ts.map +1 -0
- package/es/lsp/lint.js +114 -0
- package/es/lsp/protocol.d.ts +7 -0
- package/es/lsp/protocol.d.ts.map +1 -0
- package/es/lsp/protocol.js +1 -0
- package/es/lsp/tooltip.d.ts +3 -0
- package/es/lsp/tooltip.d.ts.map +1 -0
- package/es/lsp/tooltip.js +113 -0
- package/es/lsp/util.d.ts +15 -0
- package/es/lsp/util.d.ts.map +1 -0
- package/es/lsp/util.js +58 -0
- package/es/mode.d.ts.map +1 -1
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +4 -0
- package/es/theme.js +4 -5
- package/es/tooltip.d.ts.map +1 -1
- package/es/tooltip.js +2 -4
- package/package.json +7 -5
- package/src/auto-complete/filter.ts +5 -7
- package/src/auto-complete/index.ts +6 -7
- package/src/auto-complete/snippet.ts +8 -2
- package/src/auto-complete/state.ts +13 -18
- package/src/auto-complete/view.ts +7 -13
- package/src/completion.ts +2 -2
- package/src/config.ts +40 -28
- package/src/editor-contribution.ts +17 -0
- package/src/editor.ts +226 -50
- package/src/hyperlink.ts +1 -1
- package/src/indentation-markers/index.ts +3 -3
- package/src/indentation-markers/map.ts +9 -9
- package/src/index.ts +4 -1
- package/src/libro-icon.tsx +4 -0
- package/src/lsp/completion.ts +175 -0
- package/src/lsp/format.ts +144 -0
- package/src/lsp/index.ts +6 -0
- package/src/lsp/lint.ts +125 -0
- package/src/lsp/protocol.ts +8 -0
- package/src/lsp/tooltip.ts +76 -0
- package/src/lsp/util.ts +69 -0
- package/src/mode.ts +1 -1
- package/src/module.ts +8 -0
- package/src/theme.ts +4 -4
- package/src/tooltip.ts +2 -4
- package/src/libro-icon.ts +0 -4
|
@@ -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
|
+
};
|
package/es/lsp/util.d.ts
ADDED
|
@@ -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":"
|
|
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 @@
|
|
|
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);
|
package/es/theme.js
CHANGED
|
@@ -8,7 +8,7 @@ export var jupyterEditorTheme = EditorView.theme({
|
|
|
8
8
|
* these things differently.
|
|
9
9
|
*/
|
|
10
10
|
'&': {
|
|
11
|
-
background: 'var(--
|
|
11
|
+
background: 'var(--mana-libro-input-background)',
|
|
12
12
|
color: 'var(--mana-libro-text-default-color)'
|
|
13
13
|
},
|
|
14
14
|
/* In the notebook, we want this styling to be handled by its container */
|
|
@@ -68,10 +68,9 @@ export var jupyterEditorTheme = EditorView.theme({
|
|
|
68
68
|
letterSpacing: '0',
|
|
69
69
|
lineHeight: '20px'
|
|
70
70
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
'.cm-editor': {
|
|
72
|
+
background: 'var(--mana-libro-input-background)'
|
|
73
|
+
},
|
|
75
74
|
'.cm-searchMatch': {
|
|
76
75
|
backgroundColor: 'var(--jp-search-unselected-match-background-color)',
|
|
77
76
|
color: 'var(--jp-search-unselected-match-color)'
|
package/es/tooltip.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../src/tooltip.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EAEV,OAAO,EAER,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAIlE,eAAO,MAAM,kBAAkB,sDAAgC,CAAC;AAChE,eAAO,MAAM,kBAAkB,mDAA6B,CAAC;AAsD7D,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAG9C,CAAC;
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../src/tooltip.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EAEV,OAAO,EAER,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAIlE,eAAO,MAAM,kBAAkB,sDAAgC,CAAC;AAChE,eAAO,MAAM,kBAAkB,mDAA6B,CAAC;AAsD7D,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAG9C,CAAC;AAuDF,wBAAgB,UAAU,CAAC,eAAe,EAAE,eAAe,GAAG,SAAS,0EAEtE"}
|
package/es/tooltip.js
CHANGED
|
@@ -41,7 +41,7 @@ var tooltipField = StateField.define({
|
|
|
41
41
|
create: function create() {
|
|
42
42
|
return null;
|
|
43
43
|
},
|
|
44
|
-
update: function update(
|
|
44
|
+
update: function update(tooltips, tr) {
|
|
45
45
|
var effects = tr.effects;
|
|
46
46
|
var _iterator = _createForOfIteratorHelper(effects),
|
|
47
47
|
_step;
|
|
@@ -134,9 +134,7 @@ var TooltipPlugin = /*#__PURE__*/function () {
|
|
|
134
134
|
})
|
|
135
135
|
});
|
|
136
136
|
return undefined;
|
|
137
|
-
}).catch(
|
|
138
|
-
//
|
|
139
|
-
});
|
|
137
|
+
}).catch(console.error);
|
|
140
138
|
}
|
|
141
139
|
}
|
|
142
140
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-codemirror",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/mana-app": "latest",
|
|
36
35
|
"@codemirror/autocomplete": "^6.0.0",
|
|
37
36
|
"@codemirror/commands": "^6.1.0",
|
|
38
37
|
"@codemirror/lang-javascript": "^6.0.2",
|
|
@@ -45,11 +44,14 @@
|
|
|
45
44
|
"@codemirror/search": "^6.0.0",
|
|
46
45
|
"@codemirror/state": "^6.0.0",
|
|
47
46
|
"@codemirror/view": "^6.2.2",
|
|
48
|
-
"@difizen/libro-code-editor": "^0.1.
|
|
49
|
-
"@difizen/libro-common": "^0.1.
|
|
50
|
-
"@difizen/libro-rendermime": "^0.1.
|
|
47
|
+
"@difizen/libro-code-editor": "^0.1.2",
|
|
48
|
+
"@difizen/libro-common": "^0.1.2",
|
|
49
|
+
"@difizen/libro-rendermime": "^0.1.2",
|
|
50
|
+
"@difizen/libro-lsp": "^0.1.2",
|
|
51
|
+
"@difizen/mana-app": "latest",
|
|
51
52
|
"@lezer/common": "^1.1.0",
|
|
52
53
|
"@lezer/highlight": "^1.1.4",
|
|
54
|
+
"highlight.js": "^11.9.0",
|
|
53
55
|
"markdown-it": "^13.0.1",
|
|
54
56
|
"uuid": "^9.0.0",
|
|
55
57
|
"vscode-languageserver-protocol": "^3.17.0"
|
|
@@ -63,13 +63,11 @@ export class FuzzyMatcher {
|
|
|
63
63
|
// at the start
|
|
64
64
|
if (chars.length === 1) {
|
|
65
65
|
const first = codePointAt(word, 0);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
66
|
+
return first === chars[0]
|
|
67
|
+
? [0, 0, codePointSize(first)]
|
|
68
|
+
: first === folded[0]
|
|
69
|
+
? [Penalty.CaseFold, 0, codePointSize(first)]
|
|
70
|
+
: null;
|
|
73
71
|
}
|
|
74
72
|
const direct = word.indexOf(this.pattern);
|
|
75
73
|
if (direct === 0) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
1
2
|
import type { Extension, EditorState, StateEffect } from '@codemirror/state';
|
|
2
3
|
import { Prec } from '@codemirror/state';
|
|
3
4
|
import type { KeyBinding } from '@codemirror/view';
|
|
@@ -65,13 +66,11 @@ const completionKeymapExt = Prec.highest(
|
|
|
65
66
|
/// returns `null`.
|
|
66
67
|
export function completionStatus(state: EditorState): null | 'active' | 'pending' {
|
|
67
68
|
const cState = state.field(completionState, false);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
69
|
+
return cState && cState.active.some((a) => a.state === State.Pending)
|
|
70
|
+
? 'pending'
|
|
71
|
+
: cState && cState.active.some((a) => a.state !== State.Inactive)
|
|
72
|
+
? 'active'
|
|
73
|
+
: null;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
const completionArrayCache: WeakMap<readonly Option[], readonly Completion[]> =
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
3
3
|
/* eslint-disable prefer-const */
|
|
4
|
+
|
|
4
5
|
import { indentUnit } from '@codemirror/language';
|
|
5
6
|
import type {
|
|
6
7
|
ChangeDesc,
|
|
@@ -93,8 +94,13 @@ class Snippet {
|
|
|
93
94
|
name = m[2] || m[3] || '',
|
|
94
95
|
found = -1;
|
|
95
96
|
for (let i = 0; i < fields.length; i++) {
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
if (
|
|
98
|
+
seq !== null
|
|
99
|
+
? fields[i].seq === seq
|
|
100
|
+
: name
|
|
101
|
+
? fields[i].name === name
|
|
102
|
+
: false
|
|
103
|
+
) {
|
|
98
104
|
found = i;
|
|
99
105
|
}
|
|
100
106
|
}
|
|
@@ -49,7 +49,7 @@ function sortOptions(active: readonly ActiveSource[], state: EditorState) {
|
|
|
49
49
|
let match;
|
|
50
50
|
for (const option of a.result.options) {
|
|
51
51
|
if ((match = matcher.match(option.label))) {
|
|
52
|
-
if (option.boost
|
|
52
|
+
if (option.boost) {
|
|
53
53
|
match[0] += option.boost;
|
|
54
54
|
}
|
|
55
55
|
options.push(new Option(option, a, match));
|
|
@@ -68,9 +68,7 @@ function sortOptions(active: readonly ActiveSource[], state: EditorState) {
|
|
|
68
68
|
!prev ||
|
|
69
69
|
prev.label !== opt.completion.label ||
|
|
70
70
|
prev.detail !== opt.completion.detail ||
|
|
71
|
-
(prev.type !==
|
|
72
|
-
opt.completion.type !== null &&
|
|
73
|
-
prev.type !== opt.completion.type) ||
|
|
71
|
+
(prev.type && opt.completion.type && prev.type !== opt.completion.type) ||
|
|
74
72
|
prev.apply !== opt.completion.apply
|
|
75
73
|
) {
|
|
76
74
|
result.push(opt);
|
|
@@ -191,16 +189,15 @@ export class CompletionState {
|
|
|
191
189
|
) {
|
|
192
190
|
active = this.active;
|
|
193
191
|
}
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
|
|
193
|
+
let open =
|
|
196
194
|
tr.selection ||
|
|
197
195
|
active.some((a) => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
|
|
198
196
|
!sameResults(active, this.active)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
197
|
+
? CompletionDialog.build(active, state, this.id, this.open, conf)
|
|
198
|
+
: this.open && tr.docChanged
|
|
199
|
+
? this.open.map(tr.changes)
|
|
200
|
+
: this.open;
|
|
204
201
|
if (
|
|
205
202
|
!open &&
|
|
206
203
|
active.every((a) => a.state !== State.Pending) &&
|
|
@@ -277,13 +274,11 @@ export const enum State {
|
|
|
277
274
|
}
|
|
278
275
|
|
|
279
276
|
export function getUserEvent(tr: Transaction): 'input' | 'delete' | null {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
return null;
|
|
277
|
+
return tr.isUserEvent('input.type')
|
|
278
|
+
? 'input'
|
|
279
|
+
: tr.isUserEvent('delete.backward')
|
|
280
|
+
? 'delete'
|
|
281
|
+
: null;
|
|
287
282
|
}
|
|
288
283
|
|
|
289
284
|
export class ActiveSource {
|
|
@@ -51,16 +51,12 @@ export function moveCompletionSelection(
|
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
const { length } = cState.open.options;
|
|
54
|
-
let selected
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} else {
|
|
61
|
-
selected = length - 1;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
54
|
+
let selected =
|
|
55
|
+
cState.open.selected > -1
|
|
56
|
+
? cState.open.selected + step * (forward ? 1 : -1)
|
|
57
|
+
: forward
|
|
58
|
+
? 0
|
|
59
|
+
: length - 1;
|
|
64
60
|
if (selected < 0) {
|
|
65
61
|
selected = by === 'page' ? 0 : length - 1;
|
|
66
62
|
} else if (selected >= length) {
|
|
@@ -238,9 +234,7 @@ export const completionPlugin = ViewPlugin.fromClass(
|
|
|
238
234
|
return undefined;
|
|
239
235
|
},
|
|
240
236
|
)
|
|
241
|
-
.catch(
|
|
242
|
-
//
|
|
243
|
-
});
|
|
237
|
+
.catch(console.error);
|
|
244
238
|
}
|
|
245
239
|
|
|
246
240
|
scheduleAccept() {
|
package/src/completion.ts
CHANGED
|
@@ -19,7 +19,7 @@ export const kernelCompletions: EditorCompletion =
|
|
|
19
19
|
try {
|
|
20
20
|
result = await Promise.any([
|
|
21
21
|
provider({ cursorPosition: context.pos }),
|
|
22
|
-
new Promise<CompletionReply>((
|
|
22
|
+
new Promise<CompletionReply>((resolve, reject) => {
|
|
23
23
|
setTimeout(() => {
|
|
24
24
|
reject(`request time out in ${timeout}ms`);
|
|
25
25
|
}, timeout);
|
|
@@ -45,7 +45,7 @@ export const kernelCompletions: EditorCompletion =
|
|
|
45
45
|
return {
|
|
46
46
|
label: item['text'] as string,
|
|
47
47
|
type: item['type'] === '<unknown>' ? undefined : (item['type'] as string),
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
});
|
|
50
50
|
} else {
|
|
51
51
|
items = result.matches.map((item) => {
|