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

Brace matcher for preprocessor directives #7327

Merged
merged 8 commits into from Dec 15, 2015

Conversation

balajikris
Copy link
Member

Fixes #7120

Implements an IBraceMatcher that matches directive trivia syntax for C# and VB.

C# Implementation of a DirectiveTrivia Matcher as an IBraceMatcher which
enables Ctrl + ] navigation on preprocessor directives like #If ,
#region etc.
Tests for C# brace matcher on directive trivia syntax
Visual Basic implementation of a DirectiveTrivia Matcher which enables
Ctrl + ] nagivation on preprocessor directives like #if, #region etc.
VB tests for brace matching on directive trivia syntax.
@balajikris
Copy link
Member Author

@dotnet/roslyn-ide

}";

await TestAsync(code, expected);
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider: Tests for interleaved directives.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thanks.

@Pilchie
Copy link
Member

Pilchie commented Dec 8, 2015

👍

Add tests for interleaved directives
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var token = root.FindToken(position, findInsideTrivia: true);

var directive = token.Parent as DirectiveTriviaSyntax;
Copy link
Member

Choose a reason for hiding this comment

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

Will the parent always be DirectiveTrivia? What if i'm in something like #if Some || Thing && Else

I think you want to know if an ancestor is DirectiveTrivia instead.

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 works only when the caret is on the hashtoken or the keyword (#if$$ $$#else) and not on identifiers ($$CHK) or related trailing trivia ($$MyRegion).
In that it is consistent with how Highlight references performs navigation on these and with brace matching itself in VS2013. I'm open to tweaking this if you feel we should.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed offline to keep the existing design as such.

Moving common code to AbstractDirectiveTriviaBraceMatcher
Rename files.
@balajikris
Copy link
Member Author

@CyrusNajmabadi - incorporated all the feedback, please take a look.

{
internal abstract List<TDirectiveTriviaSyntax> GetMatchingConditionalDirectives(TDirectiveTriviaSyntax directive, CancellationToken cancellationToken);
internal abstract TDirectiveTriviaSyntax GetMatchingDirective(TDirectiveTriviaSyntax directive, CancellationToken cancellationToken);
internal abstract TextSpan GetSpansForTagging(TDirectiveTriviaSyntax directive);
Copy link
Member

Choose a reason for hiding this comment

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

GetSpanForTagging

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Thanks

@CyrusNajmabadi
Copy link
Member

👍 when you make the name change and you verify that the left/right thing isn't an issue. Also, make sure you have a test where you're on the end directive of a conditional.

@davkean
Copy link
Member

davkean commented Dec 11, 2015

Mac is back up
@dotnet-bot retest prtest/mac/dbg/unit32 please

Rename method per PR feedback
@balajikris
Copy link
Member Author

@CyrusNajmabadi : thanks, made the name change, left/right thing isn't an issue and already have a test for caret at end if, it wraps over to if directive as expected. Merging.

@balajikris
Copy link
Member Author

The test failure at prtest/win/dbg/unit32 is unrelated to this change. It is a known issue #6358 . retrying the job.

@balajikris
Copy link
Member Author

@dotnet-bot retest prtest/win/dbg/unit32 please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants