-
Notifications
You must be signed in to change notification settings - Fork 42
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 misaligned lines in debugger #634
Merged
kmagiera
merged 12 commits into
main
from
@Filip131311/FixDebuggerMissalinedLinesOnExpoProjects
Oct 22, 2024
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d72d67
init
filip131311 c64d42b
init
filip131311 e2cbc1d
changes after CR
filip131311 900205f
changes after CR
filip131311 1912a1e
changes after CR
filip131311 8c309a1
changes after CR
filip131311 4f37c39
changes after CR
filip131311 e590d62
move to passing informatoion througsh metro
filip131311 d5b61ea
Update packages/vscode-extension/src/debugging/DebugAdapter.ts
kmagiera fb61f3c
Update packages/vscode-extension/src/debugging/DebugAdapter.ts
kmagiera d28b796
Small adjustments of the code and conditions
kmagiera 7ecfcb5
Make sure we log expo prelude message when there's some offset we apply
kmagiera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
Source, | ||
StackFrame, | ||
} from "@vscode/debugadapter"; | ||
import { getReactNativeVersion } from "../utilities/reactNative"; | ||
import semver from "semver"; | ||
import { DebugProtocol } from "@vscode/debugprotocol"; | ||
import WebSocket from "ws"; | ||
import { NullablePosition, SourceMapConsumer } from "source-map"; | ||
|
@@ -83,8 +85,8 @@ | |
private absoluteProjectPath: string; | ||
private projectPathAlias?: string; | ||
private threads: Array<Thread> = []; | ||
private sourceMaps: Array<[string, string, SourceMapConsumer]> = []; | ||
|
||
private sourceMaps: Array<[string, string, SourceMapConsumer, number]> = []; | ||
private lineOffset: number; | ||
private linesStartAt1 = true; | ||
private columnsStartAt1 = true; | ||
|
||
|
@@ -96,6 +98,7 @@ | |
this.absoluteProjectPath = configuration.absoluteProjectPath; | ||
this.projectPathAlias = configuration.projectPathAlias; | ||
this.connection = new WebSocket(configuration.websocketAddress); | ||
this.lineOffset = configuration.lineOffset; | ||
|
||
this.connection.on("open", () => { | ||
// the below catch handler is used to ignore errors coming from non critical CDP messages we | ||
|
@@ -150,7 +153,31 @@ | |
const decodedData = Buffer.from(base64Data, "base64").toString("utf-8"); | ||
const sourceMap = JSON.parse(decodedData); | ||
const consumer = await new SourceMapConsumer(sourceMap); | ||
this.sourceMaps.push([message.params.url, message.params.scriptId, consumer]); | ||
|
||
// This is a heuristic that checks if the source map should contain __env__ | ||
// module that is added by expo, but not reported in the source map | ||
kmagiera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const isFileWithOffset = sourceMap.sources.includes("__prelude__"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename |
||
|
||
// This line is here because of a problem with sourcemaps for expo projects, | ||
// that was addressed in this PR https://github.com/expo/expo/pull/29463, | ||
// unfortunately it still requires changes to metro that were attempted here | ||
// https://github.com/facebook/metro/pull/1284 we should monitor the situation | ||
// in upcoming versions and if the changes are still not added bump the version below. | ||
kmagiera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const shouldApplyOffset = | ||
kmagiera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
semver.lte(getReactNativeVersion(), "0.76.0") && isFileWithOffset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we check for expo version here and not react native? |
||
if (this.lineOffset !== 0 && shouldApplyOffset) { | ||
Logger.debug( | ||
"Expo prelude lines were detected and an offset was set to:", | ||
this.lineOffset | ||
); | ||
} | ||
|
||
this.sourceMaps.push([ | ||
message.params.url, | ||
message.params.scriptId, | ||
consumer, | ||
shouldApplyOffset ? this.lineOffset : 0, | ||
kmagiera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]); | ||
this.updateBreakpointsInSource(message.params.url, consumer); | ||
} | ||
|
||
|
@@ -264,7 +291,7 @@ | |
let sourceLine1Based = lineNumber1Based; | ||
let sourceColumn0Based = columnNumber0Based; | ||
|
||
this.sourceMaps.forEach(([url, id, consumer]) => { | ||
this.sourceMaps.forEach(([url, id, consumer, lineOffset]) => { | ||
// when we identify script by its URL we need to deal with a situation when the URL is sent with a different | ||
// hostname and port than the one we have registered in the source maps. The reason for that is that the request | ||
// that populates the source map (scriptParsed) is sent by metro, while the requests from breakpoints or logs | ||
|
@@ -273,16 +300,16 @@ | |
if (id === scriptIdOrURL || compareIgnoringHost(url, scriptIdOrURL)) { | ||
scriptURL = url; | ||
const pos = consumer.originalPositionFor({ | ||
line: lineNumber1Based, | ||
line: lineNumber1Based - lineOffset, | ||
column: columnNumber0Based, | ||
}); | ||
if (pos.source != null) { | ||
sourceURL = pos.source; | ||
} | ||
if (pos.line != null) { | ||
sourceLine1Based = pos.line; | ||
} | ||
if (pos.column != null) { | ||
sourceColumn0Based = pos.column; | ||
} | ||
} | ||
|
@@ -440,7 +467,7 @@ | |
} | ||
let position: NullablePosition = { line: null, column: null, lastColumn: null }; | ||
let originalSourceURL: string = ""; | ||
this.sourceMaps.forEach(([sourceURL, scriptId, consumer]) => { | ||
this.sourceMaps.forEach(([sourceURL, scriptId, consumer, lineOffset]) => { | ||
const sources = []; | ||
consumer.eachMapping((mapping) => { | ||
sources.push(mapping.source); | ||
|
@@ -451,9 +478,9 @@ | |
column: columnNumber0Based, | ||
bias: SourceMapConsumer.LEAST_UPPER_BOUND, | ||
}); | ||
if (pos.line != null) { | ||
originalSourceURL = sourceURL; | ||
position = pos; | ||
position = { ...pos, line: pos.line + lineOffset }; | ||
} | ||
}); | ||
if (position.line === null) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This parameter should really be called
expoPreludeExtraLines
or something along these lines instead of being so generic