Skip to content

Commit 17a48e4

Browse files
committed
Rework LSP connection interface, cherry picking #278
Co-authored-by: bollwyvl Co-authored-by: krassowski
1 parent d7d007f commit 17a48e4

File tree

3 files changed

+356
-65
lines changed

3 files changed

+356
-65
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
- add ability to deactivate Kernel completions or LSP completion through the settings ([#586], thanks @Carreau)
88
- allow to set a priority for LSP server, allowing to choose which server to use when multiple servers are installed ([#588])
99
- add auto-detection of pyright server ([#587], thanks @yuntan)
10+
- log server messages in user-accessible console ([#606])
11+
- old emit-based API of lsp-ws-connection is new deprecated and will be removed in the next major version; please use `serverNotifications`, `clientNotifications`, `clientRequests` and `serverRequests` instead ([#606])
1012

1113
- bug fixes:
1214

1315
- workaround url-parse issue causing problems when using JupyterLab 3.0.15 ([#599])
1416

1517
- other changes:
1618
- drop Node 10 (EOL 2 weeks ago) testing on CI, add Node 15 ([#587])
19+
- update lsp-ws-connection dependencies ([#606])
1720

1821
[#586]: https://github.com/krassowski/jupyterlab-lsp/pull/586
1922
[#587]: https://github.com/krassowski/jupyterlab-lsp/pull/587
2023
[#588]: https://github.com/krassowski/jupyterlab-lsp/pull/588
2124
[#599]: https://github.com/krassowski/jupyterlab-lsp/pull/599
25+
[#606]: https://github.com/krassowski/jupyterlab-lsp/pull/606
2226

2327
### `jupyter-lsp 1.2.0` (2021-04-26)
2428

packages/jupyterlab-lsp/src/adapters/adapter.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import { IVirtualEditor } from '../virtual/editor';
2323

2424
import IEditor = CodeEditor.IEditor;
2525

26+
import { Dialog, showDialog } from '@jupyterlab/apputils';
27+
28+
import IButton = Dialog.IButton;
29+
import createButton = Dialog.createButton;
30+
2631
export class StatusMessage {
2732
/**
2833
* The text message to be shown on the statusbar
@@ -348,7 +353,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
348353
const loggerSourceName = virtual_document.uri;
349354
const logger = this.extension.user_console.getLogger(loggerSourceName);
350355

351-
data.connection.notifications.window.logMessage.connect(
356+
data.connection.serverNotifications['window/logMessage'].connect(
352357
(connection, message) => {
353358
this.console.log(
354359
data.connection.serverIdentifier,
@@ -362,22 +367,44 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
362367
}
363368
);
364369

365-
data.connection.notifications.window.showMessage.connect(
370+
data.connection.serverNotifications['window/showMessage'].connect(
366371
(connection, message) => {
367372
this.console.log(
368373
data.connection.serverIdentifier,
369374
virtual_document.uri,
370-
message
375+
message.message
371376
);
372-
logger.log({
373-
type: 'text',
374-
data: connection.serverIdentifier + ': ' + message.message
375-
} as ILogPayload);
376-
this.extension.app.commands
377-
.execute('logconsole:open', {
378-
source: loggerSourceName
379-
})
380-
.catch(console.log);
377+
void showDialog({
378+
title: this.trans.__('Message from ') + connection.serverIdentifier,
379+
body: message.message
380+
});
381+
}
382+
);
383+
384+
data.connection.serverRequests['window/showMessageRequest'].setHandler(
385+
async params => {
386+
this.console.log(
387+
data.connection.serverIdentifier,
388+
virtual_document.uri,
389+
params
390+
);
391+
const actionItems = params.actions;
392+
const buttons = actionItems.map(action => {
393+
return createButton({
394+
label: action.title
395+
});
396+
});
397+
const result = await showDialog<IButton>({
398+
title:
399+
this.trans.__('Message from ') + data.connection.serverIdentifier,
400+
body: params.message,
401+
buttons: buttons
402+
});
403+
const choice = buttons.indexOf(result.button);
404+
if (choice === -1) {
405+
return;
406+
}
407+
return actionItems[choice];
381408
}
382409
);
383410
}

0 commit comments

Comments
 (0)