Fix type completion in static contexts for primary constructors - #84753
Merged
Conversation
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates C# symbol recommendation logic to ensure namespaces/types are still suggested in static contexts when same-named primary-constructor parameters are returned by static-member lookup and would otherwise hide those candidates during completion.
Changes:
- Adjust symbol lookup in static expression/statement contexts to re-add namespace/type candidates matching primary-constructor parameter names.
- Add a regression completion test covering the reported static-context scenario.
Show a summary per file
| File | Description |
|---|---|
| src/Workspaces/CSharp/Portable/Recommendations/CSharpRecommendationServiceRunner.cs | Augments static-context symbol lookup to recover namespace/type candidates hidden by primary-constructor parameters. |
| src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs | Adds a regression test ensuring the type is suggested in the reported static-context scenario. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 1
JoeRobich
approved these changes
Aug 4, 2026
akhera99
enabled auto-merge (squash)
August 4, 2026 18:00
Contributor
There was a problem hiding this comment.
Copilot's findings
Suppressed comments (1)
src/Workspaces/CSharp/Portable/Recommendations/CSharpRecommendationServiceRunner.cs:421
parameter.IsPrimaryConstructor(_cancellationToken)in this completion hot path calls intoDeclaringSyntaxReferences[0].GetSyntax(...)and compares syntax nodes. Since you only need to know whether the containing constructor is a primary constructor, you can avoid those syntax materializations by usingIMethodSymbolExtensions.IsPrimaryConstructor()onparameter.ContainingSymbolinstead.
if (symbol is IParameterSymbol parameter && parameter.IsPrimaryConstructor(_cancellationToken))
{
staticSymbols.AddRange(semanticModel.LookupNamespacesAndTypes(position, name: parameter.Name));
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
JoeRobich
approved these changes
Aug 5, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: #82750
Restores type suggestions hidden by same name primary constructor parameters in static contexts
Microsoft Reviewers: Open in CodeFlow