Skip to content

Commit

Permalink
Make DebugSession.name writable; fixes #79583
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman committed Sep 4, 2019
1 parent 7e5adb5 commit cb6b17d
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8687,9 +8687,10 @@ declare module 'vscode' {
readonly type: string;

/**
* The debug session's name from the [debug configuration](#DebugConfiguration).
* The debug session's name is initially taken from the [debug configuration](#DebugConfiguration).
* Any changes will be properly reflected in the UI.
*/
readonly name: string;
name: string;

/**
* The workspace folder of this session or `undefined` for a folderless setup.
Expand Down
10 changes: 10 additions & 0 deletions src/vs/workbench/api/browser/mainThreadDebugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostDebugService);
this._toDispose.add(debugService.onDidNewSession(session => {
this._proxy.$acceptDebugSessionStarted(this.getSessionDto(session));
this._toDispose.add(session.onDidChangeName(name => {
this._proxy.$acceptDebugSessionNameChanged(this.getSessionDto(session), name);
}));
}));
// Need to start listening early to new session events because a custom event can come while a session is initialising
this._toDispose.add(debugService.onWillNewSession(session => {
Expand Down Expand Up @@ -225,6 +228,13 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
});
}

public $setDebugSessionName(sessionId: DebugSessionUUID, name: string): void {
const session = this.debugService.getModel().getSession(sessionId);
if (session) {
session.setName(name);
}
}

public $customDebugAdapterRequest(sessionId: DebugSessionUUID, request: string, args: any): Promise<any> {
const session = this.debugService.getModel().getSession(sessionId, true);
if (session) {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ export interface MainThreadDebugServiceShape extends IDisposable {
$unregisterDebugConfigurationProvider(handle: number): void;
$unregisterDebugAdapterDescriptorFactory(handle: number): void;
$startDebugging(folder: UriComponents | undefined, nameOrConfig: string | IDebugConfiguration, parentSessionID: string | undefined): Promise<boolean>;
$setDebugSessionName(id: DebugSessionUUID, name: string): void;
$customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): Promise<any>;
$appendDebugConsole(value: string): void;
$startBreakpointEvents(): void;
Expand Down Expand Up @@ -1263,6 +1264,7 @@ export interface ExtHostDebugServiceShape {
$acceptDebugSessionActiveChanged(session: IDebugSessionDto | undefined): void;
$acceptDebugSessionCustomEvent(session: IDebugSessionDto, event: any): void;
$acceptBreakpointsDelta(delta: IBreakpointsDeltaDto): void;
$acceptDebugSessionNameChanged(session: IDebugSessionDto, name: string): void;
}


Expand Down
16 changes: 16 additions & 0 deletions src/vs/workbench/api/node/extHostDebugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,13 @@ export class ExtHostDebugService implements IExtHostDebugService, ExtHostDebugSe
this._onDidChangeActiveDebugSession.fire(this._activeDebugSession);
}

public async $acceptDebugSessionNameChanged(sessionDto: IDebugSessionDto, name: string): Promise<void> {
const session = await this.getSession(sessionDto);
if (session) {
session._acceptNameChanged(name);
}
}

public async $acceptDebugSessionCustomEvent(sessionDto: IDebugSessionDto, event: any): Promise<void> {
const session = await this.getSession(sessionDto);
const ee: vscode.DebugSessionCustomEvent = {
Expand Down Expand Up @@ -917,6 +924,15 @@ export class ExtHostDebugSession implements vscode.DebugSession {
return this._name;
}

public set name(name: string) {
this._name = name;
this._debugServiceProxy.$setDebugSessionName(this._id, name);
}

_acceptNameChanged(name: string) {
this._name = name;
}

public get workspaceFolder(): vscode.WorkspaceFolder | undefined {
return this._workspaceFolder;
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/debug/browser/callStackView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class CallStackView extends ViewletPanel {
}));

this._register(this.debugService.onDidNewSession(s => {
this._register(s.onDidChangeName(() => this.tree.rerender(s)));
if (s.parentSession) {
// Auto expand sessions that have sub sessions
this.parentSessionToExpand.add(s.parentSession);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ export class FocusSessionActionViewItem extends SelectActionViewItem {
}
}));

this._register(this.debugService.onDidNewSession(() => this.update()));
this._register(this.debugService.onDidNewSession(session => {
this._register(session.onDidChangeName(() => this.update()));
this.update();
}));
this.getSessions().forEach(session => {
this._register(session.onDidChangeName(() => this.update()));
});
this._register(this.debugService.onDidEndSession(() => this.update()));

this.update();
Expand Down
15 changes: 14 additions & 1 deletion src/vs/workbench/contrib/debug/browser/debugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export class DebugSession implements IDebugSession {

private readonly _onDidChangeREPLElements = new Emitter<void>();

private name: string | undefined;
private readonly _onDidChangeName = new Emitter<string>();

constructor(
private _configuration: { resolved: IConfig, unresolved: IConfig | undefined },
public root: IWorkspaceFolder,
Expand Down Expand Up @@ -105,7 +108,13 @@ export class DebugSession implements IDebugSession {

getLabel(): string {
const includeRoot = this.workspaceContextService.getWorkspace().folders.length > 1;
return includeRoot && this.root ? `${this.configuration.name} (${resources.basenameOrAuthority(this.root.uri)})` : this.configuration.name;
const name = this.name || this.configuration.name;
return includeRoot && this.root ? `${name} (${resources.basenameOrAuthority(this.root.uri)})` : name;
}

setName(name: string): void {
this.name = name;
this._onDidChangeName.fire(name);
}

get state(): State {
Expand Down Expand Up @@ -144,6 +153,10 @@ export class DebugSession implements IDebugSession {
return this._onDidChangeREPLElements.event;
}

get onDidChangeName(): Event<string> {
return this._onDidChangeName.event;
}

//---- DAP events

get onDidCustomEvent(): Event<DebugProtocol.Event> {
Expand Down
32 changes: 19 additions & 13 deletions src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,31 +466,37 @@ export class LoadedScriptsView extends ViewletPanel {
}
}));

const registerLoadedSourceListener = (session: IDebugSession) => {
const scheduleRefreshOnVisible = () => {
if (this.isBodyVisible()) {
this.changeScheduler.schedule();
} else {
this.treeNeedsRefreshOnVisible = true;
}
};

const registerSessionListeners = (session: IDebugSession) => {
this._register(session.onDidChangeName(() => {
// Re-add session, this will trigger proper sorting and id recalculation.
root.remove(session.getId());
root.add(session);
scheduleRefreshOnVisible();
}));
this._register(session.onDidLoadedSource(event => {
let sessionRoot: SessionTreeItem;
switch (event.reason) {
case 'new':
case 'changed':
sessionRoot = root.add(session);
sessionRoot.addPath(event.source);
if (this.isBodyVisible()) {
this.changeScheduler.schedule();
} else {
this.treeNeedsRefreshOnVisible = true;
}
scheduleRefreshOnVisible();
if (event.reason === 'changed') {
DebugContentProvider.refreshDebugContent(event.source.uri);
}
break;
case 'removed':
sessionRoot = root.find(session);
if (sessionRoot && sessionRoot.removePath(event.source)) {
if (this.isBodyVisible()) {
this.changeScheduler.schedule();
} else {
this.treeNeedsRefreshOnVisible = true;
}
scheduleRefreshOnVisible();
}
break;
default:
Expand All @@ -501,8 +507,8 @@ export class LoadedScriptsView extends ViewletPanel {
}));
};

this._register(this.debugService.onDidNewSession(registerLoadedSourceListener));
this.debugService.getModel().getSessions().forEach(registerLoadedSourceListener);
this._register(this.debugService.onDidNewSession(registerSessionListeners));
this.debugService.getModel().getSessions().forEach(registerSessionListeners);

this._register(this.debugService.onDidEndSession(session => {
root.remove(session.getId());
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export interface IDebugSession extends ITreeElement {

setSubId(subId: string | undefined): void;

setName(name: string): void;
readonly onDidChangeName: Event<string>;
getLabel(): string;

getSourceForUri(modelUri: uri): Source | undefined;
Expand Down
8 changes: 8 additions & 0 deletions src/vs/workbench/contrib/debug/test/common/mockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export class MockSession implements IDebugSession {
return 'mockname';
}

setName(name: string): void {
throw new Error('not implemented');
}

getSourceForUri(modelUri: uri): Source {
throw new Error('not implemented');
}
Expand All @@ -204,6 +208,10 @@ export class MockSession implements IDebugSession {
throw new Error('not implemented');
}

get onDidChangeName(): Event<string> {
throw new Error('not implemented');
}

setConfiguration(configuration: { resolved: IConfig, unresolved: IConfig }) { }

getAllThreads(): IThread[] {
Expand Down

0 comments on commit cb6b17d

Please sign in to comment.