Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

Followup to #81157

Copilot AI and others added 11 commits November 11, 2025 15:17
- Add ValidAttributeTargets property to SyntaxContext base class
- Implement ComputeValidAttributeTargets in CSharpSyntaxContext
- Update IsOrContainsAccessibleAttribute to filter by AttributeTargets
- Add comprehensive tests for attribute filtering scenarios

Co-authored-by: CyrusNajmabadi <[email protected]>
Added lazy caching using nullable AttributeTargets field to compute the value only once per CSharpSyntaxContext instance.

Co-authored-by: CyrusNajmabadi <[email protected]>
…xtensions/ContextQuery/CSharpSyntaxContext.cs
- Added WorkItem attribute to all attribute filtering tests
- Added tests for all syntax node types (struct, interface, enum, delegate, record, constructor, property, field, event, parameter, type parameter, indexer)
- Added tests for all target specifiers (assembly, module, type, method, field, property, event, param, return, typevar)
- Simplified AttributeUsageAttribute lookup using nested property pattern
- Simplified constructor argument check using collection pattern
- Changed target identifier check to use SyntaxKind instead of string literals

Co-authored-by: CyrusNajmabadi <[email protected]>
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review November 14, 2025 10:26
@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners November 14, 2025 10:26
@CyrusNajmabadi
Copy link
Member Author

@dotnet/roslyn-compiler this is ready for review.

return false;

// possible attributes
if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken && this.PeekToken(1).Kind != SyntaxKind.CloseBracketToken)
Copy link
Member Author

Choose a reason for hiding this comment

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

this blocks good error recovery in the Foo<[]T> case. There isn't a good reason for this, as [] isn't a suitable start of some other construct. In all other attribute cases, running into [] is supported, just not for type params.

This simply removes that restriction, and gives consistent support for attributes here like everywhere else.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 13)

@CyrusNajmabadi
Copy link
Member Author

@RikkiGibson ptal :)

@CyrusNajmabadi CyrusNajmabadi requested a review from jcouv November 15, 2025 09:39
@CyrusNajmabadi
Copy link
Member Author

@jjonescz ptal :)

@jcouv jcouv self-assigned this Nov 18, 2025
}

if (this.IsCurrentTokenWhereOfConstraintClause() ||
this.IsCurrentTokenPartialKeywordOfPartialMemberOrType())
Copy link
Member

Choose a reason for hiding this comment

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

It's not obvious why "partial" is getting special treatment. Should we similarly care about other modifier keywords?

Copy link
Member Author

Choose a reason for hiding this comment

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

partial/where refer to the special identifiers that IsTrueIdentifier returns false for if it sees that these should not actually be treated as identifiers but as contextual keywords.

They're treated specially here as they are very reasonable contextual keywords that would follow a type param being written.

N(SyntaxKind.EndOfFileToken);
}
EOF();
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider testing < public or <[] public

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure: fd5d3d1

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (commit 13)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (commit 15)

@CyrusNajmabadi CyrusNajmabadi merged commit 4800e39 into dotnet:main Nov 18, 2025
29 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the copilot/update-intellisense-attribute-filtering-with-compiler branch November 18, 2025 15:45
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 18, 2025
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
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.

4 participants