@difizen/libro-lsp 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 (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/adapters/adapter.d.ts +255 -0
  4. package/es/adapters/adapter.d.ts.map +1 -0
  5. package/es/adapters/adapter.js +647 -0
  6. package/es/adapters/notebook-adapter.d.ts +150 -0
  7. package/es/adapters/notebook-adapter.d.ts.map +1 -0
  8. package/es/adapters/notebook-adapter.js +588 -0
  9. package/es/adapters/status-message.d.ts +48 -0
  10. package/es/adapters/status-message.d.ts.map +1 -0
  11. package/es/adapters/status-message.js +110 -0
  12. package/es/connection-manager.d.ts +199 -0
  13. package/es/connection-manager.d.ts.map +1 -0
  14. package/es/connection-manager.js +685 -0
  15. package/es/connection.d.ts +149 -0
  16. package/es/connection.d.ts.map +1 -0
  17. package/es/connection.js +591 -0
  18. package/es/extractors/index.d.ts +4 -0
  19. package/es/extractors/index.d.ts.map +1 -0
  20. package/es/extractors/index.js +6 -0
  21. package/es/extractors/manager.d.ts +31 -0
  22. package/es/extractors/manager.d.ts.map +1 -0
  23. package/es/extractors/manager.js +90 -0
  24. package/es/extractors/text-extractor.d.ts +56 -0
  25. package/es/extractors/text-extractor.d.ts.map +1 -0
  26. package/es/extractors/text-extractor.js +72 -0
  27. package/es/extractors/types.d.ts +68 -0
  28. package/es/extractors/types.d.ts.map +1 -0
  29. package/es/extractors/types.js +1 -0
  30. package/es/feature.d.ts +29 -0
  31. package/es/feature.d.ts.map +1 -0
  32. package/es/feature.js +85 -0
  33. package/es/index.d.ts +19 -0
  34. package/es/index.d.ts.map +1 -0
  35. package/es/index.js +21 -0
  36. package/es/lsp-app-contribution.d.ts +19 -0
  37. package/es/lsp-app-contribution.d.ts.map +1 -0
  38. package/es/lsp-app-contribution.js +155 -0
  39. package/es/lsp-protocol.d.ts +10 -0
  40. package/es/lsp-protocol.d.ts.map +1 -0
  41. package/es/lsp-protocol.js +1 -0
  42. package/es/lsp.d.ts +136 -0
  43. package/es/lsp.d.ts.map +1 -0
  44. package/es/lsp.js +141 -0
  45. package/es/manager.d.ts +142 -0
  46. package/es/manager.d.ts.map +1 -0
  47. package/es/manager.js +423 -0
  48. package/es/module.d.ts +3 -0
  49. package/es/module.d.ts.map +1 -0
  50. package/es/module.js +21 -0
  51. package/es/plugin.d.ts +56 -0
  52. package/es/plugin.d.ts.map +1 -0
  53. package/es/plugin.js +0 -0
  54. package/es/positioning.d.ts +66 -0
  55. package/es/positioning.d.ts.map +1 -0
  56. package/es/positioning.js +96 -0
  57. package/es/schema.d.ts +240 -0
  58. package/es/schema.d.ts.map +1 -0
  59. package/es/schema.js +0 -0
  60. package/es/tokens.d.ts +677 -0
  61. package/es/tokens.d.ts.map +1 -0
  62. package/es/tokens.js +183 -0
  63. package/es/utils.d.ts +33 -0
  64. package/es/utils.d.ts.map +1 -0
  65. package/es/utils.js +168 -0
  66. package/es/virtual/document.d.ts +546 -0
  67. package/es/virtual/document.d.ts.map +1 -0
  68. package/es/virtual/document.js +1263 -0
  69. package/es/ws-connection/server-capability-registration.d.ts +19 -0
  70. package/es/ws-connection/server-capability-registration.d.ts.map +1 -0
  71. package/es/ws-connection/server-capability-registration.js +51 -0
  72. package/es/ws-connection/types.d.ts +76 -0
  73. package/es/ws-connection/types.d.ts.map +1 -0
  74. package/es/ws-connection/types.js +1 -0
  75. package/es/ws-connection/ws-connection.d.ts +105 -0
  76. package/es/ws-connection/ws-connection.d.ts.map +1 -0
  77. package/es/ws-connection/ws-connection.js +301 -0
  78. package/package.json +67 -0
  79. package/src/adapters/adapter.ts +611 -0
  80. package/src/adapters/notebook-adapter.ts +463 -0
  81. package/src/adapters/status-message.ts +93 -0
  82. package/src/connection-manager.ts +626 -0
  83. package/src/connection.ts +570 -0
  84. package/src/extractors/index.ts +6 -0
  85. package/src/extractors/manager.ts +82 -0
  86. package/src/extractors/text-extractor.ts +94 -0
  87. package/src/extractors/types.ts +78 -0
  88. package/src/feature.ts +60 -0
  89. package/src/index.spec.ts +10 -0
  90. package/src/index.ts +21 -0
  91. package/src/lsp-app-contribution.ts +83 -0
  92. package/src/lsp-protocol.ts +10 -0
  93. package/src/lsp.ts +160 -0
  94. package/src/manager.ts +358 -0
  95. package/src/module.ts +32 -0
  96. package/src/plugin.ts +62 -0
  97. package/src/positioning.ts +121 -0
  98. package/src/schema.ts +249 -0
  99. package/src/tokens.ts +843 -0
  100. package/src/utils.ts +109 -0
  101. package/src/virtual/document.ts +1250 -0
  102. package/src/ws-connection/server-capability-registration.ts +77 -0
  103. package/src/ws-connection/types.ts +102 -0
  104. package/src/ws-connection/ws-connection.ts +320 -0
package/es/manager.js ADDED
@@ -0,0 +1,423 @@
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
+ var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2;
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ 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; } } }; }
8
+ 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); }
9
+ 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; }
10
+ 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; }
11
+ 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); } }
12
+ 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); }); }; }
13
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+ 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); } }
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
+ 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); }
19
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
20
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
21
+ // Copyright (c) Jupyter Development Team.
22
+ // Distributed under the terms of the Modified BSD License.
23
+
24
+ import { URL } from '@difizen/libro-common';
25
+ import { PageConfig, ServerConnection, ServerManager } from '@difizen/libro-kernel';
26
+ import { Deferred, Emitter } from '@difizen/mana-app';
27
+ import { inject, postConstruct, transient } from '@difizen/mana-app';
28
+ import { ILanguageServerManagerOptions, URL_NS } from "./tokens.js";
29
+ export var LanguageServerManager = (_dec = transient(), _dec2 = inject(ServerConnection), _dec3 = inject(ServerManager), _dec4 = postConstruct(), _dec(_class = (_class2 = /*#__PURE__*/function () {
30
+ function LanguageServerManager(options) {
31
+ _classCallCheck(this, LanguageServerManager);
32
+ _initializerDefineProperty(this, "serverConnection", _descriptor, this);
33
+ _initializerDefineProperty(this, "serverManager", _descriptor2, this);
34
+ /**
35
+ * map of language server sessions.
36
+ */
37
+ this._sessions = new Map();
38
+ /**
39
+ * Map of language server specs.
40
+ */
41
+ this._specs = new Map();
42
+ /**
43
+ * Set of emitted warning message, message in this set will not be warned again.
44
+ */
45
+ this._warningsEmitted = new Set();
46
+ /**
47
+ * A promise resolved when this server manager is ready.
48
+ */
49
+ this._ready = new Deferred();
50
+ /**
51
+ * Signal emitted when a language server session is changed
52
+ */
53
+ this._sessionsChanged = new Emitter();
54
+ this._isDisposed = false;
55
+ /**
56
+ * Check if the manager is enabled or disabled
57
+ */
58
+ this._enabled = true;
59
+ this._baseUrl = options.baseUrl || PageConfig.getBaseUrl();
60
+ this._retries = options.retries || 2;
61
+ this._retriesInterval = options.retriesInterval || 10000;
62
+ this._statusCode = -1;
63
+ this._configuration = {};
64
+ }
65
+ LanguageServerManager = inject(ILanguageServerManagerOptions)(LanguageServerManager, undefined, 0) || LanguageServerManager;
66
+ _createClass(LanguageServerManager, [{
67
+ key: "init",
68
+ value: function init() {
69
+ var _this = this;
70
+ this.serverManager.ready.then(function () {
71
+ _this.fetchSessions();
72
+ return;
73
+ }).catch(console.error);
74
+ }
75
+
76
+ /**
77
+ * Check if the manager is enabled or disabled
78
+ */
79
+ }, {
80
+ key: "isEnabled",
81
+ get: function get() {
82
+ return this._enabled;
83
+ }
84
+ /**
85
+ * Check if the manager is disposed.
86
+ */
87
+ }, {
88
+ key: "isDisposed",
89
+ get: function get() {
90
+ return this._isDisposed;
91
+ }
92
+
93
+ /**
94
+ * Get the language server specs.
95
+ */
96
+ }, {
97
+ key: "specs",
98
+ get: function get() {
99
+ return this._specs;
100
+ }
101
+
102
+ /**
103
+ * Get the status end point.
104
+ */
105
+ }, {
106
+ key: "statusUrl",
107
+ get: function get() {
108
+ var _this$serverConnectio;
109
+ var baseUrl = (_this$serverConnectio = this.serverConnection.settings.baseUrl) !== null && _this$serverConnectio !== void 0 ? _this$serverConnectio : this._baseUrl;
110
+ return URL.join(baseUrl, URL_NS, 'status');
111
+ }
112
+
113
+ /**
114
+ * Signal emitted when a language server session is changed
115
+ */
116
+ }, {
117
+ key: "sessionsChanged",
118
+ get: function get() {
119
+ return this._sessionsChanged.event;
120
+ }
121
+
122
+ /**
123
+ * Get the map of language server sessions.
124
+ */
125
+ }, {
126
+ key: "sessions",
127
+ get: function get() {
128
+ return this._sessions;
129
+ }
130
+
131
+ /**
132
+ * A promise resolved when this server manager is ready.
133
+ */
134
+ }, {
135
+ key: "ready",
136
+ get: function get() {
137
+ return this._ready.promise;
138
+ }
139
+
140
+ /**
141
+ * Get the status code of server's responses.
142
+ */
143
+ }, {
144
+ key: "statusCode",
145
+ get: function get() {
146
+ return this._statusCode;
147
+ }
148
+
149
+ /**
150
+ * Enable the language server services
151
+ */
152
+ }, {
153
+ key: "enable",
154
+ value: function () {
155
+ var _enable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
156
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
157
+ while (1) switch (_context.prev = _context.next) {
158
+ case 0:
159
+ this._enabled = true;
160
+ _context.next = 3;
161
+ return this.fetchSessions();
162
+ case 3:
163
+ case "end":
164
+ return _context.stop();
165
+ }
166
+ }, _callee, this);
167
+ }));
168
+ function enable() {
169
+ return _enable.apply(this, arguments);
170
+ }
171
+ return enable;
172
+ }()
173
+ /**
174
+ * Disable the language server services
175
+ */
176
+ }, {
177
+ key: "disable",
178
+ value: function disable() {
179
+ this._enabled = false;
180
+ this._sessions = new Map();
181
+ this._sessionsChanged.fire(void 0);
182
+ }
183
+
184
+ /**
185
+ * Dispose the manager.
186
+ */
187
+ }, {
188
+ key: "dispose",
189
+ value: function dispose() {
190
+ if (this._isDisposed) {
191
+ return;
192
+ }
193
+ this._isDisposed = true;
194
+ }
195
+
196
+ /**
197
+ * Update the language server configuration.
198
+ */
199
+ }, {
200
+ key: "setConfiguration",
201
+ value: function setConfiguration(configuration) {
202
+ this._configuration = configuration;
203
+ }
204
+
205
+ /**
206
+ * Get matching language server for input language option.
207
+ *
208
+ * modify lsp server rank on ~/.jupyter/lab/user-settings/@jupyterlab/lsp-extension
209
+ */
210
+ }, {
211
+ key: "getMatchingServers",
212
+ value: function getMatchingServers(options) {
213
+ if (!options.language) {
214
+ console.error('Cannot match server by language: language not available; ensure that kernel and specs provide language and MIME type');
215
+ return [];
216
+ }
217
+ var matchingSessionsKeys = [];
218
+ var _iterator = _createForOfIteratorHelper(this._sessions.entries()),
219
+ _step;
220
+ try {
221
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
222
+ var _step$value = _slicedToArray(_step.value, 2),
223
+ key = _step$value[0],
224
+ session = _step$value[1];
225
+ if (this.isMatchingSpec(options, session.spec)) {
226
+ matchingSessionsKeys.push(key);
227
+ }
228
+ }
229
+ } catch (err) {
230
+ _iterator.e(err);
231
+ } finally {
232
+ _iterator.f();
233
+ }
234
+ return matchingSessionsKeys.sort(this.compareRanks.bind(this));
235
+ }
236
+
237
+ /**
238
+ * Get matching language server spec for input language option.
239
+ */
240
+ }, {
241
+ key: "getMatchingSpecs",
242
+ value: function getMatchingSpecs(options) {
243
+ var result = new Map();
244
+ var _iterator2 = _createForOfIteratorHelper(this._specs.entries()),
245
+ _step2;
246
+ try {
247
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
248
+ var _step2$value = _slicedToArray(_step2.value, 2),
249
+ key = _step2$value[0],
250
+ specification = _step2$value[1];
251
+ if (this.isMatchingSpec(options, specification)) {
252
+ result.set(key, specification);
253
+ }
254
+ }
255
+ } catch (err) {
256
+ _iterator2.e(err);
257
+ } finally {
258
+ _iterator2.f();
259
+ }
260
+ return result;
261
+ }
262
+
263
+ /**
264
+ * Fetch the server session list from the status endpoint. The server
265
+ * manager is ready once this method finishes.
266
+ */
267
+ }, {
268
+ key: "fetchSessions",
269
+ value: function () {
270
+ var _fetchSessions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
271
+ var sessions, response, data, _i, _Object$keys, key, id, oldKeys, oldKey, oldId;
272
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
273
+ while (1) switch (_context2.prev = _context2.next) {
274
+ case 0:
275
+ if (this._enabled) {
276
+ _context2.next = 2;
277
+ break;
278
+ }
279
+ return _context2.abrupt("return");
280
+ case 2:
281
+ _context2.prev = 2;
282
+ _context2.next = 5;
283
+ return this.serverConnection.makeRequest(this.statusUrl, {});
284
+ case 5:
285
+ response = _context2.sent;
286
+ this._statusCode = response.status;
287
+ if (response.ok) {
288
+ _context2.next = 10;
289
+ break;
290
+ }
291
+ if (this._retries > 0) {
292
+ this._retries -= 1;
293
+ setTimeout(this.fetchSessions.bind(this), this._retriesInterval);
294
+ } else {
295
+ this._ready.resolve(undefined);
296
+ console.warn('Missing jupyter_lsp server extension, skipping.');
297
+ }
298
+ return _context2.abrupt("return");
299
+ case 10:
300
+ _context2.next = 12;
301
+ return response.json();
302
+ case 12:
303
+ data = _context2.sent;
304
+ sessions = data.sessions;
305
+ try {
306
+ this.version = data.version;
307
+ this._specs = new Map(Object.entries(data.specs));
308
+ } catch (err) {
309
+ console.warn(err);
310
+ }
311
+ _context2.next = 22;
312
+ break;
313
+ case 17:
314
+ _context2.prev = 17;
315
+ _context2.t0 = _context2["catch"](2);
316
+ console.warn(_context2.t0);
317
+ this._ready.resolve(undefined);
318
+ return _context2.abrupt("return");
319
+ case 22:
320
+ for (_i = 0, _Object$keys = Object.keys(sessions); _i < _Object$keys.length; _i++) {
321
+ key = _Object$keys[_i];
322
+ id = key;
323
+ if (this._sessions.has(id)) {
324
+ Object.assign(this._sessions.get(id), sessions[key]);
325
+ } else {
326
+ this._sessions.set(id, sessions[key]);
327
+ }
328
+ }
329
+ oldKeys = this._sessions.keys();
330
+ for (oldKey in oldKeys) {
331
+ if (!sessions[oldKey]) {
332
+ oldId = oldKey;
333
+ this._sessions.delete(oldId);
334
+ }
335
+ }
336
+ this._sessionsChanged.fire(void 0);
337
+ this._ready.resolve(undefined);
338
+ case 27:
339
+ case "end":
340
+ return _context2.stop();
341
+ }
342
+ }, _callee2, this, [[2, 17]]);
343
+ }));
344
+ function fetchSessions() {
345
+ return _fetchSessions.apply(this, arguments);
346
+ }
347
+ return fetchSessions;
348
+ }()
349
+ /**
350
+ * Version number of sever session.
351
+ */
352
+ }, {
353
+ key: "isMatchingSpec",
354
+ value:
355
+ /**
356
+ * Check if input language option maths the language server spec.
357
+ */
358
+ function isMatchingSpec(options, spec) {
359
+ // most things speak language
360
+ // if language is not known, it is guessed based on MIME type earlier
361
+ // so some language should be available by now (which can be not so obvious, e.g. "plain" for txt documents)
362
+ var lowerCaseLanguage = options.language.toLocaleLowerCase();
363
+ return spec.languages.some(function (language) {
364
+ return language.toLocaleLowerCase() === lowerCaseLanguage;
365
+ });
366
+ }
367
+
368
+ /**
369
+ * Helper function to warn a message only once.
370
+ */
371
+ }, {
372
+ key: "warnOnce",
373
+ value: function warnOnce(arg) {
374
+ if (!this._warningsEmitted.has(arg)) {
375
+ this._warningsEmitted.add(arg);
376
+ console.warn(arg);
377
+ }
378
+ }
379
+
380
+ /**
381
+ * Compare the rank of two servers with the same language.
382
+ */
383
+ }, {
384
+ key: "compareRanks",
385
+ value: function compareRanks(a, b) {
386
+ var _ref, _this$_configuration$, _this$_configuration$2, _ref2, _this$_configuration$3, _this$_configuration$4;
387
+ var DEFAULT_RANK = 50;
388
+ var defaultServerRank = {
389
+ 'pyright-extended': DEFAULT_RANK + 3,
390
+ pyright: DEFAULT_RANK + 2,
391
+ pylsp: DEFAULT_RANK + 1,
392
+ 'bash-language-server': DEFAULT_RANK,
393
+ 'dockerfile-language-server-nodejs': DEFAULT_RANK,
394
+ 'javascript-typescript-langserver': DEFAULT_RANK,
395
+ 'unified-language-server': DEFAULT_RANK,
396
+ 'vscode-css-languageserver-bin': DEFAULT_RANK,
397
+ 'vscode-html-languageserver-bin': DEFAULT_RANK,
398
+ 'vscode-json-languageserver-bin': DEFAULT_RANK,
399
+ 'yaml-language-server': DEFAULT_RANK,
400
+ 'r-languageserver': DEFAULT_RANK
401
+ };
402
+ var aRank = (_ref = (_this$_configuration$ = (_this$_configuration$2 = this._configuration[a]) === null || _this$_configuration$2 === void 0 ? void 0 : _this$_configuration$2.rank) !== null && _this$_configuration$ !== void 0 ? _this$_configuration$ : defaultServerRank[a]) !== null && _ref !== void 0 ? _ref : DEFAULT_RANK;
403
+ var bRank = (_ref2 = (_this$_configuration$3 = (_this$_configuration$4 = this._configuration[b]) === null || _this$_configuration$4 === void 0 ? void 0 : _this$_configuration$4.rank) !== null && _this$_configuration$3 !== void 0 ? _this$_configuration$3 : defaultServerRank[b]) !== null && _ref2 !== void 0 ? _ref2 : DEFAULT_RANK;
404
+ if (aRank === bRank) {
405
+ this.warnOnce("Two matching servers: ".concat(a, " and ").concat(b, " have the same rank; choose which one to use by changing the rank in Advanced Settings Editor"));
406
+ return a.localeCompare(b);
407
+ }
408
+ // higher rank = higher in the list (descending order)
409
+ return bRank - aRank;
410
+ }
411
+ }]);
412
+ return LanguageServerManager;
413
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "serverConnection", [_dec2], {
414
+ configurable: true,
415
+ enumerable: true,
416
+ writable: true,
417
+ initializer: null
418
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "serverManager", [_dec3], {
419
+ configurable: true,
420
+ enumerable: true,
421
+ writable: true,
422
+ initializer: null
423
+ }), _applyDecoratedDescriptor(_class2.prototype, "init", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "init"), _class2.prototype)), _class2)) || _class);
package/es/module.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const LibroLSPModule: 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;AAY/C,eAAO,MAAM,cAAc,YAkBG,CAAC"}
package/es/module.js ADDED
@@ -0,0 +1,21 @@
1
+ import { LibroServerModule } from '@difizen/libro-kernel';
2
+ import { ManaModule } from '@difizen/mana-app';
3
+ import { DocumentConnectionManager } from "./connection-manager.js";
4
+ import { CodeExtractorsManager } from "./extractors/index.js";
5
+ import { FeatureManager } from "./feature.js";
6
+ import { LSPAppContribution } from "./lsp-app-contribution.js";
7
+ import { LanguageServerManager } from "./manager.js";
8
+ import { ILanguageServerManagerFactory, ILanguageServerManagerOptions } from "./tokens.js";
9
+ export var LibroLSPModule = ManaModule.create().register(LSPAppContribution, DocumentConnectionManager, FeatureManager, CodeExtractorsManager, LanguageServerManager, {
10
+ token: ILanguageServerManagerFactory,
11
+ useFactory: function useFactory(ctx) {
12
+ return function (option) {
13
+ var child = ctx.container.createChild();
14
+ child.register({
15
+ token: ILanguageServerManagerOptions,
16
+ useValue: option
17
+ });
18
+ return child.get(LanguageServerManager);
19
+ };
20
+ }
21
+ }).dependOn(LibroServerModule);
package/es/plugin.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run jlpm build:schema to regenerate this file.
5
+ */
6
+ /**
7
+ * Enable or disable the language server services.
8
+ */
9
+ export type Activate = 'off' | 'on';
10
+ /**
11
+ * When multiple servers match specific document/language, the server with the highest rank will be used
12
+ */
13
+ export type RankOfTheServer = number;
14
+ /**
15
+ * Whether to ask server to send logs with execution trace (for debugging). Accepted values are: "off", "messages", "verbose". Servers are allowed to ignore this request.
16
+ */
17
+ export type AskServersToSendTraceNotifications = 'off' | 'messages' | 'verbose';
18
+ /**
19
+ * Enable or disable the logging feature of the language servers.
20
+ */
21
+ export type LogCommunication = boolean;
22
+ /**
23
+ * Language Server Protocol settings.
24
+ */
25
+ export interface LanguageServersExperimental {
26
+ activate?: Activate;
27
+ languageServers?: LanguageServer;
28
+ setTrace?: AskServersToSendTraceNotifications;
29
+ logAllCommunication?: LogCommunication;
30
+ [k: string]: any;
31
+ }
32
+ /**
33
+ * Language-server specific configuration, keyed by implementation
34
+ */
35
+ export interface LanguageServer {
36
+ [k: string]: LanguageServer1;
37
+ }
38
+ /**
39
+ * This interface was referenced by `LanguageServer`'s JSON-Schema definition
40
+ * via the `patternProperty` ".*".
41
+ *
42
+ * This interface was referenced by `LanguageServersExperimental`'s JSON-Schema
43
+ * via the `definition` "languageServer".
44
+ */
45
+ export interface LanguageServer1 {
46
+ configuration?: LanguageServerConfigurations;
47
+ rank?: RankOfTheServer;
48
+ [k: string]: any;
49
+ }
50
+ /**
51
+ * Configuration to be sent to language server over LSP when initialized: see the specific language server's documentation for more
52
+ */
53
+ export interface LanguageServerConfigurations {
54
+ [k: string]: any;
55
+ }
56
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAC;AACpC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AACrC;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AAChF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,EAAE,kCAAkC,CAAC;IAC9C,mBAAmB,CAAC,EAAE,gBAAgB,CAAC;IACvC,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AACD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC;CAC9B;AACD;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,4BAA4B,CAAC;IAC7C,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AACD;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB"}
package/es/plugin.js ADDED
File without changes
@@ -0,0 +1,66 @@
1
+ import type { IPosition as CodeEditorPosition } from '@difizen/libro-code-editor';
2
+ import type * as lsp from 'vscode-languageserver-protocol';
3
+ /**
4
+ * CM5 position interface.
5
+ *
6
+ * TODO: Migrate to offset-only mode once `CodeEditor.IPosition`
7
+ * is migrated.
8
+ */
9
+ export interface Position {
10
+ /**
11
+ * Line number
12
+ */
13
+ line: number;
14
+ /**
15
+ * Position of character in line
16
+ */
17
+ ch: number;
18
+ }
19
+ /**
20
+ * is_* attributes are there only to enforce strict interface type checking
21
+ */
22
+ export interface ISourcePosition extends Position {
23
+ isSource: true;
24
+ }
25
+ export interface IEditorPosition extends Position {
26
+ isEditor: true;
27
+ }
28
+ export interface IVirtualPosition extends Position {
29
+ isVirtual: true;
30
+ }
31
+ export interface IRootPosition extends ISourcePosition {
32
+ isRoot: true;
33
+ }
34
+ /**
35
+ * Compare two `Position` variable.
36
+ *
37
+ */
38
+ export declare function isEqual(self: Position, other: Position): boolean;
39
+ /**
40
+ * Given a list of line and an offset from the start, compute the corresponding
41
+ * position in form of line and column number
42
+ *
43
+ * @param offset - number of spaces counted from the start of first line
44
+ * @param lines - list of lines to compute the position
45
+ * @return - the position of cursor
46
+ */
47
+ export declare function positionAtOffset(offset: number, lines: string[]): CodeEditorPosition;
48
+ /**
49
+ * Given a list of line and position in form of line and column number,
50
+ * compute the offset from the start of first line.
51
+ * @param position - postion of cursor
52
+ * @param lines - list of lines to compute the position
53
+ * @param linesIncludeBreaks - should count the line break as space?
54
+ * return - offset number
55
+ */
56
+ export declare function offsetAtPosition(position: CodeEditorPosition, lines: string[], linesIncludeBreaks?: boolean): number;
57
+ export declare namespace ProtocolCoordinates {
58
+ /**
59
+ * Check if the position is in the input range
60
+ *
61
+ * @param position - position in form of line and character number.
62
+ * @param range - range in from of start and end position.
63
+ */
64
+ function isWithinRange(position: lsp.Position, range: lsp.Range): boolean;
65
+ }
66
+ //# sourceMappingURL=positioning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positioning.d.ts","sourceRoot":"","sources":["../src/positioning.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,IAAI,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,KAAK,KAAK,GAAG,MAAM,gCAAgC,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,QAAQ,EAAE,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,QAAQ,EAAE,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,MAAM,EAAE,IAAI,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAcpF;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,EAAE,MAAM,EAAE,EACf,kBAAkB,UAAQ,GACzB,MAAM,CAaR;AAED,yBAAiB,mBAAmB,CAAC;IACnC;;;;;OAKG;IACH,SAAgB,aAAa,CAAC,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,OAAO,CAS/E;CACF"}