Skip to content

Commit 6dddbd4

Browse files
authored
Merge pull request #829 from jupyter-lsp/completion/cleanup-when-disabled
Completion/cleanup when disabled
2 parents 337cb02 + 5d6ef9a commit 6dddbd4

File tree

4 files changed

+57
-22
lines changed

4 files changed

+57
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- implement settings UI using native JupyterLab 3.3 UI ([#778])
88
- bug fixes
99
- use correct websocket URL if configured as different from base URL ([#820], thanks @MikeSem)
10+
- clean up all completer styles when compelter feature is disabled ([#829]).
1011
- refactoring:
1112
- move client capabilities to features ([#738])
1213
- documentation:
@@ -26,6 +27,7 @@
2627
[#814]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/814
2728
[#820]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/820
2829
[#826]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/826
30+
[#829]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/829
2931

3032
### `@krassowski/jupyterlab-lsp 3.10.1` (2022-03-21)
3133

packages/completion-theme/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
118118
);
119119
}
120120
this.current_theme_id = id;
121-
document.body.classList.add(this.current_theme_class);
121+
if (id !== null) {
122+
document.body.classList.add(this.current_theme_class);
123+
}
122124
this.update_icons_set();
123125
}
124126

packages/completion-theme/style/index.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@
2020
/* a workaround for scrollbars being always on in the completer documentation panel, see
2121
https://github.com/jupyter-lsp/jupyterlab-lsp/pull/322#issuecomment-682724175
2222
*/
23-
.jp-Completer-docpanel {
23+
.lsp-completer .jp-Completer-docpanel {
2424
overflow: auto;
2525
}
2626

27-
.jp-Completer {
27+
.lsp-completer.jp-Completer {
2828
--lsp-completer-max-label-width: 300px;
2929
--lsp-completer-max-detail-width: 200px;
3030
}
3131

32-
.jp-Completer-match {
32+
.lsp-completer .jp-Completer-match {
3333
max-width: var(--lsp-completer-max-label-width);
3434
overflow-x: hidden;
3535
white-space: nowrap;
3636
display: block;
3737
text-overflow: ellipsis;
3838
}
3939

40-
.jp-mod-active .jp-Completer-match {
40+
.lsp-completer .jp-mod-active .jp-Completer-match {
4141
text-overflow: clip;
4242
}
4343

@@ -47,7 +47,7 @@
4747
}
4848

4949
/* a workaround for code being larger font size than text in markdown-rendered panel */
50-
.jp-Completer-docpanel pre code {
50+
.lsp-completer .jp-Completer-docpanel pre code {
5151
font-size: 90%;
5252
}
5353

@@ -81,15 +81,15 @@ body[data-lsp-completer-layout='detail-below'] .jp-Completer-match {
8181
height: var(--lsp-completer-label-height);
8282
}
8383

84-
.jp-Completer-item .jp-Completer-typeExtended {
84+
.lsp-completer .jp-Completer-item .jp-Completer-typeExtended {
8585
max-width: var(--lsp-completer-max-detail-width);
8686
min-height: 50px;
8787
overflow-x: hidden;
8888
text-overflow: ellipsis;
8989
white-space: nowrap;
9090
}
9191

92-
.jp-mod-active .jp-Completer-typeExtended {
92+
.lsp-completer .jp-mod-active .jp-Completer-typeExtended {
9393
text-overflow: clip;
9494
}
9595

packages/jupyterlab-lsp/src/features/completion/completion.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { JupyterFrontEnd } from '@jupyterlab/application';
22
import { CodeEditor } from '@jupyterlab/codeeditor';
3-
import { CompletionHandler, ICompletionManager } from '@jupyterlab/completer';
3+
import {
4+
CompletionHandler,
5+
ICompletionManager,
6+
CompleterModel
7+
} from '@jupyterlab/completer';
48
import { IDocumentWidget } from '@jupyterlab/docregistry';
59
import { NotebookPanel } from '@jupyterlab/notebook';
610
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
@@ -27,6 +31,7 @@ import { ICompletionData, LSPCompletionRenderer } from './renderer';
2731

2832
const DOC_PANEL_SELECTOR = '.jp-Completer-docpanel';
2933
const DOC_PANEL_PLACEHOLDER_CLASS = 'lsp-completer-placeholder';
34+
const LSP_COMPLETER_CLASS = 'lsp-completer';
3035

3136
export class CompletionCM extends CodeMirrorIntegration {
3237
private _completionCharacters: string[];
@@ -88,6 +93,8 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
8893
protected current_adapter: WidgetAdapter<IDocumentWidget> | null = null;
8994
protected renderer: LSPCompletionRenderer;
9095
private _latestActiveItem: LazyCompletionItem | null = null;
96+
private _signalConnected: boolean = false;
97+
private _disabled: boolean;
9198

9299
constructor(
93100
private app: JupyterFrontEnd,
@@ -108,24 +115,40 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
108115
});
109116
this.renderer.activeChanged.connect(this.active_completion_changed, this);
110117
this.renderer.itemShown.connect(this.resolve_and_update, this);
118+
this._signalConnected = false;
119+
this._disabled = false;
111120
// TODO: figure out a better way to disable lab integration elements (postpone initialization?)
112121
settings.ready
113122
.then(() => {
123+
this._disabled = settings.composite.disable;
114124
if (!settings.composite.disable) {
115125
adapterManager.adapterChanged.connect(this.swap_adapter, this);
126+
this._signalConnected = true;
116127
}
117128
})
118129
.catch(console.warn);
130+
119131
settings.changed.connect(() => {
120-
completionThemeManager.set_theme(this.settings.composite.theme);
121-
completionThemeManager.set_icons_overrides(
122-
this.settings.composite.typesMap
123-
);
132+
this._disabled = settings.composite.disable;
124133
if (!settings.composite.disable) {
125134
document.body.dataset.lspCompleterLayout =
126135
this.settings.composite.layout;
136+
completionThemeManager.set_theme(this.settings.composite.theme);
137+
completionThemeManager.set_icons_overrides(
138+
this.settings.composite.typesMap
139+
);
140+
if (!this._signalConnected) {
141+
adapterManager.adapterChanged.connect(this.swap_adapter, this);
142+
this._signalConnected = true;
143+
}
144+
} else {
145+
completionThemeManager.set_theme(null);
146+
delete document.body.dataset.lspCompleterLayout;
127147
}
128-
if (this.current_completion_handler) {
148+
if (
149+
this.current_completion_handler &&
150+
this.model instanceof LSPCompleterModel
151+
) {
129152
this.model.settings.caseSensitive =
130153
this.settings.composite.caseSensitive;
131154
this.model.settings.includePerfectMatches =
@@ -284,21 +307,26 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
284307
this.renderer
285308
) as CompletionHandler;
286309
let completer = this.completer;
287-
completer.addClass('lsp-completer');
288-
completer.model = new LSPCompleterModel({
289-
caseSensitive: this.settings.composite.caseSensitive,
290-
includePerfectMatches: this.settings.composite.includePerfectMatches,
291-
preFilterMatches: this.settings.composite.preFilterMatches
292-
});
310+
if (this._disabled) {
311+
completer.removeClass(LSP_COMPLETER_CLASS);
312+
completer.model = new CompleterModel();
313+
} else {
314+
completer.addClass(LSP_COMPLETER_CLASS);
315+
completer.model = new LSPCompleterModel({
316+
caseSensitive: this.settings.composite.caseSensitive,
317+
includePerfectMatches: this.settings.composite.includePerfectMatches,
318+
preFilterMatches: this.settings.composite.preFilterMatches
319+
});
320+
}
293321
}
294322

295323
protected get completer() {
296324
// TODO upstream: make completer public?
297325
return this.current_completion_handler.completer;
298326
}
299327

300-
protected get model(): LSPCompleterModel {
301-
return this.completer.model as LSPCompleterModel;
328+
protected get model(): LSPCompleterModel | CompleterModel {
329+
return this.completer.model as LSPCompleterModel | CompleterModel;
302330
}
303331

304332
invoke_completer(kind: ExtendedCompletionTriggerKind) {
@@ -336,6 +364,9 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
336364
private get current_items() {
337365
// TODO upstream: allow to get completionItems() without markup
338366
// (note: not trivial as _markup() does filtering too)
367+
if (!(this.model instanceof LSPCompleterModel)) {
368+
return [];
369+
}
339370
return this.model.completionItems();
340371
}
341372

0 commit comments

Comments
 (0)