@difizen/libro-language-client 0.1.26 → 0.1.27

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 (36) hide show
  1. package/es/common/codeConverter.d.ts +15 -1
  2. package/es/common/codeConverter.d.ts.map +1 -1
  3. package/es/common/codeConverter.js +122 -8
  4. package/es/common/protocolConverter.d.ts +3 -1
  5. package/es/common/protocolConverter.d.ts.map +1 -1
  6. package/es/common/protocolConverter.js +85 -2
  7. package/es/common/vscodeAdaptor/convertor.d.ts.map +1 -1
  8. package/es/common/vscodeAdaptor/convertor.js +5 -4
  9. package/es/common/vscodeAdaptor/libroWorkspace.d.ts +3 -2
  10. package/es/common/vscodeAdaptor/libroWorkspace.d.ts.map +1 -1
  11. package/es/common/vscodeAdaptor/libroWorkspace.js +21 -5
  12. package/es/common/vscodeAdaptor/monacoLanguages.d.ts +3 -0
  13. package/es/common/vscodeAdaptor/monacoLanguages.d.ts.map +1 -1
  14. package/es/common/vscodeAdaptor/monacoLanguages.js +256 -68
  15. package/es/index.d.ts +1 -0
  16. package/es/index.d.ts.map +1 -1
  17. package/es/index.js +2 -1
  18. package/es/libro-language-client-contribution.d.ts +4 -0
  19. package/es/libro-language-client-contribution.d.ts.map +1 -1
  20. package/es/libro-language-client-contribution.js +108 -30
  21. package/es/libro-language-client-manager.d.ts +4 -0
  22. package/es/libro-language-client-manager.d.ts.map +1 -1
  23. package/es/libro-language-client-manager.js +24 -11
  24. package/es/util.d.ts +9 -0
  25. package/es/util.d.ts.map +1 -0
  26. package/es/util.js +32 -0
  27. package/package.json +6 -5
  28. package/src/common/codeConverter.ts +133 -1
  29. package/src/common/protocolConverter.ts +66 -0
  30. package/src/common/vscodeAdaptor/convertor.ts +5 -4
  31. package/src/common/vscodeAdaptor/libroWorkspace.ts +16 -4
  32. package/src/common/vscodeAdaptor/monacoLanguages.ts +114 -6
  33. package/src/index.ts +1 -0
  34. package/src/libro-language-client-contribution.ts +88 -6
  35. package/src/libro-language-client-manager.ts +9 -1
  36. package/src/util.ts +43 -0
@@ -1,5 +1,5 @@
1
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, _class, _class2, _descriptor, _descriptor2;
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
3
3
  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; } } }; }
4
4
  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); }
5
5
  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; }
@@ -14,18 +14,25 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
14
14
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
15
  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; }
16
16
  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.'); }
17
+ import { EditorCellView, ILibroWorkspaceService, LibroService } from '@difizen/libro-core';
18
+ import { ExecutableNotebookModel } from '@difizen/libro-kernel';
17
19
  import { ApplicationContribution, inject, singleton } from '@difizen/mana-app';
20
+ import * as monaco from '@difizen/monaco-editor-core';
21
+ import { URI } from 'vscode-uri';
18
22
  import { CloseAction, ErrorAction } from "./common/api.js";
19
23
  import { LSPEnv } from "./common/vscodeAdaptor/lspEnv.js";
20
24
  import { workspace } from "./common/vscodeAdaptor/vscodeAdaptor.js";
21
25
  import { LibroLanguageClientManager } from "./libro-language-client-manager.js";
26
+ import { getCellURI, toEditorRange, toMonacoPosition } from "./util.js";
22
27
  export var LibroLanguageClientContribution = (_dec = singleton({
23
28
  contrib: [ApplicationContribution]
24
- }), _dec2 = inject(LibroLanguageClientManager), _dec3 = inject(LSPEnv), _dec(_class = (_class2 = /*#__PURE__*/function () {
29
+ }), _dec2 = inject(ILibroWorkspaceService), _dec3 = inject(LibroLanguageClientManager), _dec4 = inject(LSPEnv), _dec5 = inject(LibroService), _dec(_class = (_class2 = /*#__PURE__*/function () {
25
30
  function LibroLanguageClientContribution() {
26
31
  _classCallCheck(this, LibroLanguageClientContribution);
27
- _initializerDefineProperty(this, "libroLanguageClientManager", _descriptor, this);
28
- _initializerDefineProperty(this, "lspEnv", _descriptor2, this);
32
+ _initializerDefineProperty(this, "libroWorkspaceService", _descriptor, this);
33
+ _initializerDefineProperty(this, "libroLanguageClientManager", _descriptor2, this);
34
+ _initializerDefineProperty(this, "lspEnv", _descriptor3, this);
35
+ _initializerDefineProperty(this, "libroService", _descriptor4, this);
29
36
  }
30
37
  _createClass(LibroLanguageClientContribution, [{
31
38
  key: "onViewStart",
@@ -36,7 +43,8 @@ export var LibroLanguageClientContribution = (_dec = singleton({
36
43
  case 0:
37
44
  // not block
38
45
  this.startLanguageClients();
39
- case 1:
46
+ this.setupEditorOpener();
47
+ case 2:
40
48
  case "end":
41
49
  return _context.stop();
42
50
  }
@@ -51,27 +59,31 @@ export var LibroLanguageClientContribution = (_dec = singleton({
51
59
  key: "startLanguageClients",
52
60
  value: function () {
53
61
  var _startLanguageClients = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
62
+ var _this = this;
54
63
  var serverIds, _iterator, _step, serverId;
55
64
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
56
65
  while (1) switch (_context2.prev = _context2.next) {
57
66
  case 0:
58
67
  _context2.next = 2;
59
- return this.lspEnv.ready;
68
+ return this.libroWorkspaceService.ready;
60
69
  case 2:
61
70
  _context2.next = 4;
62
- return this.libroLanguageClientManager.getServers();
71
+ return this.lspEnv.ready;
63
72
  case 4:
73
+ _context2.next = 6;
74
+ return this.libroLanguageClientManager.getServers();
75
+ case 6:
64
76
  serverIds = _context2.sent;
65
77
  _iterator = _createForOfIteratorHelper(serverIds);
66
- _context2.prev = 6;
78
+ _context2.prev = 8;
67
79
  _iterator.s();
68
- case 8:
80
+ case 10:
69
81
  if ((_step = _iterator.n()).done) {
70
- _context2.next = 14;
82
+ _context2.next = 16;
71
83
  break;
72
84
  }
73
85
  serverId = _step.value;
74
- _context2.next = 12;
86
+ _context2.next = 14;
75
87
  return this.libroLanguageClientManager.getOrCreateLanguageClient(serverId, {
76
88
  name: "".concat(serverId, " Language Client"),
77
89
  clientOptions: {
@@ -92,50 +104,116 @@ export var LibroLanguageClientContribution = (_dec = singleton({
92
104
  };
93
105
  }
94
106
  },
95
- // pyright requires a workspace folder to be present, otherwise it will not work
96
- // workspaceFolder: {
97
- // index: 0,
98
- // name: 'workspace',
99
- // uri: URI.parse('/examples'), // abs path
100
- // },
101
107
  synchronize: {
102
108
  fileEvents: [workspace.createFileSystemWatcher('**', false)]
103
109
  }
104
110
  }
105
111
  });
106
- case 12:
107
- _context2.next = 8;
108
- break;
109
112
  case 14:
110
- _context2.next = 19;
113
+ _context2.next = 10;
111
114
  break;
112
115
  case 16:
113
- _context2.prev = 16;
114
- _context2.t0 = _context2["catch"](6);
116
+ _context2.next = 21;
117
+ break;
118
+ case 18:
119
+ _context2.prev = 18;
120
+ _context2.t0 = _context2["catch"](8);
115
121
  _iterator.e(_context2.t0);
116
- case 19:
117
- _context2.prev = 19;
122
+ case 21:
123
+ _context2.prev = 21;
118
124
  _iterator.f();
119
- return _context2.finish(19);
120
- case 22:
125
+ return _context2.finish(21);
126
+ case 24:
127
+ this.libroLanguageClientManager.getFeatureStatus('textDocument/formatting').then(function (status) {
128
+ _this.libroService.hasFormatter = status;
129
+ return;
130
+ }).catch(function () {
131
+ return;
132
+ });
133
+ case 25:
121
134
  case "end":
122
135
  return _context2.stop();
123
136
  }
124
- }, _callee2, this, [[6, 16, 19, 22]]);
137
+ }, _callee2, this, [[8, 18, 21, 24]]);
125
138
  }));
126
139
  function startLanguageClients() {
127
140
  return _startLanguageClients.apply(this, arguments);
128
141
  }
129
142
  return startLanguageClients;
130
143
  }()
144
+ }, {
145
+ key: "setupEditorOpener",
146
+ value: function setupEditorOpener() {
147
+ var _this2 = this;
148
+ monaco.editor.registerEditorOpener({
149
+ openCodeEditor: function openCodeEditor(source, resource, selectionOrPosition) {
150
+ var _source$getModel;
151
+ // simulate openening a new browser tab for our own type (open definition of alert)
152
+ var model = monaco.editor.getModel(resource);
153
+ if ((model === null || model === void 0 ? void 0 : model.id) === ((_source$getModel = source.getModel()) === null || _source$getModel === void 0 ? void 0 : _source$getModel.id)) {
154
+ return true;
155
+ }
156
+ var libroView = Array.from(_this2.libroService.getViewCache().values()).find(function (item) {
157
+ return ExecutableNotebookModel.is(item.model) && URI.parse(item.model.filePath).path === resource.path;
158
+ });
159
+ if (!libroView) {
160
+ return false;
161
+ }
162
+ var cell = libroView.model.cells.find(function (item) {
163
+ return ExecutableNotebookModel.is(libroView.model) && getCellURI(libroView.model, item.model).toString() === decodeURIComponent(resource.toString());
164
+ });
165
+ if (EditorCellView.is(cell)) {
166
+ var _cell$editor, _line;
167
+ libroView.selectCell(cell);
168
+ (_cell$editor = cell.editor) === null || _cell$editor === void 0 || _cell$editor.focus();
169
+ var line = 0;
170
+ if (monaco.Range.isIRange(selectionOrPosition)) {
171
+ var _cell$editor2, _cell$editor3;
172
+ (_cell$editor2 = cell.editor) === null || _cell$editor2 === void 0 || _cell$editor2.revealSelection(toEditorRange(selectionOrPosition));
173
+ (_cell$editor3 = cell.editor) === null || _cell$editor3 === void 0 || _cell$editor3.setCursorPosition(toEditorRange(selectionOrPosition).start);
174
+ line = toEditorRange(selectionOrPosition).start.line;
175
+ } else {
176
+ var _cell$editor4;
177
+ (_cell$editor4 = cell.editor) === null || _cell$editor4 === void 0 || _cell$editor4.setCursorPosition(toMonacoPosition(selectionOrPosition));
178
+ line = toMonacoPosition(selectionOrPosition).line;
179
+ }
180
+ libroView.model.scrollToView(cell, ((_line = line) !== null && _line !== void 0 ? _line : 0) * 20);
181
+ return false;
182
+ }
183
+
184
+ // alternatively set model directly in the editor if you have your own tab/navigation implementation
185
+ // const model = monaco.editor.getModel(resource);
186
+ // editor.setModel(model);
187
+ // if (monaco.Range.isIRange(selectionOrPosition)) {
188
+ // editor.revealRangeInCenterIfOutsideViewport(selectionOrPosition);
189
+ // editor.setSelection(selectionOrPosition);
190
+ // } else {
191
+ // editor.revealPositionInCenterIfOutsideViewport(selectionOrPosition);
192
+ // editor.setPosition(selectionOrPosition);
193
+ // }
194
+
195
+ return false;
196
+ }
197
+ });
198
+ }
131
199
  }]);
132
200
  return LibroLanguageClientContribution;
133
- }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroLanguageClientManager", [_dec2], {
201
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroWorkspaceService", [_dec2], {
202
+ configurable: true,
203
+ enumerable: true,
204
+ writable: true,
205
+ initializer: null
206
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "libroLanguageClientManager", [_dec3], {
207
+ configurable: true,
208
+ enumerable: true,
209
+ writable: true,
210
+ initializer: null
211
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "lspEnv", [_dec4], {
134
212
  configurable: true,
135
213
  enumerable: true,
136
214
  writable: true,
137
215
  initializer: null
138
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "lspEnv", [_dec3], {
216
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "libroService", [_dec5], {
139
217
  configurable: true,
140
218
  enumerable: true,
141
219
  writable: true,
@@ -11,6 +11,10 @@ export declare class LibroLanguageClientManager {
11
11
  protected readonly languageServerManagerFactory: ILanguageServerManagerFactory;
12
12
  protected languageServerManager: ILanguageServerManager;
13
13
  protected clientMap: Map<string, IConnectionData>;
14
+ /**
15
+ * lsp server that support notebook
16
+ */
17
+ protected supportedLSPServer: string[];
14
18
  init(): void;
15
19
  protected serverUri(languageServerId: string): string;
16
20
  getServers(language?: string): Promise<import("@difizen/libro-lsp").TLanguageServerId[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"libro-language-client-manager.d.ts","sourceRoot":"","sources":["../src/libro-language-client-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,UAAU,eAAe;IACvB,UAAU,EAAE,SAAS,CAAC;IACtB,cAAc,EAAE,mBAAmB,CAAC;CACrC;AAGD,MAAM,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEvD,qBACa,0BAA0B;IAErC,SAAS,CAAC,QAAQ,CAAC,4BAA4B,EAAE,6BAA6B,CAAC;IAE/E,SAAS,CAAC,qBAAqB,EAAE,sBAAsB,CAAC;IAExD,SAAS,CAAC,SAAS,+BAAsC;IAGzD,IAAI;IAIJ,SAAS,CAAC,SAAS,CAAC,gBAAgB,EAAE,MAAM;IAKtC,UAAU,CAAC,QAAQ,SAAW;IAQ9B,cAAc,CAAC,QAAQ,SAAW;IAQlC,cAAc;IAIpB,IAAI,eAAe,4CAElB;IAED,IAAI,QAAQ,gBAQX;IAEK,yBAAyB,CAC7B,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,0BAA0B;;;;IAYrC,SAAS,CAAC,oBAAoB,QACvB,MAAM,WACF,0BAA0B;;;OAGnC;IAEI,mBAAmB,CAAC,gBAAgB,EAAE,MAAM;IAO5C,sBAAsB;IAMtB,gBAAgB,CACpB,OAAO,EAAE,cAAc,EACvB,QAAQ,SAAW,GAClB,OAAO,CAAC,OAAO,CAAC;CAuBpB"}
1
+ {"version":3,"file":"libro-language-client-manager.d.ts","sourceRoot":"","sources":["../src/libro-language-client-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,UAAU,eAAe;IACvB,UAAU,EAAE,SAAS,CAAC;IACtB,cAAc,EAAE,mBAAmB,CAAC;CACrC;AAGD,MAAM,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEvD,qBACa,0BAA0B;IAErC,SAAS,CAAC,QAAQ,CAAC,4BAA4B,EAAE,6BAA6B,CAAC;IAE/E,SAAS,CAAC,qBAAqB,EAAE,sBAAsB,CAAC;IAExD,SAAS,CAAC,SAAS,+BAAsC;IAEzD;;OAEG;IACH,SAAS,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAA6C;IAGnF,IAAI;IAIJ,SAAS,CAAC,SAAS,CAAC,gBAAgB,EAAE,MAAM;IAKtC,UAAU,CAAC,QAAQ,SAAW;IAQ9B,cAAc,CAAC,QAAQ,SAAW;IAQlC,cAAc;IAIpB,IAAI,eAAe,4CAElB;IAED,IAAI,QAAQ,gBAQX;IAEK,yBAAyB,CAC7B,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,0BAA0B;;;;IAerC,SAAS,CAAC,oBAAoB,QACvB,MAAM,WACF,0BAA0B;;;OAGnC;IAEI,mBAAmB,CAAC,gBAAgB,EAAE,MAAM;IAO5C,sBAAsB;IAMtB,gBAAgB,CACpB,OAAO,EAAE,cAAc,EACvB,QAAQ,SAAW,GAClB,OAAO,CAAC,OAAO,CAAC;CAuBpB"}
@@ -24,6 +24,10 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
24
24
  _classCallCheck(this, LibroLanguageClientManager);
25
25
  _initializerDefineProperty(this, "languageServerManagerFactory", _descriptor, this);
26
26
  this.clientMap = new Map();
27
+ /**
28
+ * lsp server that support notebook
29
+ */
30
+ this.supportedLSPServer = ['libro-analyzer', 'ruff-lsp', 'pylance'];
27
31
  this.createLanguageClient = function (url, options) {
28
32
  return LibroLanguageClient.createWebSocketLanguageClient(url, options);
29
33
  };
@@ -43,6 +47,7 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
43
47
  key: "getServers",
44
48
  value: function () {
45
49
  var _getServers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
50
+ var _this = this;
46
51
  var language,
47
52
  serverIds,
48
53
  _args = arguments;
@@ -56,7 +61,9 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
56
61
  serverIds = this.languageServerManager.getMatchingServers({
57
62
  language: language
58
63
  });
59
- return _context.abrupt("return", serverIds);
64
+ return _context.abrupt("return", serverIds.filter(function (item) {
65
+ return _this.supportedLSPServer.includes(item);
66
+ }));
60
67
  case 5:
61
68
  case "end":
62
69
  return _context.stop();
@@ -141,21 +148,27 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
141
148
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
142
149
  while (1) switch (_context4.prev = _context4.next) {
143
150
  case 0:
144
- if (!this.clientMap.has(languageServerId)) {
151
+ if (this.supportedLSPServer.includes(languageServerId)) {
145
152
  _context4.next = 2;
146
153
  break;
147
154
  }
148
- return _context4.abrupt("return", this.clientMap.get(languageServerId));
155
+ return _context4.abrupt("return");
149
156
  case 2:
157
+ if (!this.clientMap.has(languageServerId)) {
158
+ _context4.next = 4;
159
+ break;
160
+ }
161
+ return _context4.abrupt("return", this.clientMap.get(languageServerId));
162
+ case 4:
150
163
  url = this.serverUri(languageServerId);
151
- _context4.next = 5;
164
+ _context4.next = 7;
152
165
  return this.createLanguageClient(url, options);
153
- case 5:
166
+ case 7:
154
167
  client = _context4.sent;
155
168
  this.clientMap.set(languageServerId, client);
156
169
  this.refreshRunning();
157
170
  return _context4.abrupt("return", client);
158
- case 9:
171
+ case 11:
159
172
  case "end":
160
173
  return _context4.stop();
161
174
  }
@@ -195,7 +208,7 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
195
208
  key: "closeAllLanguageClient",
196
209
  value: function () {
197
210
  var _closeAllLanguageClient = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
198
- var _this = this;
211
+ var _this2 = this;
199
212
  var servers;
200
213
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
201
214
  while (1) switch (_context6.prev = _context6.next) {
@@ -206,7 +219,7 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
206
219
  servers = _context6.sent;
207
220
  _context6.next = 5;
208
221
  return Promise.all(servers.map(function (server) {
209
- return _this.closeLanguageClient(server);
222
+ return _this2.closeLanguageClient(server);
210
223
  }));
211
224
  case 5:
212
225
  this.refreshRunning();
@@ -225,7 +238,7 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
225
238
  key: "getFeatureStatus",
226
239
  value: function () {
227
240
  var _getFeatureStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(feature) {
228
- var _this2 = this;
241
+ var _this3 = this;
229
242
  var language,
230
243
  featureEnabled,
231
244
  serverids,
@@ -240,8 +253,8 @@ export var LibroLanguageClientManager = (_dec = singleton(), _dec2 = inject(ILan
240
253
  case 4:
241
254
  serverids = _context7.sent;
242
255
  serverids.forEach(function (id) {
243
- var _this2$clientMap$get;
244
- var featureState = (_this2$clientMap$get = _this2.clientMap.get(id)) === null || _this2$clientMap$get === void 0 ? void 0 : _this2$clientMap$get.languageClient.getFeature(feature).getState();
256
+ var _this3$clientMap$get;
257
+ var featureState = (_this3$clientMap$get = _this3.clientMap.get(id)) === null || _this3$clientMap$get === void 0 ? void 0 : _this3$clientMap$get.languageClient.getFeature(feature).getState();
245
258
  if ((featureState === null || featureState === void 0 ? void 0 : featureState.kind) === 'document' && featureState.registrations === true) {
246
259
  featureEnabled = true;
247
260
  }
package/es/util.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { IPosition, IRange } from '@difizen/libro-code-editor';
2
+ import type { CellModel } from '@difizen/libro-core';
3
+ import type { ExecutableNotebookModel } from '@difizen/libro-kernel';
4
+ import { URI } from '@difizen/mana-app';
5
+ import type * as monaco from '@difizen/monaco-editor-core';
6
+ export declare const getCellURI: (libroModel: ExecutableNotebookModel, cellModel: CellModel) => URI;
7
+ export declare const toEditorRange: (range: monaco.IRange) => IRange;
8
+ export declare const toMonacoPosition: (position: monaco.IPosition | undefined) => IPosition;
9
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAI3D,eAAO,MAAM,UAAU,eACT,uBAAuB,aACxB,SAAS,KACnB,GAKF,CAAC;AAEF,eAAO,MAAM,aAAa,UAAW,aAAa,KAAG,MAWpD,CAAC;AAEF,eAAO,MAAM,gBAAgB,aAAc,gBAAgB,GAAG,SAAS,KAAG,SAWzE,CAAC"}
package/es/util.js ADDED
@@ -0,0 +1,32 @@
1
+ import { URI } from '@difizen/mana-app';
2
+ import { LibroCellURIScheme } from "./constants.js";
3
+ export var getCellURI = function getCellURI(libroModel, cellModel) {
4
+ var uri = new URI(libroModel.filePath);
5
+ uri = URI.withScheme(uri, LibroCellURIScheme);
6
+ uri = URI.withQuery(uri, "cellid=".concat(cellModel.id));
7
+ return uri;
8
+ };
9
+ export var toEditorRange = function toEditorRange(range) {
10
+ return {
11
+ start: {
12
+ line: range.startLineNumber - 1,
13
+ column: range.startColumn - 1
14
+ },
15
+ end: {
16
+ line: range.endLineNumber - 1,
17
+ column: range.endColumn - 1
18
+ }
19
+ };
20
+ };
21
+ export var toMonacoPosition = function toMonacoPosition(position) {
22
+ if (!position) {
23
+ return {
24
+ column: 0,
25
+ line: 0
26
+ };
27
+ }
28
+ return {
29
+ column: (position === null || position === void 0 ? void 0 : position.column) - 1,
30
+ line: (position === null || position === void 0 ? void 0 : position.lineNumber) - 1
31
+ };
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-language-client",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,10 +32,11 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@difizen/libro-core": "^0.1.26",
36
- "@difizen/libro-kernel": "^0.1.26",
37
- "@difizen/libro-common": "^0.1.26",
38
- "@difizen/libro-lsp": "^0.1.26",
35
+ "@difizen/libro-core": "^0.1.27",
36
+ "@difizen/libro-code-editor": "^0.1.27",
37
+ "@difizen/libro-kernel": "^0.1.27",
38
+ "@difizen/libro-common": "^0.1.27",
39
+ "@difizen/libro-lsp": "^0.1.27",
39
40
  "@difizen/mana-app": "latest",
40
41
  "@difizen/mana-common": "latest",
41
42
  "uuid": "^9.0.0",
@@ -4,6 +4,7 @@
4
4
  * ------------------------------------------------------------------------------------------ */
5
5
 
6
6
  import * as proto from '@difizen/vscode-languageserver-protocol';
7
+ import type { LocationLink } from 'vscode';
7
8
  import type {
8
9
  InlineCompletionContext,
9
10
  InlayHint,
@@ -46,6 +47,8 @@ import type {
46
47
  TextEdit,
47
48
  Uri,
48
49
  SymbolInformation as VSymbolInformation,
50
+ Definition,
51
+ DefinitionLink,
49
52
  } from 'vscode';
50
53
 
51
54
  import ProtocolCallHierarchyItem from './protocolCallHierarchyItem.js';
@@ -60,6 +63,7 @@ import ProtocolTypeHierarchyItem from './protocolTypeHierarchyItem.js';
60
63
  import WorkspaceSymbol from './protocolWorkspaceSymbol.js';
61
64
  import * as async from './utils/async.js';
62
65
  import * as Is from './utils/is.js';
66
+ import { isNumber } from './vscodeAdaptor/hostTypeUtil.js';
63
67
  import type { SymbolInformation } from './vscodeAdaptor/vscodeAdaptor.js';
64
68
  import {
65
69
  SymbolKind,
@@ -172,11 +176,25 @@ export interface Converter {
172
176
 
173
177
  asRanges(values: readonly Range[]): proto.Range[];
174
178
 
179
+ asDefinitionResult(item: Definition): proto.Definition;
180
+ asDefinitionResult(item: DefinitionLink[]): proto.Definition;
181
+ asDefinitionResult(item: undefined | null): undefined;
182
+ asDefinitionResult(
183
+ item: Definition | DefinitionLink[] | undefined | null,
184
+ ): proto.Definition | undefined;
185
+ asDefinitionResult(
186
+ item: Definition | DefinitionLink[] | undefined | null,
187
+ ): proto.Definition | undefined;
188
+
175
189
  asLocation(value: null): null;
176
190
  asLocation(value: undefined): undefined;
177
191
  asLocation(value: Location): proto.Location;
178
192
  asLocation(value: Location | undefined | null): proto.Location | undefined | null;
179
193
 
194
+ asLocationLink(item: undefined | null): undefined;
195
+ asLocationLink(item: LocationLink): proto.LocationLink;
196
+ asLocationLink(item: LocationLink | undefined | null): proto.LocationLink | undefined;
197
+
180
198
  asDiagnosticSeverity(value: DiagnosticSeverity): number;
181
199
  asDiagnosticTag(value: DiagnosticTag): number | undefined;
182
200
 
@@ -215,6 +233,8 @@ export interface Converter {
215
233
  ): Promise<proto.CodeActionContext>;
216
234
  asCodeActionContextSync(context: CodeActionContext): proto.CodeActionContext;
217
235
 
236
+ asCodeActionList(actions: (Command | CodeAction)[]): Promise<proto.CodeAction[]>;
237
+
218
238
  asInlineValueContext(context: InlineValueContext): proto.InlineValueContext;
219
239
 
220
240
  asCommand(item: Command): proto.Command;
@@ -250,6 +270,15 @@ export interface Converter {
250
270
  asInlineCompletionContext(
251
271
  context: InlineCompletionContext,
252
272
  ): proto.InlineCompletionContext;
273
+
274
+ asSignatureHelpResult(item: undefined | null): undefined;
275
+ asSignatureHelpResult(item: SignatureHelp): proto.SignatureHelp;
276
+ asSignatureHelpResult(
277
+ item: SignatureHelp | undefined | null,
278
+ ): proto.SignatureHelp | undefined;
279
+ asSignatureHelpResult(
280
+ item: SignatureHelp | undefined | null,
281
+ ): proto.SignatureHelp | undefined;
253
282
  }
254
283
 
255
284
  export interface URIConverter {
@@ -623,6 +652,63 @@ export function createConverter(uriConverter?: URIConverter): Converter {
623
652
  return values.map(asRange as (item: Range) => proto.Range);
624
653
  }
625
654
 
655
+ function asLocationLink(item: undefined | null): undefined;
656
+ function asLocationLink(item: LocationLink): proto.LocationLink;
657
+ function asLocationLink(
658
+ item: LocationLink | undefined | null,
659
+ ): proto.LocationLink | undefined {
660
+ if (!item) {
661
+ return undefined;
662
+ }
663
+ const result: proto.LocationLink = {
664
+ targetUri: item.targetUri.toString(),
665
+ targetRange: asRange(item.targetSelectionRange)!, // See issue: https://github.com/Microsoft/vscode/issues/58649
666
+ originSelectionRange: asRange(item.originSelectionRange)!,
667
+ targetSelectionRange: asRange(item.targetSelectionRange)!,
668
+ };
669
+ if (!result.targetSelectionRange) {
670
+ throw new Error(`targetSelectionRange must not be undefined or null`);
671
+ }
672
+ return result;
673
+ }
674
+
675
+ // Function to check if an object is a LocationLink
676
+ function isLocationLink(object: any): object is LocationLink {
677
+ return (
678
+ object !== undefined &&
679
+ 'targetUri' in object &&
680
+ 'targetRange' in object &&
681
+ 'targetSelectionRange' in object
682
+ );
683
+ }
684
+
685
+ function asDefinitionResult(item: Definition): proto.Definition;
686
+ function asDefinitionResult(item: DefinitionLink[]): proto.Definition;
687
+ function asDefinitionResult(item: undefined | null): undefined;
688
+ function asDefinitionResult(
689
+ item: Definition | DefinitionLink[] | undefined | null,
690
+ ): proto.Definition | proto.DefinitionLink[] | undefined;
691
+ function asDefinitionResult(
692
+ item: Definition | DefinitionLink[] | undefined | null,
693
+ ): proto.Definition | proto.DefinitionLink[] | undefined {
694
+ if (!item) {
695
+ return undefined;
696
+ }
697
+ if (Array.isArray(item)) {
698
+ if (item.length === 0) {
699
+ return undefined;
700
+ } else if (isLocationLink(item[0])) {
701
+ const links: LocationLink[] = item as unknown as LocationLink[];
702
+ return links.map((location) => asLocationLink(location));
703
+ } else {
704
+ const locations: Location[] = item as Location[];
705
+ return locations.map((location) => asLocation(location));
706
+ }
707
+ } else {
708
+ return asLocation(item);
709
+ }
710
+ }
711
+
626
712
  function asLocation(value: Location): proto.Location;
627
713
  function asLocation(value: undefined): undefined;
628
714
  function asLocation(value: null): null;
@@ -990,10 +1076,14 @@ export function createConverter(uriConverter?: URIConverter): Converter {
990
1076
  }
991
1077
 
992
1078
  async function asCodeAction(
993
- item: CodeAction,
1079
+ item: Command | CodeAction,
994
1080
  token?: CancellationToken,
995
1081
  ): Promise<proto.CodeAction> {
996
1082
  const result = proto.CodeAction.create(item.title);
1083
+ if (proto.Command.is(item)) {
1084
+ result.command = asCommand(item);
1085
+ return result;
1086
+ }
997
1087
  if (item instanceof ProtocolCodeAction && item.data !== undefined) {
998
1088
  result.data = item.data;
999
1089
  }
@@ -1105,6 +1195,12 @@ export function createConverter(uriConverter?: URIConverter): Converter {
1105
1195
  return item.value;
1106
1196
  }
1107
1197
 
1198
+ async function asCodeActionList(
1199
+ actions: (Command | CodeAction)[],
1200
+ ): Promise<proto.CodeAction[]> {
1201
+ return Promise.all(actions.map(async (action) => await asCodeAction(action)));
1202
+ }
1203
+
1108
1204
  function asInlineValueContext(context: InlineValueContext): proto.InlineValueContext {
1109
1205
  return proto.InlineValueContext.create(
1110
1206
  context.frameId,
@@ -1350,6 +1446,38 @@ export function createConverter(uriConverter?: URIConverter): Converter {
1350
1446
  return result;
1351
1447
  }
1352
1448
 
1449
+ function asSignatureHelpResult(item: undefined | null): undefined;
1450
+ function asSignatureHelpResult(item: SignatureHelp): proto.SignatureHelp;
1451
+ function asSignatureHelpResult(
1452
+ item: SignatureHelp | undefined | null,
1453
+ ): proto.SignatureHelp | undefined;
1454
+ function asSignatureHelpResult(
1455
+ item: SignatureHelp | undefined | null,
1456
+ ): proto.SignatureHelp | undefined {
1457
+ if (!item) {
1458
+ return undefined;
1459
+ }
1460
+ const result = <proto.SignatureHelp>{};
1461
+ if (isNumber(item.activeSignature)) {
1462
+ result.activeSignature = item.activeSignature;
1463
+ } else {
1464
+ // activeSignature was optional in the past
1465
+ result.activeSignature = 0;
1466
+ }
1467
+ if (isNumber(item.activeParameter)) {
1468
+ result.activeParameter = item.activeParameter;
1469
+ } else {
1470
+ // activeParameter was optional in the past
1471
+ result.activeParameter = 0;
1472
+ }
1473
+ if (item.signatures) {
1474
+ result.signatures = asSignatureInformations(item.signatures);
1475
+ } else {
1476
+ result.signatures = [];
1477
+ }
1478
+ return result;
1479
+ }
1480
+
1353
1481
  return {
1354
1482
  asUri,
1355
1483
  asTextDocumentIdentifier,
@@ -1405,5 +1533,9 @@ export function createConverter(uriConverter?: URIConverter): Converter {
1405
1533
  asWorkspaceSymbol,
1406
1534
  asInlineCompletionParams,
1407
1535
  asInlineCompletionContext,
1536
+ asDefinitionResult,
1537
+ asLocationLink,
1538
+ asSignatureHelpResult,
1539
+ asCodeActionList,
1408
1540
  };
1409
1541
  }