-
Notifications
You must be signed in to change notification settings - Fork 750
4369-[Previews] some lines are incorrectly marked as out of scope #4381
4369-[Previews] some lines are incorrectly marked as out of scope #4381
Conversation
| // We do the same check as the startsBefore case for the endsAfter case. | ||
| endsAfter = | ||
| a.end.column >= 0 && b.column >= 0 ? a.end.column >= b.column : true; | ||
| } |
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.
@jasonLaster Thanks for the gist hint.
Before proceeding to the test, would like to check with you if this solution is the right direction since this touches the util function. Below is my analysis, please have a look, thank you:
While getting out-of-scope locations, it uses the parsed source locations and the bp position to filter out those not contained within scope [1]
The bp position only has the line criterion [2] and the source locations have one location as [3].
During filtering, the containsPosition doesn’t consider the case without the column criterion.
As a result [4]
// This evaluates to false although a.start.line === b.line === 46,
// because a.start.column <= b.column is false (b.column === undefined)
startsBefore = (a.start.line === b.line && a.start.column <= b.column); then the line 46 where the bp exists is judged as out of scope.
So the solution is to take the case without column criterion into consideration.
[2] Object { sourceId: "server1.conn26.child2/source32", line: 46 }
[3] {
end: Object { line: 48, column: 3 }
start: Object { line: 46, column: 30 }
}
|
Thanks @Fischer-L This looks really good! I think it will help document the fix if you could add some unit tests.
|
ff580f4 to
001e9eb
Compare
|
@jasonLaster The test is added. Please have a look thanks. |
|
@Fischer-L looks like there are some small test issues |
jasonLaster
left a comment
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.
Great job!
src/workers/parser/utils/contains.js
Outdated
| // If the start line is equal to the target line | ||
| // and there is no column criterion, we judge it as true. | ||
| // Otherwise we have to check if the start column is really before the target colimn. | ||
| startsBefore = |
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.
perhaps we need two smaller functions:
function startsBefore(a, b) {
if (!(a.start.column > 0 && b.column)) {
return true
}
return a.start.column <= b.column;
}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.
Definitely, will update
e2e2160 to
e1de587
Compare
src/workers/parser/utils/contains.js
Outdated
| let endsAfter = a.end.line > b.line; | ||
| if (!endsAfter && a.end.line === b.line) { | ||
| endsAfter = endsAfterColumn(a, b); | ||
| } |
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.
@jasonLaster I was thinking the following as well (but seems not really different from the current one):
function startsBefore(a: AstLocation, b: AstPosition) {
let startsBefore = a.start.line < b.line;
if (a.start.line === b.line && a.start.column && b.column) {
startsBefore = a.start.column <= b.column;
}
return startsBefore;
}
function endsAfter(a: AstLocation, b: AstPosition) {
// The similar codes as startsBefore
}
export function containsPosition(a: AstLocation, b: AstPosition) {
return startsBefore(a, b) && endsAfter(a, b);
}Please let me know which is better you think, thanks
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.
I like it better :)
function startsBefore(a: AstLocation, b: AstPosition) {
if (a.start.line === b.line && a.start.column && b.column) {
return a.start.column <= b.column;
}
return a.start.line < b.line;
}it's easier for me to read
|
I think this is not fully accurate. In the example above line 47 is actually out of scope. With this code it is considered in scope, so when you hover over |
I would say Line 47 is in scope and See another case:
Consider another case function doA(n) {
let result = doSomeJob({ id: n + 1 }); // Set a bp A here
return result;
}
function doB(n) {
let result = doSomeJob( // Set a bp B here
{ id: n + 1 }
);
return result;
}
|
e1de587 to
7c15683
Compare
|
@jasonLaster Updated to use the 2nd approach. Please look thank you |
|
@jasonLaster and @amitzur For the whole issue, there are 2 aspects to consider:
|
Correct myself: Precisely speaking |
|
@Fischer-L could you fix up the tests so we can land this fix. 👍 |
7c15683 to
9668043
Compare
src/actions/tests/sources.spec.js
Outdated
|
|
||
| const locations = getOutOfScopeLocations(getState()); | ||
| expect(locations.length).toEqual(1); | ||
| expect(locations.length).toEqual(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.
This tests loads a fake "foo1" source, which is [1] and set a bp at Line 1. Originally it judged this was out of scope but that contradicts what we wanna fix in this bug. In this bug this case in fact should be ruled as in-scope, otherwise the similar case [2] would be out of scope too, so update the expected test result.
[1] "function foo1() {\n return 5;\n}": https://github.com/devtools-html/debugger.html/blob/9a2977bdb5bbb3a85effd63a315d716d9656fda3/src/actions/tests/helpers/threadClient.js#L71
[2]
let obj = { bar: "bar", foo: function foo1() { return 5; } };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.
No longer have to update sources.spec.js test because it has been modified by PR #4143 to include the column criterion.
| let startsBefore = a.start.line < b.line; | ||
| if (a.start.line === b.line) { | ||
| startsBefore = | ||
| a.start.column >= 0 && b.column >= 0 ? a.start.column <= b.column : true; |
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.
The getOutOfScopeLocations.spec.js test shows "0"[1] matters so >= 0 is required.
Definitely, updated. |
|
@Fischer-L still seeing some errors |
9668043 to
e81763b
Compare
Sorry. This was embarrassing, didn't notice some eslint error out there... Fixed |
|
@jasonLaster The tests are fine. Please have a look, thanks |
451a47a to
2a401ce
Compare
|
Hey @Fischer-L I pushed some opinionated test refactorings. The goal was to make them more readable from the outside, ideally show all the permutations in code as well as the overview. Let me know what you think. By the way, the tests really are great :) thanks for the coverage. Tests 💃 |
da7fdd0 to
f57e1f5
Compare
f57e1f5 to
84dca80
Compare
|
@jasonLaster Thank you for the update. Looks nice. |
|
|
||
| describe("containsPosition", () => { | ||
| describe("location and postion both with the column criteria", () => { | ||
| it("should contain position within the location range", () => |
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.
Was prettier moving the test description up again? I didn't touch the line break...
Only made testContains(startPos(-1, 0), false)) wrapped inside the arrow function.
| it("should not contain position out of the end column", () => | ||
| testContains(endPos(0, 1), false)); | ||
|
|
||
| it("should contain position on the same end line and within the end column", () => |
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.
@jasonLaster the eslint complains about a over-80-length line but looks like it was prettier which formatted this line...
|
hmm, yeah... i'll see what we can do about that :) |
84dca80 to
397ea02
Compare



Associated Issue: #4369
Screenshots/Videos