From cb6b17d6f36156cdbe48a6eaa8aac8895e95df4e Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 29 Aug 2019 17:23:16 -0700 Subject: [PATCH] Make DebugSession.name writable; fixes #79583 --- src/vs/vscode.d.ts | 5 +-- .../api/browser/mainThreadDebugService.ts | 10 ++++++ .../workbench/api/common/extHost.protocol.ts | 2 ++ .../workbench/api/node/extHostDebugService.ts | 16 ++++++++++ .../contrib/debug/browser/callStackView.ts | 1 + .../debug/browser/debugActionViewItems.ts | 8 ++++- .../contrib/debug/browser/debugSession.ts | 15 ++++++++- .../debug/browser/loadedScriptsView.ts | 32 +++++++++++-------- .../workbench/contrib/debug/common/debug.ts | 2 ++ .../contrib/debug/test/common/mockDebug.ts | 8 +++++ 10 files changed, 82 insertions(+), 17 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 4bf390ca0ca..812ac85c81e 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -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. diff --git a/src/vs/workbench/api/browser/mainThreadDebugService.ts b/src/vs/workbench/api/browser/mainThreadDebugService.ts index 2f0f5283bfd..5fb712fd228 100644 --- a/src/vs/workbench/api/browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/browser/mainThreadDebugService.ts @@ -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 => { @@ -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 { const session = this.debugService.getModel().getSession(sessionId, true); if (session) { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index a6ac9b8086c..dc608272431 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -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; + $setDebugSessionName(id: DebugSessionUUID, name: string): void; $customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): Promise; $appendDebugConsole(value: string): void; $startBreakpointEvents(): void; @@ -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; } diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index c82f788a370..bcb8c9810be 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -687,6 +687,13 @@ export class ExtHostDebugService implements IExtHostDebugService, ExtHostDebugSe this._onDidChangeActiveDebugSession.fire(this._activeDebugSession); } + public async $acceptDebugSessionNameChanged(sessionDto: IDebugSessionDto, name: string): Promise { + const session = await this.getSession(sessionDto); + if (session) { + session._acceptNameChanged(name); + } + } + public async $acceptDebugSessionCustomEvent(sessionDto: IDebugSessionDto, event: any): Promise { const session = await this.getSession(sessionDto); const ee: vscode.DebugSessionCustomEvent = { @@ -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; } diff --git a/src/vs/workbench/contrib/debug/browser/callStackView.ts b/src/vs/workbench/contrib/debug/browser/callStackView.ts index 46e90870f22..be89d1a2696 100644 --- a/src/vs/workbench/contrib/debug/browser/callStackView.ts +++ b/src/vs/workbench/contrib/debug/browser/callStackView.ts @@ -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); diff --git a/src/vs/workbench/contrib/debug/browser/debugActionViewItems.ts b/src/vs/workbench/contrib/debug/browser/debugActionViewItems.ts index 8e4b12fde6c..1904bd302ad 100644 --- a/src/vs/workbench/contrib/debug/browser/debugActionViewItems.ts +++ b/src/vs/workbench/contrib/debug/browser/debugActionViewItems.ts @@ -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(); diff --git a/src/vs/workbench/contrib/debug/browser/debugSession.ts b/src/vs/workbench/contrib/debug/browser/debugSession.ts index 01151248238..73907b3ca15 100644 --- a/src/vs/workbench/contrib/debug/browser/debugSession.ts +++ b/src/vs/workbench/contrib/debug/browser/debugSession.ts @@ -55,6 +55,9 @@ export class DebugSession implements IDebugSession { private readonly _onDidChangeREPLElements = new Emitter(); + private name: string | undefined; + private readonly _onDidChangeName = new Emitter(); + constructor( private _configuration: { resolved: IConfig, unresolved: IConfig | undefined }, public root: IWorkspaceFolder, @@ -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 { @@ -144,6 +153,10 @@ export class DebugSession implements IDebugSession { return this._onDidChangeREPLElements.event; } + get onDidChangeName(): Event { + return this._onDidChangeName.event; + } + //---- DAP events get onDidCustomEvent(): Event { diff --git a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts index 6a70b78319b..742b41df2aa 100644 --- a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts +++ b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts @@ -466,7 +466,21 @@ 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) { @@ -474,11 +488,7 @@ export class LoadedScriptsView extends ViewletPanel { 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); } @@ -486,11 +496,7 @@ export class LoadedScriptsView extends ViewletPanel { 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: @@ -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()); diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index 42a35769797..6fe72895ba0 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -157,6 +157,8 @@ export interface IDebugSession extends ITreeElement { setSubId(subId: string | undefined): void; + setName(name: string): void; + readonly onDidChangeName: Event; getLabel(): string; getSourceForUri(modelUri: uri): Source | undefined; diff --git a/src/vs/workbench/contrib/debug/test/common/mockDebug.ts b/src/vs/workbench/contrib/debug/test/common/mockDebug.ts index bb10110ab92..4515e8afef4 100644 --- a/src/vs/workbench/contrib/debug/test/common/mockDebug.ts +++ b/src/vs/workbench/contrib/debug/test/common/mockDebug.ts @@ -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'); } @@ -204,6 +208,10 @@ export class MockSession implements IDebugSession { throw new Error('not implemented'); } + get onDidChangeName(): Event { + throw new Error('not implemented'); + } + setConfiguration(configuration: { resolved: IConfig, unresolved: IConfig }) { } getAllThreads(): IThread[] {