@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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/adapters/adapter.d.ts +255 -0
- package/es/adapters/adapter.d.ts.map +1 -0
- package/es/adapters/adapter.js +647 -0
- package/es/adapters/notebook-adapter.d.ts +150 -0
- package/es/adapters/notebook-adapter.d.ts.map +1 -0
- package/es/adapters/notebook-adapter.js +588 -0
- package/es/adapters/status-message.d.ts +48 -0
- package/es/adapters/status-message.d.ts.map +1 -0
- package/es/adapters/status-message.js +110 -0
- package/es/connection-manager.d.ts +199 -0
- package/es/connection-manager.d.ts.map +1 -0
- package/es/connection-manager.js +685 -0
- package/es/connection.d.ts +149 -0
- package/es/connection.d.ts.map +1 -0
- package/es/connection.js +591 -0
- package/es/extractors/index.d.ts +4 -0
- package/es/extractors/index.d.ts.map +1 -0
- package/es/extractors/index.js +6 -0
- package/es/extractors/manager.d.ts +31 -0
- package/es/extractors/manager.d.ts.map +1 -0
- package/es/extractors/manager.js +90 -0
- package/es/extractors/text-extractor.d.ts +56 -0
- package/es/extractors/text-extractor.d.ts.map +1 -0
- package/es/extractors/text-extractor.js +72 -0
- package/es/extractors/types.d.ts +68 -0
- package/es/extractors/types.d.ts.map +1 -0
- package/es/extractors/types.js +1 -0
- package/es/feature.d.ts +29 -0
- package/es/feature.d.ts.map +1 -0
- package/es/feature.js +85 -0
- package/es/index.d.ts +19 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +21 -0
- package/es/lsp-app-contribution.d.ts +19 -0
- package/es/lsp-app-contribution.d.ts.map +1 -0
- package/es/lsp-app-contribution.js +155 -0
- package/es/lsp-protocol.d.ts +10 -0
- package/es/lsp-protocol.d.ts.map +1 -0
- package/es/lsp-protocol.js +1 -0
- package/es/lsp.d.ts +136 -0
- package/es/lsp.d.ts.map +1 -0
- package/es/lsp.js +141 -0
- package/es/manager.d.ts +142 -0
- package/es/manager.d.ts.map +1 -0
- package/es/manager.js +423 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +21 -0
- package/es/plugin.d.ts +56 -0
- package/es/plugin.d.ts.map +1 -0
- package/es/plugin.js +0 -0
- package/es/positioning.d.ts +66 -0
- package/es/positioning.d.ts.map +1 -0
- package/es/positioning.js +96 -0
- package/es/schema.d.ts +240 -0
- package/es/schema.d.ts.map +1 -0
- package/es/schema.js +0 -0
- package/es/tokens.d.ts +677 -0
- package/es/tokens.d.ts.map +1 -0
- package/es/tokens.js +183 -0
- package/es/utils.d.ts +33 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +168 -0
- package/es/virtual/document.d.ts +546 -0
- package/es/virtual/document.d.ts.map +1 -0
- package/es/virtual/document.js +1263 -0
- package/es/ws-connection/server-capability-registration.d.ts +19 -0
- package/es/ws-connection/server-capability-registration.d.ts.map +1 -0
- package/es/ws-connection/server-capability-registration.js +51 -0
- package/es/ws-connection/types.d.ts +76 -0
- package/es/ws-connection/types.d.ts.map +1 -0
- package/es/ws-connection/types.js +1 -0
- package/es/ws-connection/ws-connection.d.ts +105 -0
- package/es/ws-connection/ws-connection.d.ts.map +1 -0
- package/es/ws-connection/ws-connection.js +301 -0
- package/package.json +67 -0
- package/src/adapters/adapter.ts +611 -0
- package/src/adapters/notebook-adapter.ts +463 -0
- package/src/adapters/status-message.ts +93 -0
- package/src/connection-manager.ts +626 -0
- package/src/connection.ts +570 -0
- package/src/extractors/index.ts +6 -0
- package/src/extractors/manager.ts +82 -0
- package/src/extractors/text-extractor.ts +94 -0
- package/src/extractors/types.ts +78 -0
- package/src/feature.ts +60 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +21 -0
- package/src/lsp-app-contribution.ts +83 -0
- package/src/lsp-protocol.ts +10 -0
- package/src/lsp.ts +160 -0
- package/src/manager.ts +358 -0
- package/src/module.ts +32 -0
- package/src/plugin.ts +62 -0
- package/src/positioning.ts +121 -0
- package/src/schema.ts +249 -0
- package/src/tokens.ts +843 -0
- package/src/utils.ts +109 -0
- package/src/virtual/document.ts +1250 -0
- package/src/ws-connection/server-capability-registration.ts +77 -0
- package/src/ws-connection/types.ts +102 -0
- package/src/ws-connection/ws-connection.ts +320 -0
|
@@ -0,0 +1,685 @@
|
|
|
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, _class;
|
|
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 _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; }
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
10
|
+
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; } } }; }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
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); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
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); }
|
|
18
|
+
/* eslint-disable @typescript-eslint/no-shadow */
|
|
19
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
20
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
21
|
+
// Copyright (c) Jupyter Development Team.
|
|
22
|
+
// Distributed under the terms of the Modified BSD License.
|
|
23
|
+
|
|
24
|
+
// import { PageConfig, URL } from '@jupyterlab/coreutils';
|
|
25
|
+
// import type { IDocumentWidget } from '@jupyterlab/docregistry';
|
|
26
|
+
|
|
27
|
+
import { URL } from '@difizen/libro-common';
|
|
28
|
+
import { PageConfig } from '@difizen/libro-kernel';
|
|
29
|
+
import { Emitter, inject, singleton } from '@difizen/mana-app';
|
|
30
|
+
import { LSPConnection } from "./connection.js";
|
|
31
|
+
import { ILSPDocumentConnectionManager, ILanguageServerManagerFactory } from "./tokens.js";
|
|
32
|
+
import { expandDottedPaths, sleep, untilReady } from "./utils.js";
|
|
33
|
+
/**
|
|
34
|
+
* Each Widget with a document (whether file or a notebook) has the same DocumentConnectionManager
|
|
35
|
+
* (see JupyterLabWidgetAdapter). Using id_path instead of uri led to documents being overwritten
|
|
36
|
+
* as two identical id_paths could be created for two different notebooks.
|
|
37
|
+
*/
|
|
38
|
+
export var DocumentConnectionManager = (_dec = singleton({
|
|
39
|
+
token: ILSPDocumentConnectionManager
|
|
40
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
41
|
+
function DocumentConnectionManager(languageServerManagerFactory) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
_classCallCheck(this, DocumentConnectionManager);
|
|
44
|
+
/**
|
|
45
|
+
* Fired the first time a connection is opened. These _should_ be the only
|
|
46
|
+
* invocation of `.on` (once remaining LSPFeature.connection_handlers are made
|
|
47
|
+
* singletons).
|
|
48
|
+
*/
|
|
49
|
+
this.onNewConnection = function (connection) {
|
|
50
|
+
var errorSignalSlot = function errorSignalSlot(e) {
|
|
51
|
+
console.error(e);
|
|
52
|
+
var error = e.length && e.length >= 1 ? e[0] : new Error();
|
|
53
|
+
if (error.message.indexOf('code = 1005') !== -1) {
|
|
54
|
+
console.error("Connection failed for ".concat(connection));
|
|
55
|
+
_this._forEachDocumentOfConnection(connection, function (virtualDocument) {
|
|
56
|
+
console.error('disconnecting ' + virtualDocument.uri);
|
|
57
|
+
_this._closed.fire({
|
|
58
|
+
connection: connection,
|
|
59
|
+
virtualDocument: virtualDocument
|
|
60
|
+
});
|
|
61
|
+
_this._ignoredLanguages.add(virtualDocument.language);
|
|
62
|
+
console.error("Cancelling further attempts to connect ".concat(virtualDocument.uri, " and other documents for this language (no support from the server)"));
|
|
63
|
+
});
|
|
64
|
+
} else if (error.message.indexOf('code = 1006') !== -1) {
|
|
65
|
+
console.error('Connection closed by the server');
|
|
66
|
+
} else {
|
|
67
|
+
console.error('Connection error:', e);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
connection.errorSignal(errorSignalSlot);
|
|
71
|
+
var serverInitializedSlot = function serverInitializedSlot() {
|
|
72
|
+
// Initialize using settings stored in the SettingRegistry
|
|
73
|
+
_this._forEachDocumentOfConnection(connection, function (virtualDocument) {
|
|
74
|
+
// TODO: is this still necessary, e.g. for status bar to update responsively?
|
|
75
|
+
_this._initialized.fire({
|
|
76
|
+
connection: connection,
|
|
77
|
+
virtualDocument: virtualDocument
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
_this.updateServerConfigurations(_this.initialConfigurations);
|
|
81
|
+
};
|
|
82
|
+
connection.serverInitialized(serverInitializedSlot);
|
|
83
|
+
var closeSignalSlot = function closeSignalSlot(closedManually) {
|
|
84
|
+
if (!closedManually) {
|
|
85
|
+
console.error('Connection unexpectedly disconnected');
|
|
86
|
+
} else {
|
|
87
|
+
console.warn('Connection closed');
|
|
88
|
+
_this._forEachDocumentOfConnection(connection, function (virtualDocument) {
|
|
89
|
+
_this._closed.fire({
|
|
90
|
+
connection: connection,
|
|
91
|
+
virtualDocument: virtualDocument
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
connection.closeSignal(closeSignalSlot);
|
|
97
|
+
};
|
|
98
|
+
this._initialized = new Emitter();
|
|
99
|
+
this._connected = new Emitter();
|
|
100
|
+
this._disconnected = new Emitter();
|
|
101
|
+
this._closed = new Emitter();
|
|
102
|
+
this._documentsChanged = new Emitter();
|
|
103
|
+
this.connections = new Map();
|
|
104
|
+
this.documents = new Map();
|
|
105
|
+
this.adapters = new Map();
|
|
106
|
+
this._ignoredLanguages = new Set();
|
|
107
|
+
this.languageServerManager = languageServerManagerFactory({});
|
|
108
|
+
Private.setLanguageServerManager(this.languageServerManager);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Map between the URI of the virtual document and its connection
|
|
113
|
+
* to the language server
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Map between the path of the document and its adapter
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Map between the URI of the virtual document and the document itself.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The language server manager plugin.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Initial configuration for the language servers.
|
|
130
|
+
*/
|
|
131
|
+
DocumentConnectionManager = inject(ILanguageServerManagerFactory)(DocumentConnectionManager, undefined, 0) || DocumentConnectionManager;
|
|
132
|
+
_createClass(DocumentConnectionManager, [{
|
|
133
|
+
key: "initialized",
|
|
134
|
+
get:
|
|
135
|
+
/**
|
|
136
|
+
* Signal emitted when the manager is initialized.
|
|
137
|
+
*/
|
|
138
|
+
function get() {
|
|
139
|
+
return this._initialized.event;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Signal emitted when the manager is connected to the server
|
|
144
|
+
*/
|
|
145
|
+
}, {
|
|
146
|
+
key: "connected",
|
|
147
|
+
get: function get() {
|
|
148
|
+
return this._connected.event;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Connection temporarily lost or could not be fully established; a re-connection will be attempted;
|
|
153
|
+
*/
|
|
154
|
+
}, {
|
|
155
|
+
key: "disconnected",
|
|
156
|
+
get: function get() {
|
|
157
|
+
return this._disconnected.event;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Connection was closed permanently and no-reconnection will be attempted, e.g.:
|
|
162
|
+
* - there was a serious server error
|
|
163
|
+
* - user closed the connection,
|
|
164
|
+
* - re-connection attempts exceeded,
|
|
165
|
+
*/
|
|
166
|
+
}, {
|
|
167
|
+
key: "closed",
|
|
168
|
+
get: function get() {
|
|
169
|
+
return this._closed.event;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Signal emitted when the document is changed.
|
|
174
|
+
*/
|
|
175
|
+
}, {
|
|
176
|
+
key: "documentsChanged",
|
|
177
|
+
get: function get() {
|
|
178
|
+
return this._documentsChanged.event;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Promise resolved when the language server manager is ready.
|
|
183
|
+
*/
|
|
184
|
+
}, {
|
|
185
|
+
key: "ready",
|
|
186
|
+
get: function get() {
|
|
187
|
+
return Private.getLanguageServerManager().ready;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Helper to connect various virtual document signal with callbacks of
|
|
192
|
+
* this class.
|
|
193
|
+
*
|
|
194
|
+
* @param virtualDocument - virtual document to be connected.
|
|
195
|
+
*/
|
|
196
|
+
}, {
|
|
197
|
+
key: "connectDocumentSignals",
|
|
198
|
+
value: function connectDocumentSignals(virtualDocument) {
|
|
199
|
+
virtualDocument.foreignDocumentOpened(this.onForeignDocumentOpened, this);
|
|
200
|
+
virtualDocument.foreignDocumentClosed(this.onForeignDocumentClosed, this);
|
|
201
|
+
this.documents.set(virtualDocument.uri, virtualDocument);
|
|
202
|
+
this._documentsChanged.fire(this.documents);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Helper to disconnect various virtual document signal with callbacks of
|
|
207
|
+
* this class.
|
|
208
|
+
*
|
|
209
|
+
* @param virtualDocument - virtual document to be disconnected.
|
|
210
|
+
*/
|
|
211
|
+
}, {
|
|
212
|
+
key: "disconnectDocumentSignals",
|
|
213
|
+
value: function disconnectDocumentSignals(virtualDocument) {
|
|
214
|
+
var emit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
215
|
+
this.documents.delete(virtualDocument.uri);
|
|
216
|
+
var _iterator = _createForOfIteratorHelper(virtualDocument.foreignDocuments.values()),
|
|
217
|
+
_step;
|
|
218
|
+
try {
|
|
219
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
220
|
+
var foreign = _step.value;
|
|
221
|
+
this.disconnectDocumentSignals(foreign, false);
|
|
222
|
+
}
|
|
223
|
+
} catch (err) {
|
|
224
|
+
_iterator.e(err);
|
|
225
|
+
} finally {
|
|
226
|
+
_iterator.f();
|
|
227
|
+
}
|
|
228
|
+
if (emit) {
|
|
229
|
+
this._documentsChanged.fire(this.documents);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Handle foreign document opened event.
|
|
235
|
+
*/
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
237
|
+
}, {
|
|
238
|
+
key: "onForeignDocumentOpened",
|
|
239
|
+
value: function onForeignDocumentOpened(context) {
|
|
240
|
+
/** no-op */
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Handle foreign document closed event.
|
|
245
|
+
*/
|
|
246
|
+
}, {
|
|
247
|
+
key: "onForeignDocumentClosed",
|
|
248
|
+
value: function onForeignDocumentClosed(context) {
|
|
249
|
+
var foreignDocument = context.foreignDocument;
|
|
250
|
+
this.unregisterDocument(foreignDocument.uri, false);
|
|
251
|
+
this.disconnectDocumentSignals(foreignDocument);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Register a widget adapter with this manager
|
|
256
|
+
*
|
|
257
|
+
* @param path - path to the inner document of the adapter
|
|
258
|
+
* @param adapter - the adapter to be registered
|
|
259
|
+
*/
|
|
260
|
+
}, {
|
|
261
|
+
key: "registerAdapter",
|
|
262
|
+
value: function registerAdapter(path, adapter) {
|
|
263
|
+
var _this2 = this;
|
|
264
|
+
this.adapters.set(path, adapter);
|
|
265
|
+
adapter.onDispose(function () {
|
|
266
|
+
if (adapter.virtualDocument) {
|
|
267
|
+
_this2.documents.delete(adapter.virtualDocument.uri);
|
|
268
|
+
}
|
|
269
|
+
_this2.adapters.delete(path);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Handles the settings that do not require an existing connection
|
|
275
|
+
* with a language server (or can influence to which server the
|
|
276
|
+
* connection will be created, e.g. `rank`).
|
|
277
|
+
*
|
|
278
|
+
* This function should be called **before** initialization of servers.
|
|
279
|
+
*/
|
|
280
|
+
}, {
|
|
281
|
+
key: "updateConfiguration",
|
|
282
|
+
value: function updateConfiguration(allServerSettings) {
|
|
283
|
+
this.languageServerManager.setConfiguration(allServerSettings);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Handles the settings that the language servers accept using
|
|
288
|
+
* `onDidChangeConfiguration` messages, which should be passed under
|
|
289
|
+
* the "serverSettings" keyword in the setting registry.
|
|
290
|
+
* Other configuration options are handled by `updateConfiguration` instead.
|
|
291
|
+
*
|
|
292
|
+
* This function should be called **after** initialization of servers.
|
|
293
|
+
*/
|
|
294
|
+
}, {
|
|
295
|
+
key: "updateServerConfigurations",
|
|
296
|
+
value: function updateServerConfigurations(allServerSettings) {
|
|
297
|
+
var languageServerId;
|
|
298
|
+
for (languageServerId in allServerSettings) {
|
|
299
|
+
if (!Object.prototype.hasOwnProperty.call(allServerSettings, languageServerId)) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
var rawSettings = allServerSettings[languageServerId];
|
|
303
|
+
var parsedSettings = expandDottedPaths(rawSettings.configuration || {});
|
|
304
|
+
var serverSettings = {
|
|
305
|
+
settings: parsedSettings
|
|
306
|
+
};
|
|
307
|
+
Private.updateServerConfiguration(languageServerId, serverSettings);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}, {
|
|
311
|
+
key: "retryToConnect",
|
|
312
|
+
value:
|
|
313
|
+
/**
|
|
314
|
+
* Retry to connect to the server each `reconnectDelay` seconds
|
|
315
|
+
* and for `retrialsLeft` times.
|
|
316
|
+
* TODO: presently no longer referenced. A failing connection would close
|
|
317
|
+
* the socket, triggering the language server on the other end to exit.
|
|
318
|
+
*/
|
|
319
|
+
function () {
|
|
320
|
+
var _retryToConnect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options, reconnectDelay) {
|
|
321
|
+
var retrialsLeft,
|
|
322
|
+
virtualDocument,
|
|
323
|
+
interval,
|
|
324
|
+
success,
|
|
325
|
+
_args = arguments;
|
|
326
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
327
|
+
while (1) switch (_context.prev = _context.next) {
|
|
328
|
+
case 0:
|
|
329
|
+
retrialsLeft = _args.length > 2 && _args[2] !== undefined ? _args[2] : -1;
|
|
330
|
+
virtualDocument = options.virtualDocument;
|
|
331
|
+
if (!this._ignoredLanguages.has(virtualDocument.language)) {
|
|
332
|
+
_context.next = 4;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
return _context.abrupt("return");
|
|
336
|
+
case 4:
|
|
337
|
+
interval = reconnectDelay * 1000;
|
|
338
|
+
success = false;
|
|
339
|
+
case 6:
|
|
340
|
+
if (!(retrialsLeft !== 0 && !success)) {
|
|
341
|
+
_context.next = 15;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
_context.next = 9;
|
|
345
|
+
return this.connect(options)
|
|
346
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
347
|
+
.then(function () {
|
|
348
|
+
success = true;
|
|
349
|
+
return;
|
|
350
|
+
}).catch(function (e) {
|
|
351
|
+
console.warn(e);
|
|
352
|
+
});
|
|
353
|
+
case 9:
|
|
354
|
+
console.warn('will attempt to re-connect in ' + interval / 1000 + ' seconds');
|
|
355
|
+
_context.next = 12;
|
|
356
|
+
return sleep(interval);
|
|
357
|
+
case 12:
|
|
358
|
+
// gradually increase the time delay, up to 5 sec
|
|
359
|
+
interval = interval < 5 * 1000 ? interval + 500 : interval;
|
|
360
|
+
_context.next = 6;
|
|
361
|
+
break;
|
|
362
|
+
case 15:
|
|
363
|
+
case "end":
|
|
364
|
+
return _context.stop();
|
|
365
|
+
}
|
|
366
|
+
}, _callee, this);
|
|
367
|
+
}));
|
|
368
|
+
function retryToConnect(_x, _x2) {
|
|
369
|
+
return _retryToConnect.apply(this, arguments);
|
|
370
|
+
}
|
|
371
|
+
return retryToConnect;
|
|
372
|
+
}()
|
|
373
|
+
/**
|
|
374
|
+
* Disconnect the connection to the language server of the requested
|
|
375
|
+
* language.
|
|
376
|
+
*/
|
|
377
|
+
}, {
|
|
378
|
+
key: "disconnect",
|
|
379
|
+
value: function disconnect(languageId) {
|
|
380
|
+
Private.disconnect(languageId);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Create a new connection to the language server
|
|
385
|
+
* @return A promise of the LSP connection
|
|
386
|
+
*/
|
|
387
|
+
}, {
|
|
388
|
+
key: "connect",
|
|
389
|
+
value: function () {
|
|
390
|
+
var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
391
|
+
var firstTimeoutSeconds,
|
|
392
|
+
secondTimeoutMinutes,
|
|
393
|
+
connection,
|
|
394
|
+
virtualDocument,
|
|
395
|
+
_args2 = arguments;
|
|
396
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
397
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
398
|
+
case 0:
|
|
399
|
+
firstTimeoutSeconds = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 30;
|
|
400
|
+
secondTimeoutMinutes = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 5;
|
|
401
|
+
_context2.next = 4;
|
|
402
|
+
return this._connectSocket(options);
|
|
403
|
+
case 4:
|
|
404
|
+
connection = _context2.sent;
|
|
405
|
+
virtualDocument = options.virtualDocument;
|
|
406
|
+
if (connection) {
|
|
407
|
+
_context2.next = 8;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
return _context2.abrupt("return");
|
|
411
|
+
case 8:
|
|
412
|
+
if (connection.isReady) {
|
|
413
|
+
_context2.next = 26;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
_context2.prev = 9;
|
|
417
|
+
_context2.next = 12;
|
|
418
|
+
return untilReady(function () {
|
|
419
|
+
return connection.isReady;
|
|
420
|
+
}, Math.round(firstTimeoutSeconds * 1000 / 150), 150);
|
|
421
|
+
case 12:
|
|
422
|
+
_context2.next = 26;
|
|
423
|
+
break;
|
|
424
|
+
case 14:
|
|
425
|
+
_context2.prev = 14;
|
|
426
|
+
_context2.t0 = _context2["catch"](9);
|
|
427
|
+
console.warn("Connection to ".concat(virtualDocument.uri, " timed out after ").concat(firstTimeoutSeconds, " seconds, will continue retrying for another ").concat(secondTimeoutMinutes, " minutes"));
|
|
428
|
+
_context2.prev = 17;
|
|
429
|
+
_context2.next = 20;
|
|
430
|
+
return untilReady(function () {
|
|
431
|
+
return connection.isReady;
|
|
432
|
+
}, 60 * secondTimeoutMinutes, 1000);
|
|
433
|
+
case 20:
|
|
434
|
+
_context2.next = 26;
|
|
435
|
+
break;
|
|
436
|
+
case 22:
|
|
437
|
+
_context2.prev = 22;
|
|
438
|
+
_context2.t1 = _context2["catch"](17);
|
|
439
|
+
console.warn("Connection to ".concat(virtualDocument.uri, " timed out again after ").concat(secondTimeoutMinutes, " minutes, giving up"));
|
|
440
|
+
return _context2.abrupt("return");
|
|
441
|
+
case 26:
|
|
442
|
+
this._connected.fire({
|
|
443
|
+
connection: connection,
|
|
444
|
+
virtualDocument: virtualDocument
|
|
445
|
+
});
|
|
446
|
+
return _context2.abrupt("return", connection);
|
|
447
|
+
case 28:
|
|
448
|
+
case "end":
|
|
449
|
+
return _context2.stop();
|
|
450
|
+
}
|
|
451
|
+
}, _callee2, this, [[9, 14], [17, 22]]);
|
|
452
|
+
}));
|
|
453
|
+
function connect(_x3) {
|
|
454
|
+
return _connect.apply(this, arguments);
|
|
455
|
+
}
|
|
456
|
+
return connect;
|
|
457
|
+
}()
|
|
458
|
+
/**
|
|
459
|
+
* Disconnect the signals of requested virtual document uri.
|
|
460
|
+
*/
|
|
461
|
+
}, {
|
|
462
|
+
key: "unregisterDocument",
|
|
463
|
+
value: function unregisterDocument(uri) {
|
|
464
|
+
var emit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
465
|
+
var connection = this.connections.get(uri);
|
|
466
|
+
if (connection) {
|
|
467
|
+
this.connections.delete(uri);
|
|
468
|
+
var allConnection = new Set(this.connections.values());
|
|
469
|
+
if (!allConnection.has(connection)) {
|
|
470
|
+
this.disconnect(connection.serverIdentifier);
|
|
471
|
+
connection.dispose();
|
|
472
|
+
}
|
|
473
|
+
if (emit) {
|
|
474
|
+
this._documentsChanged.fire(this.documents);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Enable or disable the logging feature of the language servers
|
|
481
|
+
*/
|
|
482
|
+
}, {
|
|
483
|
+
key: "updateLogging",
|
|
484
|
+
value: function updateLogging(logAllCommunication, setTrace) {
|
|
485
|
+
var _iterator2 = _createForOfIteratorHelper(this.connections.values()),
|
|
486
|
+
_step2;
|
|
487
|
+
try {
|
|
488
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
489
|
+
var connection = _step2.value;
|
|
490
|
+
connection.logAllCommunication = logAllCommunication;
|
|
491
|
+
if (setTrace !== null) {
|
|
492
|
+
connection.clientNotifications['$/setTrace'].fire({
|
|
493
|
+
value: setTrace
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} catch (err) {
|
|
498
|
+
_iterator2.e(err);
|
|
499
|
+
} finally {
|
|
500
|
+
_iterator2.f();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Create the LSP connection for requested virtual document.
|
|
506
|
+
*
|
|
507
|
+
* @return Return the promise of the LSP connection.
|
|
508
|
+
*/
|
|
509
|
+
}, {
|
|
510
|
+
key: "_connectSocket",
|
|
511
|
+
value: function () {
|
|
512
|
+
var _connectSocket2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(options) {
|
|
513
|
+
var language, capabilities, virtualDocument, uris, matchingServers, languageServerId, connection;
|
|
514
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
515
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
516
|
+
case 0:
|
|
517
|
+
language = options.language, capabilities = options.capabilities, virtualDocument = options.virtualDocument;
|
|
518
|
+
this.connectDocumentSignals(virtualDocument);
|
|
519
|
+
uris = DocumentConnectionManager.solveUris(virtualDocument, language);
|
|
520
|
+
matchingServers = this.languageServerManager.getMatchingServers({
|
|
521
|
+
language: language
|
|
522
|
+
}); // for now use only the server with the highest rank.
|
|
523
|
+
languageServerId = matchingServers.length === 0 ? null : matchingServers[0]; // lazily load 1) the underlying library (1.5mb) and/or 2) a live WebSocket-
|
|
524
|
+
// like connection: either already connected or potentially in the process
|
|
525
|
+
// of connecting.
|
|
526
|
+
if (uris) {
|
|
527
|
+
_context3.next = 7;
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
return _context3.abrupt("return");
|
|
531
|
+
case 7:
|
|
532
|
+
_context3.next = 9;
|
|
533
|
+
return Private.connection(language, languageServerId, uris, this.onNewConnection, capabilities);
|
|
534
|
+
case 9:
|
|
535
|
+
connection = _context3.sent;
|
|
536
|
+
// if connecting for the first time, all documents subsequent documents will
|
|
537
|
+
// be re-opened and synced
|
|
538
|
+
this.connections.set(virtualDocument.uri, connection);
|
|
539
|
+
return _context3.abrupt("return", connection);
|
|
540
|
+
case 12:
|
|
541
|
+
case "end":
|
|
542
|
+
return _context3.stop();
|
|
543
|
+
}
|
|
544
|
+
}, _callee3, this);
|
|
545
|
+
}));
|
|
546
|
+
function _connectSocket(_x4) {
|
|
547
|
+
return _connectSocket2.apply(this, arguments);
|
|
548
|
+
}
|
|
549
|
+
return _connectSocket;
|
|
550
|
+
}()
|
|
551
|
+
/**
|
|
552
|
+
* Helper to apply callback on all documents of a connection.
|
|
553
|
+
*/
|
|
554
|
+
}, {
|
|
555
|
+
key: "_forEachDocumentOfConnection",
|
|
556
|
+
value: function _forEachDocumentOfConnection(connection, callback) {
|
|
557
|
+
var _iterator3 = _createForOfIteratorHelper(this.connections.entries()),
|
|
558
|
+
_step3;
|
|
559
|
+
try {
|
|
560
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
561
|
+
var _step3$value = _slicedToArray(_step3.value, 2),
|
|
562
|
+
virtualDocumentUri = _step3$value[0],
|
|
563
|
+
currentConnection = _step3$value[1];
|
|
564
|
+
if (connection !== currentConnection) {
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
callback(this.documents.get(virtualDocumentUri));
|
|
568
|
+
}
|
|
569
|
+
} catch (err) {
|
|
570
|
+
_iterator3.e(err);
|
|
571
|
+
} finally {
|
|
572
|
+
_iterator3.f();
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Set of ignored languages
|
|
578
|
+
*/
|
|
579
|
+
}]);
|
|
580
|
+
return DocumentConnectionManager;
|
|
581
|
+
}()) || _class);
|
|
582
|
+
(function (_DocumentConnectionManager) {
|
|
583
|
+
/**
|
|
584
|
+
* Generate the URI of a virtual document from input
|
|
585
|
+
*
|
|
586
|
+
* @param virtualDocument - the virtual document
|
|
587
|
+
* @param language - language of the document
|
|
588
|
+
*/
|
|
589
|
+
function solveUris(virtualDocument, language) {
|
|
590
|
+
var wsBase = PageConfig.getBaseUrl().replace(/^http/, 'ws');
|
|
591
|
+
var rootUri = PageConfig.getOption('rootUri');
|
|
592
|
+
var virtualDocumentsUri = PageConfig.getOption('virtualDocumentsUri');
|
|
593
|
+
var baseUri = virtualDocument.hasLspSupportedFile ? rootUri : virtualDocumentsUri;
|
|
594
|
+
|
|
595
|
+
// for now take the best match only
|
|
596
|
+
var matchingServers = Private.getLanguageServerManager().getMatchingServers({
|
|
597
|
+
language: language
|
|
598
|
+
});
|
|
599
|
+
var languageServerId = matchingServers.length === 0 ? null : matchingServers[0];
|
|
600
|
+
if (languageServerId === null) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// workaround url-parse bug(s) (see https://github.com/jupyter-lsp/jupyterlab-lsp/issues/595)
|
|
605
|
+
var documentUri = URL.join(baseUri, virtualDocument.uri);
|
|
606
|
+
if (!documentUri.startsWith('file:///') && documentUri.startsWith('file://')) {
|
|
607
|
+
documentUri = documentUri.replace('file://', 'file:///');
|
|
608
|
+
if (documentUri.startsWith('file:///users/') && baseUri.startsWith('file:///Users/')) {
|
|
609
|
+
documentUri = documentUri.replace('file:///users/', 'file:///Users/');
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
base: baseUri,
|
|
614
|
+
document: documentUri,
|
|
615
|
+
server: URL.join('ws://jupyter-lsp', language),
|
|
616
|
+
socket: URL.join(wsBase, 'lsp', 'ws', languageServerId)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
_DocumentConnectionManager.solveUris = solveUris;
|
|
620
|
+
})(DocumentConnectionManager || (DocumentConnectionManager = {}));
|
|
621
|
+
/**
|
|
622
|
+
* Namespace primarily for language-keyed cache of LSPConnections
|
|
623
|
+
*/
|
|
624
|
+
var Private;
|
|
625
|
+
(function (_Private) {
|
|
626
|
+
var _connections = new Map();
|
|
627
|
+
var _languageServerManager;
|
|
628
|
+
function getLanguageServerManager() {
|
|
629
|
+
return _languageServerManager;
|
|
630
|
+
}
|
|
631
|
+
_Private.getLanguageServerManager = getLanguageServerManager;
|
|
632
|
+
function setLanguageServerManager(languageServerManager) {
|
|
633
|
+
_languageServerManager = languageServerManager;
|
|
634
|
+
}
|
|
635
|
+
_Private.setLanguageServerManager = setLanguageServerManager;
|
|
636
|
+
function disconnect(languageServerId) {
|
|
637
|
+
var connection = _connections.get(languageServerId);
|
|
638
|
+
if (connection) {
|
|
639
|
+
connection.close();
|
|
640
|
+
_connections.delete(languageServerId);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
_Private.disconnect = disconnect;
|
|
644
|
+
function connection(_x5, _x6, _x7, _x8, _x9) {
|
|
645
|
+
return _connection.apply(this, arguments);
|
|
646
|
+
}
|
|
647
|
+
function _connection() {
|
|
648
|
+
_connection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(language, languageServerId, uris, onCreate, capabilities) {
|
|
649
|
+
var connection, socket, _connection2;
|
|
650
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
651
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
652
|
+
case 0:
|
|
653
|
+
connection = _connections.get(languageServerId);
|
|
654
|
+
if (!connection) {
|
|
655
|
+
socket = new WebSocket(uris.socket);
|
|
656
|
+
_connection2 = new LSPConnection({
|
|
657
|
+
languageId: language,
|
|
658
|
+
serverUri: uris.server,
|
|
659
|
+
rootUri: uris.base,
|
|
660
|
+
serverIdentifier: languageServerId,
|
|
661
|
+
capabilities: capabilities
|
|
662
|
+
});
|
|
663
|
+
_connections.set(languageServerId, _connection2);
|
|
664
|
+
_connection2.connect(socket);
|
|
665
|
+
onCreate(_connection2);
|
|
666
|
+
}
|
|
667
|
+
connection = _connections.get(languageServerId);
|
|
668
|
+
return _context4.abrupt("return", connection);
|
|
669
|
+
case 4:
|
|
670
|
+
case "end":
|
|
671
|
+
return _context4.stop();
|
|
672
|
+
}
|
|
673
|
+
}, _callee4);
|
|
674
|
+
}));
|
|
675
|
+
return _connection.apply(this, arguments);
|
|
676
|
+
}
|
|
677
|
+
_Private.connection = connection;
|
|
678
|
+
function updateServerConfiguration(languageServerId, settings) {
|
|
679
|
+
var connection = _connections.get(languageServerId);
|
|
680
|
+
if (connection) {
|
|
681
|
+
connection.sendConfigurationChange(settings);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
_Private.updateServerConfiguration = updateServerConfiguration;
|
|
685
|
+
})(Private || (Private = {}));
|