Skip to content
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

Merged
merged 1 commit into from
May 26, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Drops the cost here to practically nothing:

image

This is around a goal of getting all tagging work as low as possible.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 26, 2024 08:03
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 26, 2024
var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
var trivia = root.FindTrivia(position);
Copy link
Member Author

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

Copy link
Contributor

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?

Copy link
Member Author

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:

  1. Nodes (the directive trivia, its expressions etc)
  2. tokens 9the #, if and false tokens
  3. 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?

@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal

if (position < token.SpanStart)
return FindBraces(token.LeadingTrivia);
else if (position >= token.Span.End)
return FindBraces(token.TrailingTrivia);

return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return null;

this should never hit, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. this was paranoia.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants