-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[incrParse] Skip missing node in SyntaxData::getNextNode() #19951
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 all commits
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 |
---|---|---|
|
@@ -59,7 +59,8 @@ RC<SyntaxData> SyntaxData::getPreviousNode() const { | |
if (hasParent()) { | ||
for (size_t I = N - 1; ; I--) { | ||
if (auto C = getParent()->getChild(I)) { | ||
return C; | ||
if (C->getRaw()->isPresent() && C->getFirstToken()) | ||
return C; | ||
} | ||
if (I == 0) | ||
break; | ||
|
@@ -73,27 +74,35 @@ RC<SyntaxData> SyntaxData::getNextNode() const { | |
if (hasParent()) { | ||
for (size_t I = getIndexInParent() + 1, N = Parent->getNumChildren(); | ||
I != N; I++) { | ||
if (auto C = getParent()->getChild(I)) | ||
return C; | ||
if (auto C = getParent()->getChild(I)) { | ||
if (C->getRaw()->isPresent() && C->getFirstToken()) | ||
return C; | ||
} | ||
} | ||
return Parent->getNextNode(); | ||
} | ||
return nullptr; | ||
} | ||
|
||
RC<SyntaxData> SyntaxData::getFirstToken() const { | ||
if (getRaw()->isToken()) { | ||
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. Also here, I think it's worth adding a doc comment mentioning that we return the first non-missing token. |
||
// Get a reference counted version of this | ||
assert(hasParent() && "The syntax tree should not conisist only of the root"); | ||
return getParent()->getChild(getIndexInParent()); | ||
} | ||
|
||
for (size_t I = 0, E = getNumChildren(); I < E; ++I) { | ||
if (auto Child = getChild(I)) { | ||
if (!Child->getRaw()->isMissing()) { | ||
return Child->getFirstToken(); | ||
if (Child->getRaw()->isMissing()) | ||
continue; | ||
if (Child->getRaw()->isToken()) { | ||
return Child; | ||
} else if (auto Token = Child->getFirstToken()) { | ||
return Token; | ||
} | ||
} | ||
} | ||
|
||
// Get a reference counted version of this | ||
assert(getRaw()->isToken() && "Leaf node that is no token?"); | ||
assert(hasParent() && "The syntax tree should not conisist only of the root"); | ||
return getParent()->getChild(getIndexInParent()); | ||
return nullptr; | ||
} | ||
|
||
AbsolutePosition SyntaxData::getAbsolutePositionBeforeLeadingTrivia() const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %validate-incrparse %s --test-case ADD_ELSE | ||
|
||
func container() { | ||
#if false | ||
<<ADD_ELSE<|||#else>>> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %validate-incrparse %s --test-case INSERT_SPACE | ||
|
||
class AnimationType { | ||
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. You are missing the 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. Oops... 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. Well, this change doesn't fix this test case. Sorry, I will retry fixing. |
||
func foo(x: Blah) { | ||
switch x { | ||
case (. | ||
|
||
extension AnimationType { | ||
public<<INSERT_SPACE<||| >>> |
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.
If we skip over missing nodes here, I think we should do the same in
getPreviousNode
. Also I think it's worth documenting thatgetNextNode
will return the next node that does contain a non-missing token.