Skip to content

Commit 22bf7b3

Browse files
authored
Merge pull request #606 from krassowski/add-log-window
Implement console log window messages, update lsp-ws-connection
2 parents 739f3dd + 9b5c35f commit 22bf7b3

File tree

15 files changed

+1014
-237
lines changed

15 files changed

+1014
-237
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
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)
1010
- update from JupyterLab Classic to RetroLab ([#603])
11+
- log server messages in user-accessible console ([#606])
12+
- 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])
1113

1214
- bug fixes:
1315

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

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

1922
[#586]: https://github.com/krassowski/jupyterlab-lsp/pull/586
2023
[#587]: https://github.com/krassowski/jupyterlab-lsp/pull/587
2124
[#588]: https://github.com/krassowski/jupyterlab-lsp/pull/588
2225
[#599]: https://github.com/krassowski/jupyterlab-lsp/pull/599
2326
[#602]: https://github.com/krassowski/jupyterlab-lsp/pull/602
27+
[#606]: https://github.com/krassowski/jupyterlab-lsp/pull/606
2428

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

packages/jupyterlab-lsp/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@krassowski/theme-material": "~2.1.0",
6363
"@krassowski/theme-vscode": "~2.1.0",
6464
"lodash.mergewith": "^4.6.1",
65-
"lsp-ws-connection": "~0.5.1"
65+
"lsp-ws-connection": "~0.6.0"
6666
},
6767
"devDependencies": {
6868
"@babel/preset-env": "^7.4.3",
@@ -77,6 +77,7 @@
7777
"@jupyterlab/docmanager": "^3.0.0",
7878
"@jupyterlab/docregistry": "^3.0.0",
7979
"@jupyterlab/fileeditor": "^3.0.0",
80+
"@jupyterlab/logconsole": "^3.0.0",
8081
"@jupyterlab/notebook": "^3.0.0",
8182
"@jupyterlab/rendermime": "^3.0.0",
8283
"@jupyterlab/services": "^6.0.0",
@@ -102,7 +103,8 @@
102103
"react": "^17.0.1",
103104
"rimraf": "^3.0.2",
104105
"ts-jest": "^26.4.3",
105-
"typescript": "~4.1.3"
106+
"typescript": "~4.1.3",
107+
"vscode-languageserver-protocol": "^3.16.0"
106108
},
107109
"peerDependencies": {
108110
"@jupyterlab/application": "^3.0.0",

packages/jupyterlab-lsp/schema/plugin.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@
6060
"enum": ["debug", "log", "warn", "error"],
6161
"default": "warn",
6262
"description": "The verbosity of the console for debugging problems with this extension. Allowed values are: debug, log, warn, error."
63+
},
64+
"logAllCommunication": {
65+
"title": "Log all LSP communication with the LSP servers",
66+
"type": "boolean",
67+
"default": false,
68+
"description": "Whether all messages sent to and received from LSP servers should be logged into the console. To see these messages, set loggingLevel to debug or log. Note: Only messages handled by the new API will be shown."
69+
},
70+
"setTrace": {
71+
"title": "Ask servers to send trace notifications",
72+
"type": ["string", "null"],
73+
"enum": ["off", "messages", "verbose", null],
74+
"default": null,
75+
"description": "Whether to ask server to send logs with execution trace (for debugging). To see these messages, set loggingLevel to debug or log. Accepted values are: \"off\", \"messages\", \"verbose\". Servers are allowed to ignore this request."
6376
}
6477
},
6578
"jupyter.lab.shortcuts": []

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { JupyterFrontEnd } from '@jupyterlab/application';
2+
import { Dialog, showDialog } from '@jupyterlab/apputils';
23
import { CodeEditor } from '@jupyterlab/codeeditor';
34
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
5+
import { ILogPayload } from '@jupyterlab/logconsole';
46
import { nullTranslator, TranslationBundle } from '@jupyterlab/translation';
57
import { JSONObject } from '@lumino/coreutils';
68
import { Signal } from '@lumino/signaling';
@@ -21,6 +23,8 @@ import { IForeignContext, VirtualDocument } from '../virtual/document';
2123
import { IVirtualEditor } from '../virtual/editor';
2224

2325
import IEditor = CodeEditor.IEditor;
26+
import IButton = Dialog.IButton;
27+
import createButton = Dialog.createButton;
2428

2529
export class StatusMessage {
2630
/**
@@ -341,6 +345,77 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
341345
'have been initialized'
342346
);
343347
});
348+
349+
// Note: the logger extension behaves badly with non-default names
350+
// as it changes the source to the active file afterwards anyways
351+
const loggerSourceName = virtual_document.uri;
352+
const logger = this.extension.user_console.getLogger(loggerSourceName);
353+
354+
data.connection.serverNotifications['$/logTrace'].connect(
355+
(connection, message) => {
356+
this.console.log(
357+
data.connection.serverIdentifier,
358+
'trace',
359+
virtual_document.uri,
360+
message
361+
);
362+
}
363+
);
364+
365+
data.connection.serverNotifications['window/logMessage'].connect(
366+
(connection, message) => {
367+
this.console.log(
368+
data.connection.serverIdentifier,
369+
virtual_document.uri,
370+
message
371+
);
372+
logger.log({
373+
type: 'text',
374+
data: connection.serverIdentifier + ': ' + message.message
375+
} as ILogPayload);
376+
}
377+
);
378+
379+
data.connection.serverNotifications['window/showMessage'].connect(
380+
(connection, message) => {
381+
this.console.log(
382+
data.connection.serverIdentifier,
383+
virtual_document.uri,
384+
message.message
385+
);
386+
void showDialog({
387+
title: this.trans.__('Message from ') + connection.serverIdentifier,
388+
body: message.message
389+
});
390+
}
391+
);
392+
393+
data.connection.serverRequests['window/showMessageRequest'].setHandler(
394+
async params => {
395+
this.console.log(
396+
data.connection.serverIdentifier,
397+
virtual_document.uri,
398+
params
399+
);
400+
const actionItems = params.actions;
401+
const buttons = actionItems.map(action => {
402+
return createButton({
403+
label: action.title
404+
});
405+
});
406+
const result = await showDialog<IButton>({
407+
title:
408+
this.trans.__('Message from ') + data.connection.serverIdentifier,
409+
body: params.message,
410+
buttons: buttons
411+
});
412+
const choice = buttons.indexOf(result.button);
413+
if (choice === -1) {
414+
return;
415+
}
416+
return actionItems[choice];
417+
}
418+
);
344419
}
345420

346421
/**

0 commit comments

Comments
 (0)