Skip to content

Fix type completion in static contexts for primary constructors - #84753

Merged
akhera99 merged 3 commits into
dotnet:mainfrom
akhera99:completion_static_context
Aug 5, 2026
Merged

Fix type completion in static contexts for primary constructors#84753
akhera99 merged 3 commits into
dotnet:mainfrom
akhera99:completion_static_context

Conversation

@akhera99

@akhera99 akhera99 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Fixes: #82750

Restores type suggestions hidden by same name primary constructor parameters in static contexts

Microsoft Reviewers: Open in CodeFlow

@akhera99
akhera99 requested a review from a team as a code owner August 4, 2026 16:34
Copilot AI review requested due to automatic review settings August 4, 2026 16:34
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copilot AI review requested due to automatic review settings August 4, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new

@akhera99
akhera99 enabled auto-merge (squash) August 4, 2026 18:00
Copilot AI review requested due to automatic review settings August 4, 2026 20:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

Suppressed comments (1)

src/Workspaces/CSharp/Portable/Recommendations/CSharpRecommendationServiceRunner.cs:421

  • parameter.IsPrimaryConstructor(_cancellationToken) in this completion hot path calls into DeclaringSyntaxReferences[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 using IMethodSymbolExtensions.IsPrimaryConstructor() on parameter.ContainingSymbol instead.
                            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

@akhera99
akhera99 merged commit b8fd4a7 into dotnet:main Aug 5, 2026
25 checks passed
@jjonescz jjonescz added this to the 18.11 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing suggestion completion of class in static context when a same-name property exists

4 participants