Skip to content

Commit 2ea6f55

Browse files
authored
Selective webview warmup based on cell selection (#239721)
selective webview warmup based on cell selection
1 parent 9ae8fb1 commit 2ea6f55

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
24632463
} else {
24642464
await this.revealInView(cell);
24652465
}
2466+
24662467
}
24672468

24682469
}
@@ -2609,6 +2610,37 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
26092610
return Promise.all(requests);
26102611
}
26112612

2613+
private async _warmupSelection(includeOutput: boolean, selectedCellRanges: ICellRange[]) {
2614+
if (!this.hasModel() || !this.viewModel) {
2615+
return;
2616+
}
2617+
2618+
const cells = this.viewModel.viewCells;
2619+
const requests = [];
2620+
2621+
for (const range of selectedCellRanges) {
2622+
for (let i = range.start; i < range.end; i++) {
2623+
if (cells[i].cellKind === CellKind.Markup && !this._webview!.markupPreviewMapping.has(cells[i].id)) {
2624+
requests.push(this.createMarkupPreview(cells[i]));
2625+
}
2626+
}
2627+
}
2628+
2629+
if (includeOutput && this._list) {
2630+
for (const range of selectedCellRanges) {
2631+
for (let i = range.start; i < range.end; i++) {
2632+
const cell = this._list.element(i);
2633+
2634+
if (cell?.cellKind === CellKind.Code) {
2635+
requests.push(this._warmupCell((cell as CodeCellViewModel)));
2636+
}
2637+
}
2638+
}
2639+
}
2640+
2641+
return Promise.all(requests);
2642+
}
2643+
26122644
async find(query: string, options: INotebookFindOptions, token: CancellationToken, skipWarmup: boolean = false, shouldGetSearchPreviewInfo = false, ownerID?: string): Promise<CellFindMatchWithIndex[]> {
26132645
if (!this._notebookViewModel) {
26142646
return [];
@@ -2633,10 +2665,14 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
26332665
});
26342666

26352667
if (this._webview) {
2636-
// request all outputs to be rendered
2668+
// request all or some outputs to be rendered
26372669
// measure perf
26382670
const start = Date.now();
2639-
await this._warmupAll(!!options.includeOutput);
2671+
if (options.findScope && options.findScope.findScopeType === NotebookFindScopeType.Cells && options.findScope.selectedCellRanges) {
2672+
await this._warmupSelection(!!options.includeOutput, options.findScope.selectedCellRanges);
2673+
} else {
2674+
await this._warmupAll(!!options.includeOutput);
2675+
}
26402676
const end = Date.now();
26412677
this.logService.debug('Find', `Warmup time: ${end - start}ms`);
26422678

0 commit comments

Comments
 (0)