Skip to content

Include extension properties in object initializer completion#81498

Merged
CyrusNajmabadi merged 4 commits intomainfrom
copilot/fix-intellisense-extension-property
Dec 1, 2025
Merged

Include extension properties in object initializer completion#81498
CyrusNajmabadi merged 4 commits intomainfrom
copilot/fix-intellisense-extension-property

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

Extension properties were not appearing in IntelliSense within object initializers, though they worked correctly for direct property access.

MyClass myClass = new MyClass()
{
    NewProperty = 3, // ❌ Missing from completion
};

myClass.NewProperty = 3; // ✅ Shows in completion

Changes

  • Pass includeReducedExtensionMethods: true to LookupSymbols in AbstractObjectInitializerCompletionProvider to include extension members in the symbol lookup

Tests

Added tests in CSharpCompletionCommandHandlerTests.vb verifying:

  • Extension properties appear in object initializer completion
  • Read-only extension properties are excluded
  • Read-only collection properties are shown for collection initializer syntax (e.g., new MyClass { ReadOnlyListProp = { ... } })
  • Both regular and extension properties appear together
  • Already-typed extension properties are hidden from completion

Fixes #81497
Fixes #81405


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
@CyrusNajmabadi
Copy link
Contributor

@copilot inside AbstractObjectInitializerCompletionProvider we should add the extension properties we can find off of initializedType

Copilot AI changed the title [WIP] Fix intellisense suggestion for extension property in initializer Include extension properties in object initializer completion Dec 1, 2025
Copilot AI requested a review from CyrusNajmabadi December 1, 2025 13:39
}
""", "PropC");

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/77484")]
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot change tehse links to #81405

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated all WorkItem links to #81405 in commit 1293665.

}
""";

await VerifyItemIsAbsentAsync(markup, "ReadOnlyProp");
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot add test that shows that we would show it if it was public List<int> ReadOnlyProp because then the user could write new MyClass { ReadOnlyProp = { ... } }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added ExtensionPropertyInObjectInitializer_ReadOnlyCollectionShown test in commit 1293665 that verifies a read-only List<int> extension property is shown for collection initializer syntax new MyClass { ReadOnlyListProp = { ... } }.

Copy link
Contributor Author

Copilot AI commented Dec 1, 2025

@copilot inside AbstractObjectInitializerCompletionProvider we should add the extension properties we can find off of initializedType

The change at commit e213e21 does exactly this - passing includeReducedExtensionMethods: true to LookupSymbols(position, initializedType, ...) includes the extension properties found off of initializedType in the completion results, filtered through IsInitializableFieldOrProperty to ensure they're writeable properties.

}
""", "PropC");

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/77484")]
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot place all new tests in CSharpCompletionCommandHandlerTests.vb instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved all extension property tests from ObjectInitializerCompletionProviderTests.cs to CSharpCompletionCommandHandlerTests.vb in commit c2cdb13.

…operty

Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
…rTests.cs to CSharpCompletionCommandHandlerTests.vb

Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
@CyrusNajmabadi CyrusNajmabadi merged commit ad250e7 into main Dec 1, 2025
25 of 26 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Dec 1, 2025
@CyrusNajmabadi CyrusNajmabadi deleted the copilot/fix-intellisense-extension-property branch December 2, 2025 11:52
@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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intellisense missing extension property - in initializer Completion should include C# 14 extension property in object initializers

4 participants