-
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
Streamline brace matcher code #73722
Conversation
var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false); | ||
var trivia = root.FindTrivia(position); |
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.
it seems like findTrivia is just not that very good. Looking at the impl, it's pretty darn complex. FindToken seems to be much simpler and much more optimized. So changing our code here to just get the token, and walk the start/end trivia of it
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've never really internalized how structured trivia works.
Nodes can have child nodes/tokens
Tokens have leading/trailing trivia
Trivia may have structure (which is a node)
Can those nodes inside the trivia repeat this cycle?
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.
Nodes can have child nodes/tokens
Tokens have leading/trailing trivia
Trivia may have structure (which is a node)
100% correct.
Can those nodes inside the trivia repeat this cycle?
No. trivia only goes one more level deep. So within a top levle trivia (like a #if false
directive trivia), you have:
- Nodes (the directive trivia, its expressions etc)
- tokens 9the
#
,if
andfalse
tokens - trivia (the whitespace between those)
However, those final trivia are never structured themselves, so it bottoms out.
We were explicit int he syntax design that no operations go from top level to strucutred trivia automatically, and you always pass the findInsideTrivia
flag to control that. And, because there's no more recursion, there's no confusion abuot which level you're diving down into. It's either the top level, or the single structured-trivia level.
Does that make sense?
@ToddGrun ptal |
if (position < token.SpanStart) | ||
return FindBraces(token.LeadingTrivia); | ||
else if (position >= token.Span.End) | ||
return FindBraces(token.TrailingTrivia); | ||
|
||
return null; |
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.
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.
yeah. this was paranoia.
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.
Drops the cost here to practically nothing:
This is around a goal of getting all tagging work as low as possible.