Skip to content

Commit edaceab

Browse files
authored
Fixes #1017: Make sure that filter callback is called for notebooks even if no language filter is provided. (#1018)
1 parent 2e889fb commit edaceab

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

client/src/common/notebook.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -818,14 +818,9 @@ class NotebookDocumentSyncFeatureProvider implements NotebookDocumentSyncFeature
818818
return undefined;
819819
}
820820
for (const item of this.options.notebookSelector) {
821-
if (item.notebook === undefined) {
822-
if (item.cells === undefined) {
823-
return undefined;
824-
}
821+
if (item.notebook === undefined || $NotebookDocumentFilter.matchNotebook(item.notebook, notebookDocument)) {
825822
const filtered = this.filterCells(notebookDocument, cells, item.cells);
826823
return filtered.length === 0 ? undefined : filtered;
827-
} else if ($NotebookDocumentFilter.matchNotebook(item.notebook, notebookDocument)){
828-
return item.cells === undefined ? cells : this.filterCells(notebookDocument, cells, item.cells);
829824
}
830825
}
831826
return undefined;
@@ -836,14 +831,14 @@ class NotebookDocumentSyncFeatureProvider implements NotebookDocumentSyncFeature
836831
return cells !== undefined && cells[0] === cell;
837832
}
838833

839-
private filterCells(notebookDocument: vscode.NotebookDocument, cells: vscode.NotebookCell[], cellSelector: { language: string }[]): vscode.NotebookCell[] {
840-
const result = cells.filter((cell) => {
834+
private filterCells(notebookDocument: vscode.NotebookDocument, cells: vscode.NotebookCell[], cellSelector: undefined | { language: string }[]): vscode.NotebookCell[] {
835+
const filtered = cellSelector !== undefined ? cells.filter((cell) => {
841836
const cellLanguage = cell.document.languageId;
842837
return cellSelector.some((filter => (filter.language === '*' || cellLanguage === filter.language)));
843-
});
838+
}) : cells;
844839
return typeof this.client.clientOptions.notebookDocumentOptions?.filterCells === 'function'
845-
? this.client.clientOptions.notebookDocumentOptions.filterCells(notebookDocument, cells)
846-
: result;
840+
? this.client.clientOptions.notebookDocumentOptions.filterCells(notebookDocument, filtered)
841+
: filtered;
847842

848843
}
849844
}

0 commit comments

Comments
 (0)