Skip to content

Commit 7420ac1

Browse files
authored
Merge pull request #166 from krassowski/diagnostics/dock_at_bottom
Start the diagnostics panel docked at the bottom
2 parents 377f209 + bc4107c commit 7420ac1

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
return MarkupContent (
1919
[#164](https://github.com/krassowski/jupyterlab-lsp/pull/164)
2020
)
21+
- Start the diagnostics panel docked at the bottom and improve
22+
the re-spawning of the (closed) diagnostics panel (
23+
[#166](https://github.com/krassowski/jupyterlab-lsp/pull/166)
24+
)
2125

2226
## `lsp-ws-connection 0.3.1`
2327

packages/jupyterlab-lsp/src/adapters/codemirror/features/diagnostics.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,29 @@ import { VirtualEditor } from '../../../virtual/editor';
2121
const default_severity = 2;
2222

2323
class DiagnosticsPanel {
24-
content: DiagnosticsListing;
25-
widget: MainAreaWidget<DiagnosticsListing>;
24+
private _content: DiagnosticsListing = null;
25+
private _widget: MainAreaWidget<DiagnosticsListing> = null;
2626
is_registered = false;
2727

28-
constructor() {
29-
this.widget = this.init_widget();
30-
this.widget.content.disposed.connect(() => {
31-
// immortal widget (or mild memory leak) TODO: rewrite this
32-
this.widget.dispose();
33-
this.widget = this.init_widget();
34-
});
28+
get widget() {
29+
if (this._widget == null || this._widget.content.model === null) {
30+
if (this._widget && !this._widget.isDisposed) {
31+
this._widget.dispose();
32+
}
33+
this._widget = this.init_widget();
34+
}
35+
return this._widget;
3536
}
3637

37-
init_widget() {
38-
this.content = new DiagnosticsListing(new DiagnosticsListing.Model());
39-
this.content.model.diagnostics = new DiagnosticsDatabase();
40-
this.content.addClass('lsp-diagnostics-panel-content');
41-
const widget = new MainAreaWidget({ content: this.content });
38+
get content() {
39+
return this.widget.content;
40+
}
41+
42+
protected init_widget() {
43+
this._content = new DiagnosticsListing(new DiagnosticsListing.Model());
44+
this._content.model.diagnostics = new DiagnosticsDatabase();
45+
this._content.addClass('lsp-diagnostics-panel-content');
46+
const widget = new MainAreaWidget({ content: this._content });
4247
widget.id = 'lsp-diagnostics-panel';
4348
widget.title.label = 'Diagnostics Panel';
4449
widget.title.closable = true;
@@ -68,7 +73,7 @@ export class Diagnostics extends CodeMirrorLSPFeature {
6873
static commands: Array<IFeatureCommand> = [
6974
{
7075
id: 'show-diagnostics-panel',
71-
execute: ({ app, features }) => {
76+
execute: ({ app, features, adapter }) => {
7277
let diagnostics_feature = features.get('Diagnostics') as Diagnostics;
7378
diagnostics_feature.switchDiagnosticsPanelSource();
7479

@@ -113,7 +118,11 @@ export class Diagnostics extends CodeMirrorLSPFeature {
113118
}
114119

115120
if (!panel_widget.isAttached) {
116-
app.shell.add(panel_widget, 'main');
121+
console.warn(adapter.widget_id);
122+
app.shell.add(panel_widget, 'main', {
123+
ref: adapter.widget_id,
124+
mode: 'split-bottom'
125+
});
117126
}
118127
app.shell.activateById(panel_widget.id);
119128
},

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ export abstract class JupyterLabWidgetAdapter
150150
abstract get mime_type(): string;
151151
protected abstract connect_completion(): void;
152152

153+
get widget_id(): string {
154+
return this.widget.id;
155+
}
156+
153157
get language(): string {
154158
// the values should follow https://microsoft.github.io/language-server-protocol/specification guidelines
155159
if (mime_type_language_map.hasOwnProperty(this.mime_type)) {
@@ -425,7 +429,8 @@ export abstract class JupyterLabWidgetAdapter
425429
root_position,
426430
features: this.get_features(document),
427431
editor: this.virtual_editor,
428-
app: this.app
432+
app: this.app,
433+
adapter: this
429434
};
430435
}
431436

packages/jupyterlab-lsp/src/command_manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,5 @@ export interface ICommandContext {
257257
root_position: IRootPosition;
258258
features: Map<string, ILSPFeature>;
259259
editor: VirtualEditor;
260+
adapter: JupyterLabWidgetAdapter;
260261
}

0 commit comments

Comments
 (0)