Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unexecuted precedent cells #14549

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/standalone/executionAnalysis/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>(IVSCodeNotebook);
Expand Down
Loading