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

debug: allow orphans to outlive their parents #169074

Merged
merged 1 commit into from
Dec 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/debug/browser/debugCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
} else {
const showSubSessions = configurationService.getValue<IDebugConfiguration>('debug').showSubSessionsInToolBar;
// Stop should be sent to the root parent session
while (!showSubSessions && session && session.parentSession) {
while (!showSubSessions && session.lifecycleManagedByParent && session.parentSession) {
session = session.parentSession;
}
session.removeReplExpressions();
Expand Down Expand Up @@ -605,7 +605,7 @@ async function stopHandler(accessor: ServicesAccessor, _: string, context: CallS
const configurationService = accessor.get(IConfigurationService);
const showSubSessions = configurationService.getValue<IDebugConfiguration>('debug').showSubSessionsInToolBar;
// Stop should be sent to the root parent session
while (!showSubSessions && session && session.parentSession) {
while (!showSubSessions && session && session.lifecycleManagedByParent && session.parentSession) {
session = session.parentSession;
}

Expand Down
29 changes: 22 additions & 7 deletions src/vs/workbench/contrib/debug/browser/debugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cance
import { canceled } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { normalizeDriveLetter } from 'vs/base/common/labels';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore, dispose, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { mixin } from 'vs/base/common/objects';
import * as platform from 'vs/base/common/platform';
import * as resources from 'vs/base/common/resources';
Expand Down Expand Up @@ -40,6 +40,7 @@ import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecy
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';

export class DebugSession implements IDebugSession {
parentSession: IDebugSession | undefined;

private _subId: string | undefined;
raw: RawDebugSession | undefined; // used in tests
Expand Down Expand Up @@ -93,24 +94,26 @@ export class DebugSession implements IDebugSession {
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService,
) {
this._options = options || {};
this.parentSession = this._options.parentSession;
if (this.hasSeparateRepl()) {
this.repl = new ReplModel(this.configurationService);
} else {
this.repl = (this.parentSession as DebugSession).repl;
}

const toDispose: IDisposable[] = [];
toDispose.push(this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire()));
const toDispose = new DisposableStore();
const replListener = toDispose.add(new MutableDisposable());
replListener.value = this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire());
if (lifecycleService) {
toDispose.push(lifecycleService.onWillShutdown(() => {
toDispose.add(lifecycleService.onWillShutdown(() => {
this.shutdown();
dispose(toDispose);
}));
}

const compoundRoot = this._options.compoundRoot;
if (compoundRoot) {
toDispose.push(compoundRoot.onDidSessionStop(() => this.terminate()));
toDispose.add(compoundRoot.onDidSessionStop(() => this.terminate()));
}
this.passFocusScheduler = new RunOnceScheduler(() => {
// If there is some session or thread that is stopped pass focus to it
Expand All @@ -130,6 +133,18 @@ export class DebugSession implements IDebugSession {
}
}
}, 800);

const parent = this._options.parentSession;
if (parent) {
toDispose.add(parent.onDidEndAdapter(() => {
// copy the parent repl and get a new detached repl for this child
if (!this.hasSeparateRepl()) {
this.repl = this.repl.clone();
replListener.value = this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire());
}
this.parentSession = undefined;
}));
}
}

getId(): string {
Expand All @@ -156,8 +171,8 @@ export class DebugSession implements IDebugSession {
return this._configuration.unresolved;
}

get parentSession(): IDebugSession | undefined {
return this._options.parentSession;
get lifecycleManagedByParent(): boolean {
return !!this._options.lifecycleManagedByParent;
}

get compact(): boolean {
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/debug/browser/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export class Repl extends FilterViewPane implements IHistoryNavigationWidget {
}
this.multiSessionRepl.set(this.isMultiSessionView);
}));
this._register(this.debugService.onDidEndSession(async session => {
// Update view, since orphaned sessions might now be separate
await Promise.resolve(); // allow other listeners to go first, so sessions can update parents
this.multiSessionRepl.set(this.isMultiSessionView);
}));
this._register(this.themeService.onDidColorThemeChange(() => {
this.refreshReplElements(false);
if (this.isVisible()) {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export interface IDebugSession extends ITreeElement {
readonly suppressDebugToolbar: boolean;
readonly suppressDebugStatusbar: boolean;
readonly suppressDebugView: boolean;
readonly lifecycleManagedByParent: boolean;

setSubId(subId: string | undefined): void;

Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/contrib/debug/common/replModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,11 @@ export class ReplModel {
this._onDidChangeElements.fire();
}
}

/** Returns a new REPL model that's a copy of this one. */
clone() {
const newRepl = new ReplModel(this.configurationService);
newRepl.replElements = this.replElements.slice();
return newRepl;
}
}
4 changes: 4 additions & 0 deletions src/vs/workbench/contrib/debug/test/common/mockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export class MockSession implements IDebugSession {
return false;
}

get lifecycleManagedByParent(): boolean {
return false;
}

stepInTargets(frameId: number): Promise<{ id: number; label: string }[]> {
throw new Error('Method not implemented.');
}
Expand Down