-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
…files map to a single JS file.
There was a problem hiding this 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, |
There was a problem hiding this comment.
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:
column: originalBreakpoint.column || 0, | |
column: originalBreakpoint.column ?? 0, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
line: generatedPosition.line || 0, | |
line: generatedPosition.line ?? 0, |
@@ -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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good call.
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.