Skip to content

Enable tab completion for variables that are of enum type #10631

Closed

Description

Summary of the new feature/enhancement

When setting preference variables like $ErrorActionPreference, it would be great to help users discover allowed values by:

$ErrorActionPreference = <tab>

instead of trying to set it to something invalid and seeing the allowed values in the error message.

Activity

  1. added
    Issue-Enhancement
    on Sep 26, 2019
  2. mklement0 commented on Sep 26, 2019

    @mklement0
    Contributor

    That would be an excellent improvement.

    Ideally, this should also work for flag (bit-field) enumerations, so that something like the following would work:

    # Sample flags enumeration.
    [Flags()] enum Foo { first = 0x1; second = 0x2; third = 0x4 }
    
    # Tab-complete flag values inside strings too (with or without a closing quote present).
    [Foo] 'first, th'<tab>  # -> 'first, third', tantamount to [Foo]::first -bor [Foo]::third
  3. SeeminglyScience commented on Sep 27, 2019

    @SeeminglyScience
    Contributor
    $ErrorActionPreference = <tab>

    Should it be that or should it be:

    $ErrorActionPreference = '<tab>

    If the former, would it complete to a string or to a static member expression?

    Also would be fantastic if this worked on convert expressions (like in Michael Klement (@mklement0)'s example)

  4. mklement0 commented on Sep 27, 2019

    @mklement0
    Contributor

    Good question, Patrick Meinecke (@SeeminglyScience).

    I'm thinking that even $ErrorActionPreference = <tab> (no opening quote) should complete to a string (e.g, $ErrorActionPreference = 'Stop'), for two reasons:

    • Using types and static properties is an advanced technique, and strings are more concise and provide better symmetry with use in arguments (e.g., -ErrorAction Stop), where use of the static property expression would be impractical (e.g., -ErrorAction ([System.Management.Automation.ActionPreference]::Stop))

    • With flag enumerations, a string value is easier to modify later (again with tab-completion support), especially when new flags are added (e.g., 'Compiled' -> 'Compiled, IgnoreCase' vs. [System.Text.RegularExpressions.RegexOptions]::Compiled -> [System.Text.RegularExpressions.RegexOptions]::Compiled -bor [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)

  5. SteveL-MSFT commented on Sep 28, 2019

    @SteveL-MSFT
    MemberAuthor

    I think string is definitely more user friendly.

  6. SteveL-MSFT commented on Sep 29, 2019

    @SteveL-MSFT
    MemberAuthor

    Michael Klement (@mklement0) please open a new issue for flags

  7. mklement0 commented on Sep 29, 2019

    @mklement0
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-EnhancementResolution-FixedWG-Interactive-IntelliSense

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions