Skip to content

Commit

Permalink
Rework LSP connection interface, cherry picking #278
Browse files Browse the repository at this point in the history
Co-authored-by: bollwyvl
Co-authored-by: krassowski
  • Loading branch information
krassowski committed May 29, 2021
1 parent d7d007f commit 17a48e4
Show file tree
Hide file tree
Showing 3 changed files with 356 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
- add ability to deactivate Kernel completions or LSP completion through the settings ([#586], thanks @Carreau)
- allow to set a priority for LSP server, allowing to choose which server to use when multiple servers are installed ([#588])
- add auto-detection of pyright server ([#587], thanks @yuntan)
- log server messages in user-accessible console ([#606])
- 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])

- bug fixes:

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

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

[#586]: https://github.com/krassowski/jupyterlab-lsp/pull/586
[#587]: https://github.com/krassowski/jupyterlab-lsp/pull/587
[#588]: https://github.com/krassowski/jupyterlab-lsp/pull/588
[#599]: https://github.com/krassowski/jupyterlab-lsp/pull/599
[#606]: https://github.com/krassowski/jupyterlab-lsp/pull/606

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

Expand Down
51 changes: 39 additions & 12 deletions packages/jupyterlab-lsp/src/adapters/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import { IVirtualEditor } from '../virtual/editor';

import IEditor = CodeEditor.IEditor;

import { Dialog, showDialog } from '@jupyterlab/apputils';

import IButton = Dialog.IButton;
import createButton = Dialog.createButton;

export class StatusMessage {
/**
* The text message to be shown on the statusbar
Expand Down Expand Up @@ -348,7 +353,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
const loggerSourceName = virtual_document.uri;
const logger = this.extension.user_console.getLogger(loggerSourceName);

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

data.connection.notifications.window.showMessage.connect(
data.connection.serverNotifications['window/showMessage'].connect(
(connection, message) => {
this.console.log(
data.connection.serverIdentifier,
virtual_document.uri,
message
message.message
);
logger.log({
type: 'text',
data: connection.serverIdentifier + ': ' + message.message
} as ILogPayload);
this.extension.app.commands
.execute('logconsole:open', {
source: loggerSourceName
})
.catch(console.log);
void showDialog({
title: this.trans.__('Message from ') + connection.serverIdentifier,
body: message.message
});
}
);

data.connection.serverRequests['window/showMessageRequest'].setHandler(
async params => {
this.console.log(
data.connection.serverIdentifier,
virtual_document.uri,
params
);
const actionItems = params.actions;
const buttons = actionItems.map(action => {
return createButton({
label: action.title
});
});
const result = await showDialog<IButton>({
title:
this.trans.__('Message from ') + data.connection.serverIdentifier,
body: params.message,
buttons: buttons
});
const choice = buttons.indexOf(result.button);
if (choice === -1) {
return;
}
return actionItems[choice];
}
);
}
Expand Down
Loading

0 comments on commit 17a48e4

Please sign in to comment.