Skip to content

Commit f252eb3

Browse files
committed
debug: contextKeyService.bufferChangeEvents
microsoft#101268
1 parent f690f66 commit f252eb3

2 files changed

Lines changed: 49 additions & 41 deletions

File tree

src/vs/workbench/contrib/debug/browser/debugService.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ export class DebugService implements IDebugService {
6161
private taskRunner: DebugTaskRunner;
6262
private configurationManager: ConfigurationManager;
6363
private toDispose: IDisposable[];
64-
private debugType: IContextKey<string>;
65-
private debugState: IContextKey<string>;
66-
private inDebugMode: IContextKey<boolean>;
67-
private debugUx: IContextKey<string>;
68-
private breakpointsExist: IContextKey<boolean>;
64+
private debugType!: IContextKey<string>;
65+
private debugState!: IContextKey<string>;
66+
private inDebugMode!: IContextKey<boolean>;
67+
private debugUx!: IContextKey<string>;
68+
private breakpointsExist!: IContextKey<boolean>;
6969
private breakpointsToSendOnResourceSaved: Set<string>;
7070
private initializing = false;
7171
private previousState: State | undefined;
@@ -80,7 +80,7 @@ export class DebugService implements IDebugService {
8080
@IDialogService private readonly dialogService: IDialogService,
8181
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
8282
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
83-
@IContextKeyService contextKeyService: IContextKeyService,
83+
@IContextKeyService private readonly contextKeyService: IContextKeyService,
8484
@ILifecycleService private readonly lifecycleService: ILifecycleService,
8585
@IInstantiationService private readonly instantiationService: IInstantiationService,
8686
@IExtensionService private readonly extensionService: IExtensionService,
@@ -101,17 +101,19 @@ export class DebugService implements IDebugService {
101101
this.configurationManager = this.instantiationService.createInstance(ConfigurationManager);
102102
this.toDispose.push(this.configurationManager);
103103

104-
this.debugType = CONTEXT_DEBUG_TYPE.bindTo(contextKeyService);
105-
this.debugState = CONTEXT_DEBUG_STATE.bindTo(contextKeyService);
106-
this.inDebugMode = CONTEXT_IN_DEBUG_MODE.bindTo(contextKeyService);
107-
this.debugUx = CONTEXT_DEBUG_UX.bindTo(contextKeyService);
108-
this.debugUx.set(!!this.configurationManager.selectedConfiguration.name ? 'default' : 'simple');
104+
contextKeyService.bufferChangeEvents(() => {
105+
this.debugType = CONTEXT_DEBUG_TYPE.bindTo(contextKeyService);
106+
this.debugState = CONTEXT_DEBUG_STATE.bindTo(contextKeyService);
107+
this.inDebugMode = CONTEXT_IN_DEBUG_MODE.bindTo(contextKeyService);
108+
this.debugUx = CONTEXT_DEBUG_UX.bindTo(contextKeyService);
109+
this.debugUx.set(!!this.configurationManager.selectedConfiguration.name ? 'default' : 'simple');
110+
this.breakpointsExist = CONTEXT_BREAKPOINTS_EXIST.bindTo(contextKeyService);
111+
});
109112

110113
this.debugStorage = this.instantiationService.createInstance(DebugStorage);
111114
this.model = this.instantiationService.createInstance(DebugModel, this.debugStorage);
112115
this.telemetry = this.instantiationService.createInstance(DebugTelemetry, this.model);
113116
const setBreakpointsExistContext = () => this.breakpointsExist.set(!!(this.model.getBreakpoints().length || this.model.getDataBreakpoints().length || this.model.getFunctionBreakpoints().length));
114-
this.breakpointsExist = CONTEXT_BREAKPOINTS_EXIST.bindTo(contextKeyService);
115117
setBreakpointsExistContext();
116118

117119
this.viewModel = new ViewModel(contextKeyService);
@@ -229,10 +231,12 @@ export class DebugService implements IDebugService {
229231
private onStateChange(): void {
230232
const state = this.state;
231233
if (this.previousState !== state) {
232-
this.debugState.set(getStateLabel(state));
233-
this.inDebugMode.set(state !== State.Inactive);
234-
// Only show the simple ux if debug is not yet started and if no launch.json exists
235-
this.debugUx.set(((state !== State.Inactive && state !== State.Initializing) || this.configurationManager.selectedConfiguration.name) ? 'default' : 'simple');
234+
this.contextKeyService.bufferChangeEvents(() => {
235+
this.debugState.set(getStateLabel(state));
236+
this.inDebugMode.set(state !== State.Inactive);
237+
// Only show the simple ux if debug is not yet started and if no launch.json exists
238+
this.debugUx.set(((state !== State.Inactive && state !== State.Initializing) || this.configurationManager.selectedConfiguration.name) ? 'default' : 'simple');
239+
});
236240
this.previousState = state;
237241
this._onDidChangeState.fire(state);
238242
}

src/vs/workbench/contrib/debug/common/debugViewModel.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@ export class ViewModel implements IViewModel {
2121
private readonly _onDidFocusStackFrame = new Emitter<{ stackFrame: IStackFrame | undefined, explicit: boolean }>();
2222
private readonly _onDidSelectExpression = new Emitter<IExpression | undefined>();
2323
private multiSessionView: boolean;
24-
private expressionSelectedContextKey: IContextKey<boolean>;
25-
private breakpointSelectedContextKey: IContextKey<boolean>;
26-
private loadedScriptsSupportedContextKey: IContextKey<boolean>;
27-
private stepBackSupportedContextKey: IContextKey<boolean>;
28-
private focusedSessionIsAttach: IContextKey<boolean>;
29-
private restartFrameSupportedContextKey: IContextKey<boolean>;
30-
private stepIntoTargetsSupported: IContextKey<boolean>;
31-
private jumpToCursorSupported: IContextKey<boolean>;
32-
33-
constructor(contextKeyService: IContextKeyService) {
24+
private expressionSelectedContextKey!: IContextKey<boolean>;
25+
private breakpointSelectedContextKey!: IContextKey<boolean>;
26+
private loadedScriptsSupportedContextKey!: IContextKey<boolean>;
27+
private stepBackSupportedContextKey!: IContextKey<boolean>;
28+
private focusedSessionIsAttach!: IContextKey<boolean>;
29+
private restartFrameSupportedContextKey!: IContextKey<boolean>;
30+
private stepIntoTargetsSupported!: IContextKey<boolean>;
31+
private jumpToCursorSupported!: IContextKey<boolean>;
32+
33+
constructor(private contextKeyService: IContextKeyService) {
3434
this.multiSessionView = false;
35-
this.expressionSelectedContextKey = CONTEXT_EXPRESSION_SELECTED.bindTo(contextKeyService);
36-
this.breakpointSelectedContextKey = CONTEXT_BREAKPOINT_SELECTED.bindTo(contextKeyService);
37-
this.loadedScriptsSupportedContextKey = CONTEXT_LOADED_SCRIPTS_SUPPORTED.bindTo(contextKeyService);
38-
this.stepBackSupportedContextKey = CONTEXT_STEP_BACK_SUPPORTED.bindTo(contextKeyService);
39-
this.focusedSessionIsAttach = CONTEXT_FOCUSED_SESSION_IS_ATTACH.bindTo(contextKeyService);
40-
this.restartFrameSupportedContextKey = CONTEXT_RESTART_FRAME_SUPPORTED.bindTo(contextKeyService);
41-
this.stepIntoTargetsSupported = CONTEXT_STEP_INTO_TARGETS_SUPPORTED.bindTo(contextKeyService);
42-
this.jumpToCursorSupported = CONTEXT_JUMP_TO_CURSOR_SUPPORTED.bindTo(contextKeyService);
35+
contextKeyService.bufferChangeEvents(() => {
36+
this.expressionSelectedContextKey = CONTEXT_EXPRESSION_SELECTED.bindTo(contextKeyService);
37+
this.breakpointSelectedContextKey = CONTEXT_BREAKPOINT_SELECTED.bindTo(contextKeyService);
38+
this.loadedScriptsSupportedContextKey = CONTEXT_LOADED_SCRIPTS_SUPPORTED.bindTo(contextKeyService);
39+
this.stepBackSupportedContextKey = CONTEXT_STEP_BACK_SUPPORTED.bindTo(contextKeyService);
40+
this.focusedSessionIsAttach = CONTEXT_FOCUSED_SESSION_IS_ATTACH.bindTo(contextKeyService);
41+
this.restartFrameSupportedContextKey = CONTEXT_RESTART_FRAME_SUPPORTED.bindTo(contextKeyService);
42+
this.stepIntoTargetsSupported = CONTEXT_STEP_INTO_TARGETS_SUPPORTED.bindTo(contextKeyService);
43+
this.jumpToCursorSupported = CONTEXT_JUMP_TO_CURSOR_SUPPORTED.bindTo(contextKeyService);
44+
});
4345
}
4446

4547
getId(): string {
@@ -66,13 +68,15 @@ export class ViewModel implements IViewModel {
6668
this._focusedThread = thread;
6769
this._focusedSession = session;
6870

69-
this.loadedScriptsSupportedContextKey.set(session ? !!session.capabilities.supportsLoadedSourcesRequest : false);
70-
this.stepBackSupportedContextKey.set(session ? !!session.capabilities.supportsStepBack : false);
71-
this.restartFrameSupportedContextKey.set(session ? !!session.capabilities.supportsRestartFrame : false);
72-
this.stepIntoTargetsSupported.set(session ? !!session.capabilities.supportsStepInTargetsRequest : false);
73-
this.jumpToCursorSupported.set(session ? !!session.capabilities.supportsGotoTargetsRequest : false);
74-
const attach = !!session && isSessionAttach(session);
75-
this.focusedSessionIsAttach.set(attach);
71+
this.contextKeyService.bufferChangeEvents(() => {
72+
this.loadedScriptsSupportedContextKey.set(session ? !!session.capabilities.supportsLoadedSourcesRequest : false);
73+
this.stepBackSupportedContextKey.set(session ? !!session.capabilities.supportsStepBack : false);
74+
this.restartFrameSupportedContextKey.set(session ? !!session.capabilities.supportsRestartFrame : false);
75+
this.stepIntoTargetsSupported.set(session ? !!session.capabilities.supportsStepInTargetsRequest : false);
76+
this.jumpToCursorSupported.set(session ? !!session.capabilities.supportsGotoTargetsRequest : false);
77+
const attach = !!session && isSessionAttach(session);
78+
this.focusedSessionIsAttach.set(attach);
79+
});
7680

7781
if (shouldEmitForSession) {
7882
this._onDidFocusSession.fire(session);

0 commit comments

Comments
 (0)