From f252eb3f777f250bcd7dc8d8b71ee987257719ce Mon Sep 17 00:00:00 2001 From: isidor Date: Tue, 30 Jun 2020 09:36:07 +0200 Subject: [PATCH] debug: contextKeyService.bufferChangeEvents #101268 --- .../contrib/debug/browser/debugService.ts | 36 +++++++------ .../contrib/debug/common/debugViewModel.ts | 52 ++++++++++--------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index dd504fba250..b94c4b4897d 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -61,11 +61,11 @@ export class DebugService implements IDebugService { private taskRunner: DebugTaskRunner; private configurationManager: ConfigurationManager; private toDispose: IDisposable[]; - private debugType: IContextKey; - private debugState: IContextKey; - private inDebugMode: IContextKey; - private debugUx: IContextKey; - private breakpointsExist: IContextKey; + private debugType!: IContextKey; + private debugState!: IContextKey; + private inDebugMode!: IContextKey; + private debugUx!: IContextKey; + private breakpointsExist!: IContextKey; private breakpointsToSendOnResourceSaved: Set; private initializing = false; private previousState: State | undefined; @@ -80,7 +80,7 @@ export class DebugService implements IDebugService { @IDialogService private readonly dialogService: IDialogService, @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, @IWorkspaceContextService private readonly contextService: IWorkspaceContextService, - @IContextKeyService contextKeyService: IContextKeyService, + @IContextKeyService private readonly contextKeyService: IContextKeyService, @ILifecycleService private readonly lifecycleService: ILifecycleService, @IInstantiationService private readonly instantiationService: IInstantiationService, @IExtensionService private readonly extensionService: IExtensionService, @@ -101,17 +101,19 @@ export class DebugService implements IDebugService { this.configurationManager = this.instantiationService.createInstance(ConfigurationManager); this.toDispose.push(this.configurationManager); - this.debugType = CONTEXT_DEBUG_TYPE.bindTo(contextKeyService); - this.debugState = CONTEXT_DEBUG_STATE.bindTo(contextKeyService); - this.inDebugMode = CONTEXT_IN_DEBUG_MODE.bindTo(contextKeyService); - this.debugUx = CONTEXT_DEBUG_UX.bindTo(contextKeyService); - this.debugUx.set(!!this.configurationManager.selectedConfiguration.name ? 'default' : 'simple'); + contextKeyService.bufferChangeEvents(() => { + this.debugType = CONTEXT_DEBUG_TYPE.bindTo(contextKeyService); + this.debugState = CONTEXT_DEBUG_STATE.bindTo(contextKeyService); + this.inDebugMode = CONTEXT_IN_DEBUG_MODE.bindTo(contextKeyService); + this.debugUx = CONTEXT_DEBUG_UX.bindTo(contextKeyService); + this.debugUx.set(!!this.configurationManager.selectedConfiguration.name ? 'default' : 'simple'); + this.breakpointsExist = CONTEXT_BREAKPOINTS_EXIST.bindTo(contextKeyService); + }); this.debugStorage = this.instantiationService.createInstance(DebugStorage); this.model = this.instantiationService.createInstance(DebugModel, this.debugStorage); this.telemetry = this.instantiationService.createInstance(DebugTelemetry, this.model); const setBreakpointsExistContext = () => this.breakpointsExist.set(!!(this.model.getBreakpoints().length || this.model.getDataBreakpoints().length || this.model.getFunctionBreakpoints().length)); - this.breakpointsExist = CONTEXT_BREAKPOINTS_EXIST.bindTo(contextKeyService); setBreakpointsExistContext(); this.viewModel = new ViewModel(contextKeyService); @@ -229,10 +231,12 @@ export class DebugService implements IDebugService { private onStateChange(): void { const state = this.state; if (this.previousState !== state) { - this.debugState.set(getStateLabel(state)); - this.inDebugMode.set(state !== State.Inactive); - // Only show the simple ux if debug is not yet started and if no launch.json exists - this.debugUx.set(((state !== State.Inactive && state !== State.Initializing) || this.configurationManager.selectedConfiguration.name) ? 'default' : 'simple'); + this.contextKeyService.bufferChangeEvents(() => { + this.debugState.set(getStateLabel(state)); + this.inDebugMode.set(state !== State.Inactive); + // Only show the simple ux if debug is not yet started and if no launch.json exists + this.debugUx.set(((state !== State.Inactive && state !== State.Initializing) || this.configurationManager.selectedConfiguration.name) ? 'default' : 'simple'); + }); this.previousState = state; this._onDidChangeState.fire(state); } diff --git a/src/vs/workbench/contrib/debug/common/debugViewModel.ts b/src/vs/workbench/contrib/debug/common/debugViewModel.ts index 7a7d370ac06..f1b3ed17894 100644 --- a/src/vs/workbench/contrib/debug/common/debugViewModel.ts +++ b/src/vs/workbench/contrib/debug/common/debugViewModel.ts @@ -21,25 +21,27 @@ export class ViewModel implements IViewModel { private readonly _onDidFocusStackFrame = new Emitter<{ stackFrame: IStackFrame | undefined, explicit: boolean }>(); private readonly _onDidSelectExpression = new Emitter(); private multiSessionView: boolean; - private expressionSelectedContextKey: IContextKey; - private breakpointSelectedContextKey: IContextKey; - private loadedScriptsSupportedContextKey: IContextKey; - private stepBackSupportedContextKey: IContextKey; - private focusedSessionIsAttach: IContextKey; - private restartFrameSupportedContextKey: IContextKey; - private stepIntoTargetsSupported: IContextKey; - private jumpToCursorSupported: IContextKey; + private expressionSelectedContextKey!: IContextKey; + private breakpointSelectedContextKey!: IContextKey; + private loadedScriptsSupportedContextKey!: IContextKey; + private stepBackSupportedContextKey!: IContextKey; + private focusedSessionIsAttach!: IContextKey; + private restartFrameSupportedContextKey!: IContextKey; + private stepIntoTargetsSupported!: IContextKey; + private jumpToCursorSupported!: IContextKey; - constructor(contextKeyService: IContextKeyService) { + constructor(private contextKeyService: IContextKeyService) { this.multiSessionView = false; - this.expressionSelectedContextKey = CONTEXT_EXPRESSION_SELECTED.bindTo(contextKeyService); - this.breakpointSelectedContextKey = CONTEXT_BREAKPOINT_SELECTED.bindTo(contextKeyService); - this.loadedScriptsSupportedContextKey = CONTEXT_LOADED_SCRIPTS_SUPPORTED.bindTo(contextKeyService); - this.stepBackSupportedContextKey = CONTEXT_STEP_BACK_SUPPORTED.bindTo(contextKeyService); - this.focusedSessionIsAttach = CONTEXT_FOCUSED_SESSION_IS_ATTACH.bindTo(contextKeyService); - this.restartFrameSupportedContextKey = CONTEXT_RESTART_FRAME_SUPPORTED.bindTo(contextKeyService); - this.stepIntoTargetsSupported = CONTEXT_STEP_INTO_TARGETS_SUPPORTED.bindTo(contextKeyService); - this.jumpToCursorSupported = CONTEXT_JUMP_TO_CURSOR_SUPPORTED.bindTo(contextKeyService); + contextKeyService.bufferChangeEvents(() => { + this.expressionSelectedContextKey = CONTEXT_EXPRESSION_SELECTED.bindTo(contextKeyService); + this.breakpointSelectedContextKey = CONTEXT_BREAKPOINT_SELECTED.bindTo(contextKeyService); + this.loadedScriptsSupportedContextKey = CONTEXT_LOADED_SCRIPTS_SUPPORTED.bindTo(contextKeyService); + this.stepBackSupportedContextKey = CONTEXT_STEP_BACK_SUPPORTED.bindTo(contextKeyService); + this.focusedSessionIsAttach = CONTEXT_FOCUSED_SESSION_IS_ATTACH.bindTo(contextKeyService); + this.restartFrameSupportedContextKey = CONTEXT_RESTART_FRAME_SUPPORTED.bindTo(contextKeyService); + this.stepIntoTargetsSupported = CONTEXT_STEP_INTO_TARGETS_SUPPORTED.bindTo(contextKeyService); + this.jumpToCursorSupported = CONTEXT_JUMP_TO_CURSOR_SUPPORTED.bindTo(contextKeyService); + }); } getId(): string { @@ -66,13 +68,15 @@ export class ViewModel implements IViewModel { this._focusedThread = thread; this._focusedSession = session; - this.loadedScriptsSupportedContextKey.set(session ? !!session.capabilities.supportsLoadedSourcesRequest : false); - this.stepBackSupportedContextKey.set(session ? !!session.capabilities.supportsStepBack : false); - this.restartFrameSupportedContextKey.set(session ? !!session.capabilities.supportsRestartFrame : false); - this.stepIntoTargetsSupported.set(session ? !!session.capabilities.supportsStepInTargetsRequest : false); - this.jumpToCursorSupported.set(session ? !!session.capabilities.supportsGotoTargetsRequest : false); - const attach = !!session && isSessionAttach(session); - this.focusedSessionIsAttach.set(attach); + this.contextKeyService.bufferChangeEvents(() => { + this.loadedScriptsSupportedContextKey.set(session ? !!session.capabilities.supportsLoadedSourcesRequest : false); + this.stepBackSupportedContextKey.set(session ? !!session.capabilities.supportsStepBack : false); + this.restartFrameSupportedContextKey.set(session ? !!session.capabilities.supportsRestartFrame : false); + this.stepIntoTargetsSupported.set(session ? !!session.capabilities.supportsStepInTargetsRequest : false); + this.jumpToCursorSupported.set(session ? !!session.capabilities.supportsGotoTargetsRequest : false); + const attach = !!session && isSessionAttach(session); + this.focusedSessionIsAttach.set(attach); + }); if (shouldEmitForSession) { this._onDidFocusSession.fire(session);