diff --git a/src/standalone/executionAnalysis/symbols.ts b/src/standalone/executionAnalysis/symbols.ts index cb451f9f65d..49cced10704 100644 --- a/src/standalone/executionAnalysis/symbols.ts +++ b/src/standalone/executionAnalysis/symbols.ts @@ -63,9 +63,9 @@ export class CellAnalysis { /** * Get predecessor cells */ - getPredecessorCells(cell: vscode.NotebookCell): vscode.NotebookCell[] { + getPredecessorCells(cell: vscode.NotebookCell, forceReadNotebook: boolean = false): vscode.NotebookCell[] { // find last execution item index from cell list whose cell property matches cell - const virtualCellList = this._getVirtualCellList(cell); + const virtualCellList = forceReadNotebook ? this._notebookDocument.getCells() : this._getVirtualCellList(cell); var i; for ( i = virtualCellList.length - 1; @@ -290,9 +290,19 @@ export class NotebookDocumentSymbolTracker { async selectPrecedentCells(cell: vscode.NotebookCell) { await this.requestCellSymbolsSync(); const analysis = new CellAnalysis(this._notebookEditor.notebook, this._cellExecution, this._cellRefs); - const precedentCells = analysis.getPredecessorCells(cell) as vscode.NotebookCell[]; - const cellRanges = cellIndexesToRanges(precedentCells.map((cell) => cell.index)); - this._notebookEditor.selections = cellRanges; + try { + const precedentCells = analysis.getPredecessorCells(cell); + this._notebookEditor.selections = cellIndexesToRanges(precedentCells.map((cell) => cell.index)); + return; + } catch {} + + try { + const precedentCells = analysis.getPredecessorCells(cell, true); + this._notebookEditor.selections = cellIndexesToRanges(precedentCells.map((cell) => cell.index)); + return; + } catch { + // noop + } } async selectSuccessorCells(cell: vscode.NotebookCell) { @@ -306,7 +316,18 @@ export class NotebookDocumentSymbolTracker { async runPrecedentCells(cell: vscode.NotebookCell) { await this.requestCellSymbolsSync(); const analysis = new CellAnalysis(this._notebookEditor.notebook, this._cellExecution, this._cellRefs); - const precedentCells = analysis.getPredecessorCells(cell) as vscode.NotebookCell[]; + let precedentCells: vscode.NotebookCell[] = []; + + try { + precedentCells = analysis.getPredecessorCells(cell); + } catch { + // precendent cells might not be executed yet + try { + precedentCells = analysis.getPredecessorCells(cell, true); + } catch { + throw new Error('No precedent cells found'); + } + } // find the first stale cell const staleCellIndex = precedentCells.findIndex( diff --git a/src/test/datascience/widgets/standardWidgets.vscode.common.test.ts b/src/test/datascience/widgets/standardWidgets.vscode.common.test.ts index 37a4d46d2eb..c0d7293bba3 100644 --- a/src/test/datascience/widgets/standardWidgets.vscode.common.test.ts +++ b/src/test/datascience/widgets/standardWidgets.vscode.common.test.ts @@ -133,7 +133,7 @@ suite('Standard IPyWidget Tests @widgets', function () { // and the output is not visible, then it will not get rendered & the tests will fail. The tests inspect the rendered HTML. // Solution - maximize available real-estate by hiding the output panels & hiding the input cells. await commands.executeCommand('workbench.action.closePanel'); - await commands.executeCommand('workbench.action.maximizeEditor'); + await commands.executeCommand('workbench.action.maximizeEditorGroup'); await commands.executeCommand('notebook.cell.collapseAllCellInputs'); comms = await initializeWidgetComms(disposables); diff --git a/src/test/datascience/widgets/thirdpartyWidgets.vscode.common.test.ts b/src/test/datascience/widgets/thirdpartyWidgets.vscode.common.test.ts index 42d2e81fcd9..ec2c80744b7 100644 --- a/src/test/datascience/widgets/thirdpartyWidgets.vscode.common.test.ts +++ b/src/test/datascience/widgets/thirdpartyWidgets.vscode.common.test.ts @@ -80,7 +80,7 @@ import { getTextOutputValue } from '../../../kernels/execution/helpers'; // and the output is not visible, then it will not get rendered & the tests will fail. The tests inspect the rendered HTML. // Solution - maximize available real-estate by hiding the output panels & hiding the input cells. await commands.executeCommand('workbench.action.closePanel'); - await commands.executeCommand('workbench.action.maximizeEditor'); + await commands.executeCommand('workbench.action.maximizeEditorGroup'); comms = await initializeWidgetComms(disposables); vscodeNotebook = api.serviceContainer.get(IVSCodeNotebook);