Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(breakpoints): Breakpoints could get overwritten when multiple TS files map to a single JS file. #285

Merged
merged 3 commits into from
Jan 28, 2025

Conversation

chmeyer-ms
Copy link
Contributor

Maintain a map of source breakpoints per file. VSCode's setBreakpointRequest is triggered per file whenever breakpoints are added or removed. Since it does not provide all breakpoints for all files, we need to maintain our own record of every breakpoint for every file. This way, we have all inputs available when constructing the complete list of BPs for a given generated file.

@chmeyer-ms chmeyer-ms self-assigned this Jan 28, 2025
Copy link

@frgarc frgarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing it 😄

src/session.ts Outdated
for (let originalBreakpoint of originalBreakpoints) {
const generatedPosition = await this._sourceMaps.getGeneratedPositionFor({
source: originalLocalAbsolutePath,
column: originalBreakpoint.column || 0,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using null coalescing operator should be better:

Suggested change
column: originalBreakpoint.column || 0,
column: originalBreakpoint.column ?? 0,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip. Looks like I have this in a LOT of places.

src/session.ts Outdated
line: originalBreakpoint.line,
});
generatedBreakpoints.push({
line: generatedPosition.line || 0,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Suggested change
line: generatedPosition.line || 0,
line: generatedPosition.line ?? 0,

@chmeyer-ms chmeyer-ms merged commit a7e542f into main Jan 28, 2025
2 checks passed
@chmeyer-ms chmeyer-ms deleted the chmeyer/fix_bps branch January 28, 2025 16:39
@@ -131,6 +131,7 @@ export class Session extends DebugSession {
private _sourceFileWatcher?: FileSystemWatcher;
private _activeThreadId: number = 0; // the one being debugged
private _localRoot: string = '';
private _sourceBreakpointsMap: Map<string, DebugProtocol.SourceBreakpoint[] | undefined> = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be simpler in usage if the value is just DebugProtocol.SourceBreakpoint[] without the undefined. Just each time you set it, like on line 353, do this._sourceBreakpointsMap.set(args.source.path, args.breakpoints ?? []); to handle the undefined input case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants