Skip to content

Commit 14323d3

Browse files
authored
fix: ensure that the debugAdapter's _onInitialize() is called (#1010)
When launching a `pwa-node` process, the debugAdapter's _onInitialize() method is never called, since the dap registers a listener for the `'initialize'` message _after_ it has arrived. This causes the Thread's `dap` to never be resolved, so any thread events (e.g. `'paused'`) are never sent to the client! This in turn causes VSCode to never realize that the process is stopped, so the debuggee just waits there, patiently, forever. This change stores the `Dap.InitializeParams` on the Binder and then when the Thread is created, the params are forwarded so that the DebugAdapter can _onInitialize() correctly and the thread-related events can flow.
1 parent d1ab2b4 commit 14323d3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/adapter/debugAdapter.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ export class DebugAdapter implements IDisposable {
303303
return errors.createSilentError(localize('error.threadNotFound', 'Thread not found'));
304304
}
305305

306-
createThread(cdp: Cdp.Api, delegate: IThreadDelegate): Thread {
306+
createThread(
307+
cdp: Cdp.Api,
308+
delegate: IThreadDelegate,
309+
initializeParams?: Dap.InitializeParams,
310+
): Thread {
307311
this._thread = new Thread(
308312
this.sourceContainer,
309313
cdp,
@@ -318,6 +322,13 @@ export class DebugAdapter implements IDisposable {
318322
this._services.get(IConsole),
319323
this._services.get(IExceptionPauseService),
320324
);
325+
if (initializeParams) {
326+
// We won't get notified of an initialize message:
327+
// that was already caught by the caller.
328+
setTimeout(() => {
329+
this._onInitialize(initializeParams);
330+
}, 0);
331+
}
321332

322333
const profile = this._services.get<IProfileController>(IProfileController);
323334
profile.connect(this.dap, this._thread);

src/binder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class Binder implements IDisposable {
5757
private _onTargetListChangedEmitter = new EventEmitter<void>();
5858
readonly onTargetListChanged = this._onTargetListChangedEmitter.event;
5959
private _dap: Promise<Dap.Api>;
60+
private _dapInitializeParams?: Dap.InitializeParams;
6061
private _targetOrigin: ITargetOrigin;
6162
private _launchParams?: AnyLaunchConfiguration;
6263
private _asyncStackPolicy?: IAsyncStackPolicy;
@@ -93,6 +94,7 @@ export class Binder implements IDisposable {
9394
if (clientCapabilities.clientID === 'vscode') {
9495
filterErrorsReportedToTelemetry();
9596
}
97+
this._dapInitializeParams = clientCapabilities;
9698

9799
setTimeout(() => {
98100
dap.initialized({});
@@ -403,7 +405,7 @@ export class Binder implements IDisposable {
403405

404406
// todo: move scriptskipper into services collection
405407
const debugAdapter = new DebugAdapter(dap, this._asyncStackPolicy, launchParams, container);
406-
const thread = debugAdapter.createThread(cdp, target);
408+
const thread = debugAdapter.createThread(cdp, target, this._dapInitializeParams);
407409

408410
const startThread = async () => {
409411
await debugAdapter.launchBlocker();

0 commit comments

Comments
 (0)