Skip to content

Commit ececa35

Browse files
committed
Squash more warnings and do not hard-code the cell type
1 parent 90778b1 commit ececa35

File tree

1 file changed

+15
-6
lines changed
  • packages/jupyterlab-lsp/src/adapters/notebook

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
2020
private known_editors_ids: Set<string>;
2121

2222
private _language_info: ILanguageInfoMetadata;
23+
private type: nbformat.CellType = 'code';
2324

2425
constructor(extension: LSPExtension, editor_widget: NotebookPanel) {
2526
super(extension, editor_widget);
@@ -141,6 +142,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
141142
this.widget.model.cells.changed.connect(async (cells, change) => {
142143
let cellsAdded: ICellModel[] = [];
143144
let cellsRemoved: ICellModel[] = [];
145+
const type = this.type;
144146

145147
if (change.type === 'set') {
146148
// handling of conversions is important, because the editors get re-used and their handlers inherited,
@@ -152,13 +154,13 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
152154
// during conversion the cells should not get deleted nor added
153155
for (let i = 0; i < change.newValues.length; i++) {
154156
if (
155-
change.oldValues[i].type === 'code' &&
156-
change.newValues[i].type !== 'code'
157+
change.oldValues[i].type === type &&
158+
change.newValues[i].type !== type
157159
) {
158160
convertedToMarkdownOrRaw.push(change.newValues[i]);
159161
} else if (
160-
change.oldValues[i].type !== 'code' &&
161-
change.newValues[i].type === 'code'
162+
change.oldValues[i].type !== type &&
163+
change.newValues[i].type === type
162164
) {
163165
convertedToCode.push(change.newValues[i]);
164166
}
@@ -168,7 +170,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
168170
}
169171
} else if (change.type == 'add') {
170172
cellsAdded = change.newValues.filter(
171-
cellModel => cellModel.type === 'code'
173+
cellModel => cellModel.type === type
172174
);
173175
}
174176
// note: editorRemoved is not emitted for removal of cells by change of type 'remove' (but only during cell type conversion)
@@ -256,7 +258,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
256258
}
257259

258260
private activeCellChanged(notebook: Notebook, cell: Cell) {
259-
if (cell.model.type !== 'code') {
261+
if (cell.model.type !== this.type) {
260262
return;
261263
}
262264
if (!this.known_editors_ids.has(cell.editor.uuid)) {
@@ -272,6 +274,13 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
272274

273275
context_from_active_document(): ICommandContext | null {
274276
let cell = this.widget.content.activeCell;
277+
if (cell.model.type !== this.type) {
278+
// context will be sought on all cells to verify if the context menu should be visible,
279+
// thus it is ok to just return null; it seems to stem from the implementation detail
280+
// upstream, i.e. the markdown cells appear to be created by transforming the code cells
281+
// but do not quote me on that.
282+
return null;
283+
}
275284
let editor = cell.editor;
276285
let ce_cursor = editor.getCursorPosition();
277286
let cm_cursor = PositionConverter.ce_to_cm(ce_cursor) as IEditorPosition;

0 commit comments

Comments
 (0)