-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Filter IntelliSense attribute suggestions by AttributeTargets #81157
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
Merged
CyrusNajmabadi
merged 15 commits into
main
from
copilot/update-intellisense-attribute-filtering
Nov 14, 2025
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3a09a5d
Initial plan
Copilot c780868
Implement attribute target filtering for IntelliSense
Copilot a95e595
Cache ValidAttributeTargets to avoid expensive recomputation
Copilot 51cfa91
Update src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/E…
CyrusNajmabadi bd67526
Add comprehensive tests and use pattern matching improvements
Copilot 8fc6527
Add tests
CyrusNajmabadi 0a0d8ce
Update parser
CyrusNajmabadi 78d6908
Use 'field'
CyrusNajmabadi 13d6ec2
Update logic and add tests
CyrusNajmabadi 286d305
More precise check
CyrusNajmabadi 01e2862
Simplify
CyrusNajmabadi df40d59
Revert compiler side
CyrusNajmabadi f463828
Merge remote-tracking branch 'upstream/main' into copilot/update-inte…
CyrusNajmabadi dc37782
Add test
CyrusNajmabadi 3424a47
Update test
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5956,8 +5956,41 @@ private bool IsStartOfTypeParameter() | |
| return false; | ||
|
|
||
| // possible attributes | ||
| if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken && this.PeekToken(1).Kind != SyntaxKind.CloseBracketToken) | ||
| return true; | ||
| if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken) | ||
| { | ||
|
||
| var nextKind = this.PeekToken(1).Kind; | ||
| // [... | ||
| // The start of an attribute on a type parameter. | ||
| if (nextKind != SyntaxKind.CloseBracketToken) | ||
| return true; | ||
|
|
||
| // We have `[]`. Recover from a partially written attribute. | ||
| // | ||
| // <[] , | ||
| // <[] > | ||
| // <[] in/out | ||
| // <[] { ... | ||
| if (nextKind is SyntaxKind.CommaToken | ||
| or SyntaxKind.GreaterThanToken | ||
| or SyntaxKind.InKeyword | ||
| or SyntaxKind.OutKeyword | ||
| or SyntaxKind.OpenBraceToken) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| // <[] where | ||
| // <[] partial | ||
| // | ||
| // Parsing a type parameter will see this and treat the 'where' appropriately if it is the start | ||
| // of a where-clause or not. Similarly for 'partial' and if it is a keyword, or just an identifier. | ||
| if (this.PeekToken(1).ContextualKind is SyntaxKind.WhereKeyword or SyntaxKind.PartialKeyword) | ||
| return true; | ||
|
|
||
| using var _ = this.GetDisposableResetPoint(resetOnDispose: true); | ||
| this.EatToken(); // eat '[' | ||
| return IsTrueIdentifier(); | ||
| } | ||
|
|
||
| // Variance. | ||
| if (this.CurrentToken.Kind is SyntaxKind.InKeyword or SyntaxKind.OutKeyword) | ||
|
|
@@ -5968,23 +6001,24 @@ private bool IsStartOfTypeParameter() | |
|
|
||
| private TypeParameterSyntax ParseTypeParameter() | ||
| { | ||
| if (this.IsCurrentTokenWhereOfConstraintClause()) | ||
| { | ||
| return _syntaxFactory.TypeParameter( | ||
| default(SyntaxList<AttributeListSyntax>), | ||
| varianceKeyword: null, | ||
| this.AddError(CreateMissingIdentifierToken(), ErrorCode.ERR_IdentifierExpected)); | ||
| } | ||
|
|
||
| var attrs = default(SyntaxList<AttributeListSyntax>); | ||
| if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken && this.PeekToken(1).Kind != SyntaxKind.CloseBracketToken) | ||
| if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken) | ||
| { | ||
| var saveTerm = _termState; | ||
| _termState = TerminatorState.IsEndOfTypeArgumentList; | ||
| attrs = this.ParseAttributeDeclarations(inExpressionContext: false); | ||
| _termState = saveTerm; | ||
| } | ||
|
|
||
| if (this.IsCurrentTokenWhereOfConstraintClause() || | ||
| this.IsCurrentTokenPartialKeywordOfPartialMemberOrType()) | ||
|
||
| { | ||
| return _syntaxFactory.TypeParameter( | ||
| attrs, | ||
| varianceKeyword: null, | ||
| this.AddError(CreateMissingIdentifierToken(), ErrorCode.ERR_IdentifierExpected)); | ||
| } | ||
|
|
||
| return _syntaxFactory.TypeParameter( | ||
| attrs, | ||
| this.CurrentToken.Kind is SyntaxKind.InKeyword or SyntaxKind.OutKeyword ? EatToken() : null, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ok. i was actually able to simplify this to just:
and i got no regressions (in the syntax tests at least). i'm going to go with that much simpler approach as i don't really see a reason why we would accept
[ <non-close-braceas an attribute, but not[]as well.