- Notifications
You must be signed in to change notification settings - Fork8.1k
Allow HiddenAttribute to decorate classes and exclude from type completion#26517
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…etion- Extend AttributeUsage to include AttributeTargets.Class- Add IsHidden property to TypeDefinitionAst with caching- Filter hidden classes from type name completion in CompleteType- Add comprehensive tests for hidden class functionality
iSazonov commentedNov 24, 2025
@MartinGC94 Please review. |
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.
Pull request overview
This PR extends theHiddenAttribute to support class-level application, allowing developers to hide internal helper classes from type name completion while still allowing explicit instantiation. The feature complements the existing ability to hide class members from Get-Member and Format-* cmdlets.
Key changes:
- Extended
HiddenAttributetarget to include classes - Added cached
IsHiddenproperty toTypeDefinitionAstfor PowerShell-defined classes - Updated type completion to filter out hidden classes from both C# and PowerShell definitions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/System.Management.Automation/engine/Attributes.cs | AddedAttributeTargets.Class toHiddenAttribute.AttributeUsage |
| src/System.Management.Automation/engine/parser/ast.cs | Added cachedIsHidden property toTypeDefinitionAst using reflection-based attribute checking |
| src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs | Filtered hidden classes from type completion for both loaded assemblies (C# types) and script-defined types (PowerShell classes) |
| test/powershell/Language/Classes/Scripting.Classes.BasicParsing.Tests.ps1 | Added test cases verifying instantiation, attribute presence, and completion exclusion for C#-defined hidden classes |
💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
MartinGC94 commentedNov 24, 2025
It seems fine but I don't see a test for hiding PowerShell classes from tabcompletion: This uses the AST so it's handled differently than C# classes are. |
faa095d toa5344feCompareyotsuda commentedNov 25, 2025
@MartinGC94 Thank you for the insightful review! You're absolutely right - the I've added the following ina5344fe:
All tests pass (332 passed). |
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.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for7 days. |
PR Summary
Allow
HiddenAttributeto be applied to classes and exclude hidden classes from type name completion.PR Context
Fixes#18914
The
HiddenAttributecan be applied to properties, methods, and other members to hide them from tab completion andGet-Member, but could not be applied to classes themselves. This PR extends the attribute to support classes and ensures hidden classes are excluded from type name completion.Before this fix:
After this fix:
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerDescription
Implementation
1. Extended
HiddenAttributetarget (Attributes.cs)AttributeTargets.ClasstoAttributeUsage2. Added
IsHiddenproperty toTypeDefinitionAst(ast.cs)PropertyMemberAst.IsHiddenGetReflectionAttributeType()for attribute checking3. Filtered hidden classes from type completion (CompletionCompleters.cs)
!ast.IsHiddentype.IsDefined(typeof(HiddenAttribute), false)Files Changed
src/System.Management.Automation/engine/Attributes.cs- Extended AttributeUsagesrc/System.Management.Automation/engine/parser/ast.cs- Added IsHidden propertysrc/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs- Filter hidden typestest/powershell/Language/Classes/Scripting.Classes.BasicParsing.Tests.ps1- Added testsTesting
Test Coverage
Added 3 comprehensive test cases:
Results
Additional Notes
HiddenAttributebehavior for members