-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[incrParse] Fix bug mapping a node's location back to its location in the cached syntax tree #19782
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
Changes from 1 commit
5c568af
63becb5
9d9bb53
d6fc080
8baba29
0152e23
efa2c54
9003d83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ llvm::Optional<Syntax> SyntaxParsingCache::lookUp(size_t NewPosition, | |
size_t OldPosition = NewPosition; | ||
for (auto I = Edits.rbegin(), E = Edits.rend(); I != E; ++I) { | ||
auto Edit = *I; | ||
if (Edit.End <= OldPosition) { | ||
if (Edit.End < OldPosition) { | ||
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. After some more consideration this should be if (Edit.End + Edit.ReplacementLength - Edit.originalLength() <= OldPosition) { ExplanationWith Original text: The edit range is 1-4 with original length 3 and replacement length 2. The issue is that we are comparing 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. Ah, you're right! Ok, so this should make it correct for a single edit, but if there are multiple I think we'll need to account for the original-vs-replacement length differences of any edits earlier in the file too. I'll give that a go and update shortly. |
||
OldPosition = | ||
OldPosition - Edit.ReplacementLength + Edit.originalLength(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"id": 39, | ||
"kind": "SourceFile", | ||
"layout": [ | ||
{ | ||
"id": 38, | ||
"kind": "CodeBlockItemList", | ||
"layout": [ | ||
{ | ||
"id": 13, | ||
"omitted": true | ||
}, | ||
{ | ||
"id": 35, | ||
"kind": "CodeBlockItem", | ||
"layout": [ | ||
{ | ||
"id": 34, | ||
"kind": "SequenceExpr", | ||
"layout": [ | ||
{ | ||
"id": 33, | ||
"kind": "ExprList", | ||
"layout": [ | ||
{ | ||
"id": 28, | ||
"kind": "DiscardAssignmentExpr", | ||
"layout": [ | ||
{ | ||
"id": 27, | ||
"tokenKind": { | ||
"kind": "kw__" | ||
}, | ||
"leadingTrivia": [ | ||
{ | ||
"kind": "Newline", | ||
"value": 1 | ||
} | ||
], | ||
"trailingTrivia": [ | ||
{ | ||
"kind": "Space", | ||
"value": 1 | ||
} | ||
], | ||
"presence": "Present" | ||
} | ||
], | ||
"presence": "Present" | ||
}, | ||
{ | ||
"id": 30, | ||
"kind": "AssignmentExpr", | ||
"layout": [ | ||
{ | ||
"id": 29, | ||
"tokenKind": { | ||
"kind": "equal" | ||
}, | ||
"leadingTrivia": [], | ||
"trailingTrivia": [ | ||
{ | ||
"kind": "Space", | ||
"value": 1 | ||
} | ||
], | ||
"presence": "Present" | ||
} | ||
], | ||
"presence": "Present" | ||
}, | ||
{ | ||
"id": 32, | ||
"kind": "IdentifierExpr", | ||
"layout": [ | ||
{ | ||
"id": 31, | ||
"tokenKind": { | ||
"kind": "identifier", | ||
"text": "xx" | ||
}, | ||
"leadingTrivia": [], | ||
"trailingTrivia": [], | ||
"presence": "Present" | ||
}, | ||
null | ||
], | ||
"presence": "Present" | ||
} | ||
], | ||
"presence": "Present" | ||
} | ||
], | ||
"presence": "Present" | ||
}, | ||
null, | ||
null | ||
], | ||
"presence": "Present" | ||
} | ||
], | ||
"presence": "Present" | ||
}, | ||
{ | ||
"id": 37, | ||
"tokenKind": { | ||
"kind": "eof", | ||
"text": "" | ||
}, | ||
"leadingTrivia": [], | ||
"trailingTrivia": [], | ||
"presence": "Present" | ||
} | ||
], | ||
"presence": "Present" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// RUN: %incr-transfer-tree --expected-incremental-syntax-tree %S/Outputs/extend-identifier-at-eof.json %s | ||
|
||
func foo() {} | ||
_ = x<<<|||x>>> | ||
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. I would add comment to this file explaining that no trailing newline should be added to the end of it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,16 @@ | |
// RUN: %validate-incrparse %s --test-case LAST_CHARACTER_OF_STRUCT | ||
// RUN: %validate-incrparse %s --test-case ADD_ARRAY_CLOSE_BRACKET | ||
// RUN: %validate-incrparse %s --test-case ADD_IF_OPEN_BRACE | ||
// RUN: %validate-incrparse %s --test-case EXTEND_IDENTIFIER | ||
|
||
func start() {} | ||
|
||
<reparse REPLACE> | ||
func foo() { | ||
} | ||
|
||
_ = <<REPLACE<6|||7>>></reparse REPLACE> | ||
_ = <<REPLACE_BY_LONGER<6|||"Hello World">>> | ||
_ = <<REPLACE<6|||7>>> | ||
_ = </reparse REPLACE><<REPLACE_BY_LONGER<6|||"Hello World">>> | ||
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. Putting the Investigating further, I noticed that we need to remove the |
||
_ = <<REPLACE_BY_SHORTER<"Hello again"|||"a">>> | ||
<<INSERT<|||foo()>>> | ||
<<REMOVE<print("abc")|||>>> | ||
|
@@ -52,3 +53,5 @@ var computedVar: [Int] { | |
if true <<ADD_IF_OPEN_BRACE<|||{>>> | ||
_ = 5 | ||
} | ||
|
||
let y<<EXTEND_IDENTIFIER<|||ou>>> = 42 |
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.
Good catch!