Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
yotsuda wants to merge4 commits intoPowerShell:master
base:master
Choose a base branch
Loading
fromyotsuda:PowerShell-issue-18914

Conversation

@yotsuda
Copy link
Contributor

PR Summary

AllowHiddenAttribute to be applied to classes and exclude hidden classes from type name completion.

PR Context

Fixes#18914

TheHiddenAttribute can 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:

[Hidden]// Error: Not valid on this declaration typepublicclassInternalHelperClass{}

After this fix:

[Hidden]// Now works - class is hidden from completionpublicclassInternalHelperClass{}varobj=newInternalHelperClass();// Can still instantiate explicitly[Internal<Tab>]// Does NOT suggest InternalHelperClass

PR Checklist

Description

Implementation

1. ExtendedHiddenAttribute target (Attributes.cs)

  • AddedAttributeTargets.Class toAttributeUsage

2. AddedIsHidden property toTypeDefinitionAst (ast.cs)

  • Cached property following the same pattern asPropertyMemberAst.IsHidden
  • UsesGetReflectionAttributeType() for attribute checking

3. Filtered hidden classes from type completion (CompletionCompleters.cs)

  • PowerShell-defined types: Filter using!ast.IsHidden
  • C#-defined types: Filter usingtype.IsDefined(typeof(HiddenAttribute), false)

Files Changed

  • src/System.Management.Automation/engine/Attributes.cs - Extended AttributeUsage
  • src/System.Management.Automation/engine/parser/ast.cs - Added IsHidden property
  • src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs - Filter hidden types
  • test/powershell/Language/Classes/Scripting.Classes.BasicParsing.Tests.ps1 - Added tests

Testing

Test Coverage

Added 3 comprehensive test cases:

  1. Instance creation - Verifies hidden classes can be instantiated
  2. Attribute presence - Validates attribute is correctly applied
  3. Type completion exclusion - Confirms hidden classes don't appear in tab completion

Results

Describing HiddenAttribute on Class Test  [+] Should be able to create an instance of hidden class 7ms  [+] HiddenAttribute should be present on the class 14ms  [+] Hidden class should not appear in type name completion 142msTests Passed: 327, Failed: 0, Skipped: 11, Pending: 13, Inconclusive: 0

Additional Notes

  • No breaking changes - only adds new functionality
  • Consistent with existingHiddenAttribute behavior for members
  • Performance: Attribute check is cached to avoid repeated reflection calls
  • Useful for hiding internal helper classes in modules

…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
@iSazonoviSazonov added the CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log labelNov 24, 2025
@iSazonov
Copy link
Collaborator

@MartinGC94 Please review.

Copy link
Contributor

CopilotAI left a 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:

  • ExtendedHiddenAttribute target to include classes
  • Added cachedIsHidden property toTypeDefinitionAst for 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.

FileDescription
src/System.Management.Automation/engine/Attributes.csAddedAttributeTargets.Class toHiddenAttribute.AttributeUsage
src/System.Management.Automation/engine/parser/ast.csAdded cachedIsHidden property toTypeDefinitionAst using reflection-based attribute checking
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.csFiltered 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.ps1Added 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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MartinGC94
Copy link
Contributor

It seems fine but I don't see a test for hiding PowerShell classes from tabcompletion:TabExpansion2 '[hidden()] class Test1{} [Test1'

This uses the AST so it's handled differently than C# classes are.

iSazonov reacted with thumbs up emoji

@yotsuda
Copy link
ContributorAuthor

@MartinGC94 Thank you for the insightful review! You're absolutely right - the[hidden()] syntax wasn't available for PowerShell classes (missing type accelerator), and there were no tests for the AST-based scenario you mentioned.

I've added the following ina5344fe:

  1. Hidden type accelerator - RegisteredHiddenAttribute inCoreTypes to enable[hidden()] syntax for PowerShell classes, consistent with other attributes like[Parameter()]

  2. Comprehensive tests - Including your specific scenario[hidden()] class Test1{} [Test1, plus regression tests to ensure visible classes still appear in completion

All tests pass (332 passed).

MartinGC94 reacted with thumbs up emoji

Copy link
Contributor

CopilotAI left a 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.

@microsoft-github-policy-servicemicrosoft-github-policy-servicebot added the Review - NeededThe PR is being reviewed labelDec 3, 2025
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for7 days.
Maintainer, please provide feedback and/or mark it asWaiting on Author

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@daxian-dbwdaxian-dbwAwaiting requested review from daxian-dbwdaxian-dbw is a code owner

@SeeminglyScienceSeeminglyScienceAwaiting requested review from SeeminglyScienceSeeminglyScience is a code owner

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change LogReview - NeededThe PR is being reviewed

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AllowHiddenAttribute to decorate classes

3 participants

@yotsuda@iSazonov@MartinGC94

[8]ページ先頭

©2009-2025 Movatter.jp