Skip to content

Commit

Permalink
Ensure trans always available, camelCase some protected members
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Sep 5, 2021
1 parent 59f1a84 commit 9bd55aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/jupyterlab-lsp/src/features/diagnostics/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JupyterFrontEnd } from '@jupyterlab/application';
import { MainAreaWidget } from '@jupyterlab/apputils';
import { TranslationBundle } from '@jupyterlab/translation';
import { nullTranslator, TranslationBundle } from '@jupyterlab/translation';
import { LabIcon, copyIcon } from '@jupyterlab/ui-components';
import { Menu } from '@lumino/widgets';
import type * as CodeMirror from 'codemirror';
Expand Down Expand Up @@ -56,12 +56,16 @@ class DiagnosticsPanel {
is_registered = false;
trans: TranslationBundle;

constructor(trans: TranslationBundle) {
this.trans = trans;
}

get widget() {
if (this._widget == null || this._widget.content.model == null) {
if (this._widget && !this._widget.isDisposed) {
this._widget.dispose();
}
this._widget = this.init_widget();
this._widget = this.initWidget();
}
return this._widget;
}
Expand All @@ -70,7 +74,7 @@ class DiagnosticsPanel {
return this.widget.content;
}

protected init_widget() {
protected initWidget() {
this._content = new DiagnosticsListing(
new DiagnosticsListing.Model(this.trans)
);
Expand Down Expand Up @@ -275,7 +279,9 @@ class DiagnosticsPanel {
}
}

export const diagnostics_panel = new DiagnosticsPanel();
export const diagnostics_panel = new DiagnosticsPanel(
nullTranslator.load('jupyterlab_lsp')
);
export const diagnostics_databases = new WeakMap<
CodeMirrorVirtualEditor,
DiagnosticsDatabase
Expand Down Expand Up @@ -349,7 +355,7 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
diagnostics_panel.update();
};

protected collapse_overlapping_diagnostics(
protected collapseOverlappingDiagnostics(
diagnostics: lsProtocol.Diagnostic[]
): Map<lsProtocol.Range, lsProtocol.Diagnostic[]> {
// because Range is not a primitive type, the equality of the objects having
Expand Down Expand Up @@ -447,7 +453,7 @@ export class DiagnosticsCM extends CodeMirrorIntegration {

// TODO: test case for severity class always being set, even if diagnostic has no severity

let diagnostics_by_range = this.collapse_overlapping_diagnostics(
let diagnostics_by_range = this.collapseOverlappingDiagnostics(
this.filterDiagnostics(response.diagnostics)
);

Expand Down Expand Up @@ -607,7 +613,7 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
);

// remove the markers which were not included in the new message
this.remove_unused_diagnostic_markers(markers_to_retain);
this.removeUnusedDiagnosticMarkers(markers_to_retain);

this.diagnostics_db.set(this.virtual_document, diagnostics_list);
}
Expand Down Expand Up @@ -641,7 +647,7 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
diagnostics_panel.update();
}

protected remove_unused_diagnostic_markers(to_retain: Set<string>) {
protected removeUnusedDiagnosticMarkers(to_retain: Set<string>) {
this.marked_diagnostics.forEach(
(marker: CodeMirror.TextMarker, diagnostic_hash: string) => {
if (!to_retain.has(diagnostic_hash)) {
Expand All @@ -655,7 +661,7 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
remove(): void {
this.settings.changed.disconnect(this.refreshDiagnostics, this);
// remove all markers
this.remove_unused_diagnostic_markers(new Set());
this.removeUnusedDiagnosticMarkers(new Set());
this.diagnostics_db.clear();
diagnostics_databases.delete(this.virtual_editor);
this.unique_editor_ids.clear();
Expand Down
1 change: 1 addition & 0 deletions packages/jupyterlab-lsp/src/features/diagnostics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const COMMANDS = (trans: TranslationBundle): IFeatureCommand[] => [
diagnostics_feature.switchDiagnosticsPanelSource();

if (!diagnostics_panel.is_registered) {
diagnostics_panel.trans = trans;
diagnostics_panel.register(app);
}

Expand Down

0 comments on commit 9bd55aa

Please sign in to comment.