-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix SyntaxNode.Ancestors() to work correctly with structured trivia #80786
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
base: main
Are you sure you want to change the base?
Conversation
- Changed Ancestors() to use GetParent() instead of just Parent property - This allows it to properly ascend out of structured trivia (like DocumentationCommentTriviaSyntax) - Added tests for DocumentationCommentTriviaSyntax and DefineDirectiveTriviaSyntax Co-authored-by: CyrusNajmabadi <[email protected]>
Co-authored-by: CyrusNajmabadi <[email protected]>
| Assert.Equal(SyntaxKind.AddExpression, nodes[7].Kind()); | ||
| } | ||
|
|
||
| [Fact] |
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.
@copilot add a WorkItem attribute. And use a raw string literal for the test. This applies to all tests you added.
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.
Done in commit e8d5c67. Added [WorkItem("https://github.com/dotnet/roslyn/issues/46964")] attribute to both tests and converted the verbatim strings to raw string literals.
- Added [WorkItem] attribute referencing issue #46964 to both test methods - Converted verbatim strings to raw string literals (""") for better formatting Co-authored-by: CyrusNajmabadi <[email protected]>
|
@dotnet/roslyn-compiler ptal. |
Fix: DocumentationCommentTriviaSyntax.Ancestors() returns empty collection
Problem
Ancestors(ascendOutOfTrivia: true)onDocumentationCommentTriviaSyntaxreturned no ancestorsAncestorsAndSelf(ascendOutOfTrivia: true)correctly returned all ancestors including selfRoot Cause
The
Ancestorsmethod inSyntaxNode.cswas usingthis.Parentdirectly, which isnullfor structured trivia nodes. It should use theGetParenthelper method (likeAncestorsAndSelfdoes) which knows how to ascend out of structured trivia whenascendOutOfTriviaistrue.Solution
Changed
Ancestorsto useGetParent(this, ascendOutOfTrivia)instead of justthis.Parent.Changes Made
Ancestorsmethod in SyntaxNode.csTesting
TestAncestorsOfDocumentationCommentTrivia- tests doc comment triviaTestAncestorsOfDirectiveTrivia- tests preprocessor directive triviaFixes #46964
Original prompt
Fixes #46964
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.