Select a cell when setting a breakpoint in it

Fix #130620
This commit is contained in:
Rob Lourens 2021-08-11 17:14:57 -07:00
parent ab8e743520
commit 5673802238

View file

@ -7,21 +7,25 @@
import { RunOnceScheduler } from 'vs/base/common/async';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { ResourceMap } from 'vs/base/common/map';
import { Schemas } from 'vs/base/common/network';
import { isEqual } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { IDebugService, State } from 'vs/workbench/contrib/debug/common/debug';
import { IDebugService, State, IBreakpoint } from 'vs/workbench/contrib/debug/common/debug';
import { Thread } from 'vs/workbench/contrib/debug/common/debugModel';
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CellEditType, CellUri, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
class NotebookBreakpoints extends Disposable implements IWorkbenchContribution {
constructor(
@IDebugService private readonly _debugService: IDebugService,
@INotebookService _notebookService: INotebookService,
@IEditorService private readonly _editorService: IEditorService,
) {
super();
@ -55,6 +59,29 @@ class NotebookBreakpoints extends Disposable implements IWorkbenchContribution {
this.updateBreakpoints(model);
listeners.get(model.uri)?.dispose();
}));
this._register(this._debugService.getModel().onDidChangeBreakpoints(e => {
const newCellBp = e?.added?.find(bp => 'uri' in bp && bp.uri.scheme === Schemas.vscodeNotebookCell) as IBreakpoint | undefined;
if (newCellBp) {
const parsed = CellUri.parse(newCellBp.uri);
if (!parsed) {
return;
}
const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
if (!editor || !editor.hasModel() || editor.viewModel.uri.toString() !== parsed.notebook.toString()) {
return;
}
const cell = editor.viewModel.getCellByHandle(parsed.handle);
if (!cell) {
return;
}
editor.focusElement(cell);
}
}));
}
private updateBreakpoints(model: NotebookTextModel): void {