Skip to content

Commit

Permalink
fix: disable entrypoint breakpoint at first pause in script (#2094)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 authored Oct 3, 2024
1 parent 868c088 commit fc778e6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/adapter/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,19 @@ export class BreakpointManager {
});
}

/**
* Disables entrypoint breakpoints set in the given script ID. This is
* needed so they don't vote to continue later
* @see https://github.com/microsoft/vscode/issues/230201
*/
public async disableEntrypointBreaks(scriptId: string) {
await Promise.all([...this.moduleEntryBreakpoints.values()].map(bp => {
if (bp.enabled && bp.cdpScriptIds.has(scriptId)) {
return bp.disable();
}
}));
}

/** Gets whether the CDP breakpoint ID refers to an entrypoint breakpoint. */
public isEntrypointCdpBreak(cdpId: string) {
const bp = this._resolvedBreakpoints.get(cdpId);
Expand Down
2 changes: 2 additions & 0 deletions src/adapter/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ export class Thread implements IVariableStoreLocationProvider {
}

const timer = new HrTime();
const disableProm = this._breakpointManager.disableEntrypointBreaks(scriptId);
const result = await Promise.race([this._getOrStartLoadingSourceMaps(script), delay(timeout)]);

const timeSpentWallClockInMs = timer.elapsed().ms;
Expand Down Expand Up @@ -1751,6 +1752,7 @@ export class Thread implements IVariableStoreLocationProvider {

console.assert(this._pausedForSourceMapScriptId === scriptId);
this._pausedForSourceMapScriptId = undefined;
await disableProm;

const bLine = brokenOn?.lineNumber || 0;
const bColumn = brokenOn?.columnNumber;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
allThreadsStopped : false
description : Paused
reason : step
threadId : <number>
}
<anonymous> @ ${fixturesDir}/test.js:5:1
25 changes: 25 additions & 0 deletions src/test/breakpoints/breakpointsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,4 +1414,29 @@ describe('breakpoints', () => {
await waitForPause(p);
p.assertLog();
});

itIntegrates('disables entrypoint breakpoint when in file (vscode#230201)', async ({ r }) => {
createFileTree(testFixturesDir, {
'test.js': `function firstfunc(arg){
return arg * arg
}
const a = firstfunc(2);
console.log('Finished awesome program');`,
});

const handle = await r.runScript('test.js', {
cwd: testFixturesDir,
});

await handle.dap.setBreakpoints({
source: { path: join(testFixturesDir, 'test.js') },
breakpoints: [{ line: 4, column: 1 }],
});

handle.load();
const { threadId } = await handle.dap.once('stopped');
await handle.dap.next({ threadId: threadId! });
await waitForPause(handle);
r.assertLog({ substring: true });
});
});

0 comments on commit fc778e6

Please # to comment.