-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use next sibling in SyntaxNode.GetChildPosition() if available #66876
Changes from 1 commit
6d82cde
86786a2
4bea78e
050f570
14c639e
95880f0
8f18f02
9e8e9ce
a98cb9a
bff2282
528a2a8
80f0ab8
724aecd
c187e3d
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 |
---|---|---|
|
@@ -611,25 +611,52 @@ internal int GetChildIndex(int slot) | |
/// efficient implementations. | ||
/// </summary> | ||
internal virtual int GetChildPosition(int index) | ||
{ | ||
return GetChildPosition(index, useNextNotPrevious: false); | ||
} | ||
|
||
internal int GetChildPosition(int index, bool useNextNotPrevious) | ||
{ | ||
int offset = 0; | ||
var green = this.Green; | ||
while (index > 0) | ||
|
||
if (!useNextNotPrevious) | ||
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. nit: flip? 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 used |
||
{ | ||
index--; | ||
var prevSibling = this.GetCachedSlot(index); | ||
if (prevSibling != null) | ||
while (index > 0) | ||
{ | ||
return prevSibling.EndPosition + offset; | ||
index--; | ||
var prevSibling = this.GetCachedSlot(index); | ||
if (prevSibling != null) | ||
{ | ||
return prevSibling.EndPosition + offset; | ||
} | ||
var greenChild = green.GetSlot(index); | ||
if (greenChild != null) | ||
{ | ||
offset += greenChild.FullWidth; | ||
} | ||
} | ||
var greenChild = green.GetSlot(index); | ||
if (greenChild != null) | ||
return this.Position + offset; | ||
} | ||
else | ||
{ | ||
int slotCount = green.SlotCount; | ||
while (index < slotCount - 1) | ||
{ | ||
offset += greenChild.FullWidth; | ||
index++; | ||
var prevSibling = this.GetCachedSlot(index); | ||
if (prevSibling != null) | ||
{ | ||
return prevSibling.EndPosition - offset; | ||
} | ||
var greenChild = green.GetSlot(index); | ||
if (greenChild != null) | ||
{ | ||
offset += greenChild.FullWidth; | ||
} | ||
} | ||
return this.EndPosition - offset; | ||
} | ||
|
||
return this.Position + offset; | ||
} | ||
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. overall, i have no issue with the approach. but i think we def need tests around ensuring that reverse iterating produces nodes/tokens in the correct location. can you add a bunch of tests that show that if we reverse iterate the positions of things are all correct? 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. Added verifying results from |
||
|
||
public Location GetLocation() | ||
|
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 legit do not understand any of this :D
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.
We decide whether to look at previous siblings or following siblings in
GetChildPosition()
by checking whether the nearest siblings are included in the_children
cache. If the nearest previous sibling is not cached, but the nearest following sibling is cached, we'll look at the following siblings; otherwise, we'll use the existing behavior of looking at the previous siblings.To check for the nearest siblings though, we need to ignore separators, because separators are not represented in the cache.