Skip to content

Commit 22e0bf4

Browse files
committed
Limt; improve the action on unexpected arrays length difference on set
1 parent d441550 commit 22e0bf4

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,36 +148,40 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
148148
let convertedToMarkdownOrRaw = [];
149149
let convertedToCode = [];
150150

151-
if (change.newValues.length !== change.oldValues.length) {
151+
if (change.newValues.length === change.oldValues.length) {
152152
// during conversion the cells should not get deleted nor added
153-
return;
154-
}
155-
156-
for (let i = 0; i < change.newValues.length; i++) {
157-
if (
158-
change.oldValues[i].type === 'code' &&
159-
change.newValues[i].type !== 'code'
160-
) {
161-
convertedToMarkdownOrRaw.push(change.newValues[i]);
162-
} else if (
163-
change.oldValues[i].type !== 'code' &&
164-
change.newValues[i].type === 'code'
165-
) {
166-
convertedToCode.push(change.newValues[i]);
153+
for (let i = 0; i < change.newValues.length; i++) {
154+
if (
155+
change.oldValues[i].type === 'code' &&
156+
change.newValues[i].type !== 'code'
157+
) {
158+
convertedToMarkdownOrRaw.push(change.newValues[i]);
159+
} else if (
160+
change.oldValues[i].type !== 'code' &&
161+
change.newValues[i].type === 'code'
162+
) {
163+
convertedToCode.push(change.newValues[i]);
164+
}
167165
}
166+
cellsAdded = convertedToCode;
167+
cellsRemoved = convertedToMarkdownOrRaw;
168168
}
169-
cellsAdded = convertedToCode;
170-
cellsRemoved = convertedToMarkdownOrRaw;
171-
172169
} else if (change.type == 'add') {
173-
cellsAdded = change.newValues.filter((cellModel) => cellModel.type === 'code')
170+
cellsAdded = change.newValues.filter(
171+
cellModel => cellModel.type === 'code'
172+
);
174173
}
175174
// note: editorRemoved is not emitted for removal of cells by change of type 'remove' (but only during cell type conversion)
176175
// because there is no easy way to get the widget associated with the removed cell(s) - because it is no
177176
// longer in the notebook widget list! It would need to be tracked on our side, but it is not necessary
178177
// as (except for a tiny memory leak) it should not impact the functionality in any way
179178

180-
if (cellsRemoved.length || cellsAdded.length || change.type === 'move' || change.type === 'remove') {
179+
if (
180+
cellsRemoved.length ||
181+
cellsAdded.length ||
182+
change.type === 'move' ||
183+
change.type === 'remove'
184+
) {
181185
// in contrast to the file editor document which can be only changed by the modification of the editor content,
182186
// the notebook document cna also get modified by a change in the number or arrangement of editors themselves;
183187
// for this reason each change has to trigger documents update (so that LSP mirror is in sync).
@@ -188,7 +192,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
188192
let cellWidget = this.widget.content.widgets.find(
189193
cell => cell.model.id === cellModel.id
190194
);
191-
this.known_editors_ids.delete(cellWidget.editor.uuid)
195+
this.known_editors_ids.delete(cellWidget.editor.uuid);
192196

193197
// for practical purposes this editor got removed from our consideration;
194198
// it might seem that we should instead look for the editor indicated by
@@ -203,13 +207,12 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
203207
let cellWidget = this.widget.content.widgets.find(
204208
cell => cell.model.id === cellModel.id
205209
);
206-
this.known_editors_ids.add(cellWidget.editor.uuid)
210+
this.known_editors_ids.add(cellWidget.editor.uuid);
207211

208212
this.editorAdded.emit({
209213
editor: cellWidget.editor
210214
});
211215
}
212-
213216
});
214217
}
215218

packages/jupyterlab-lsp/src/editor_integration/testutils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ export namespace IFeatureTestEnvironment {
178178
type TestEnvironmentConstructor = new (...args: any[]) => ITestEnvironment;
179179

180180
function FeatureSupport<TBase extends TestEnvironmentConstructor>(Base: TBase) {
181-
return class FeatureTestEnvironment
182-
extends Base
181+
return class FeatureTestEnvironment extends Base
183182
implements IFeatureTestEnvironment {
184183
_connections: Map<CodeMirrorIntegration, LSPConnection>;
185184

packages/jupyterlab-lsp/src/virtual/codemirror_editor.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,10 @@ export class CodeMirrorVirtualEditor
519519
callback(cm_editor);
520520
}
521521
if (monitor_for_new_blocks) {
522-
523-
let activation_callback = (adapter: WidgetAdapter<IDocumentWidget>, data: IEditorChangedData) => {
522+
let activation_callback = (
523+
adapter: WidgetAdapter<IDocumentWidget>,
524+
data: IEditorChangedData
525+
) => {
524526
let { editor } = data;
525527
if (editor == null) {
526528
return;
@@ -529,9 +531,9 @@ export class CodeMirrorVirtualEditor
529531
if (!editors_with_handlers.has(cm_editor)) {
530532
callback(cm_editor);
531533
}
532-
}
534+
};
533535

534-
this.adapter.editorAdded.connect(activation_callback)
536+
this.adapter.editorAdded.connect(activation_callback);
535537
this.adapter.editorRemoved.connect(
536538
(adapter, data: IEditorChangedData) => {
537539
let { editor } = data;

0 commit comments

Comments
 (0)