From 24508d4688757b4187f31a92faf5fd756987f87c Mon Sep 17 00:00:00 2001 From: Annenkov_V Date: Wed, 24 Aug 2022 18:36:10 +0300 Subject: [PATCH 1/2] Fix debugger breakpoints --- packages/debug/src/browser/debug-session.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/debug/src/browser/debug-session.tsx b/packages/debug/src/browser/debug-session.tsx index b81cbb8c415f9..04641d5221624 100644 --- a/packages/debug/src/browser/debug-session.tsx +++ b/packages/debug/src/browser/debug-session.tsx @@ -53,6 +53,9 @@ export enum DebugState { // FIXME: make injectable to allow easily inject services export class DebugSession implements CompositeTreeElement { + private onCapabilitiesConfiguredEmitter = new Emitter(); + private readonly onCapabilitiesConfigured = this.onCapabilitiesConfiguredEmitter.event; + protected readonly onDidChangeEmitter = new Emitter(); readonly onDidChange: Event = this.onDidChangeEmitter.event; protected fireDidChange(): void { @@ -507,6 +510,18 @@ export class DebugSession implements CompositeTreeElement { protected updateCapabilities(capabilities: DebugProtocol.Capabilities): void { Object.assign(this._capabilities, capabilities); + this.onCapabilitiesConfiguredEmitter.fire(undefined); + } + + private waitUntilCapabilitiesConfigured(): Promise { + return new Promise((resolve, reject) => { + if (Object.keys(this._capabilities).length !== 0) { + resolve(); + } + + this.onCapabilitiesConfigured(resolve); + setTimeout(reject, 300); + }); } protected readonly _breakpoints = new Map(); @@ -634,6 +649,7 @@ export class DebugSession implements CompositeTreeElement { return; } const { uri, sourceModified } = options; + await this.waitUntilCapabilitiesConfigured(); for (const affectedUri of this.getAffectedUris(uri)) { if (affectedUri.toString() === BreakpointManager.EXCEPTION_URI.toString()) { await this.sendExceptionBreakpoints(); From 8a72266a7bf2b765db16f76ccc647d731fad02ed Mon Sep 17 00:00:00 2001 From: Annenkov_V Date: Wed, 7 Sep 2022 17:07:10 +0300 Subject: [PATCH 2/2] Replace Emitter with Deferred class --- packages/debug/src/browser/debug-session.tsx | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/packages/debug/src/browser/debug-session.tsx b/packages/debug/src/browser/debug-session.tsx index 04641d5221624..53aa5e566329c 100644 --- a/packages/debug/src/browser/debug-session.tsx +++ b/packages/debug/src/browser/debug-session.tsx @@ -40,7 +40,7 @@ import { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/brows import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; import { DebugContribution } from './debug-contribution'; -import { waitForEvent } from '@theia/core/lib/common/promise-util'; +import { Deferred, waitForEvent } from '@theia/core/lib/common/promise-util'; import { WorkspaceService } from '@theia/workspace/lib/browser'; import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint'; @@ -53,8 +53,7 @@ export enum DebugState { // FIXME: make injectable to allow easily inject services export class DebugSession implements CompositeTreeElement { - private onCapabilitiesConfiguredEmitter = new Emitter(); - private readonly onCapabilitiesConfigured = this.onCapabilitiesConfiguredEmitter.event; + protected readonly deferredOnDidConfigureCapabilities = new Deferred(); protected readonly onDidChangeEmitter = new Emitter(); readonly onDidChange: Event = this.onDidChangeEmitter.event; @@ -510,18 +509,7 @@ export class DebugSession implements CompositeTreeElement { protected updateCapabilities(capabilities: DebugProtocol.Capabilities): void { Object.assign(this._capabilities, capabilities); - this.onCapabilitiesConfiguredEmitter.fire(undefined); - } - - private waitUntilCapabilitiesConfigured(): Promise { - return new Promise((resolve, reject) => { - if (Object.keys(this._capabilities).length !== 0) { - resolve(); - } - - this.onCapabilitiesConfigured(resolve); - setTimeout(reject, 300); - }); + this.deferredOnDidConfigureCapabilities.resolve(); } protected readonly _breakpoints = new Map(); @@ -649,7 +637,7 @@ export class DebugSession implements CompositeTreeElement { return; } const { uri, sourceModified } = options; - await this.waitUntilCapabilitiesConfigured(); + await this.deferredOnDidConfigureCapabilities.promise; for (const affectedUri of this.getAffectedUris(uri)) { if (affectedUri.toString() === BreakpointManager.EXCEPTION_URI.toString()) { await this.sendExceptionBreakpoints();