Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Expose parameters to the Outline View #5153

Open
5 of 6 tasks
BinaryInk opened this issue Mar 7, 2025 · 1 comment
Open
5 of 6 tasks

Feature Request: Expose parameters to the Outline View #5153

BinaryInk opened this issue Mar 7, 2025 · 1 comment
Labels
Area-UI Feature: VS Code Request to use or implement a VS Code feature. Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs. Verified This issue has been determined to be a legitimate issue that requires a fix.

Comments

@BinaryInk
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

Issue & Reproduction

First, searching through the open issues, this could be related to #3913, but I don't believe so as it doesn't matter whether the parameter declaration has attributes or not.

When creating a script using a param() block, the parameters are not included in the outline. It doesn't matter whether the parameter(s) have attributes or defined types, it doesn't appear

For example, none of the following situations result in the appearance of parameters in outline:

# As a Cmdlet:
[CmdletBinding()]
param(
  [Parameter()]
  [string]
  $MyString,

  [Parameter()]
  $MyLooselyTypedParam
)

# As a script
param(
  [string]$MyString,

  $MyLooselyTypedParam
)

# As an in-script Cmdlet:
function New-MyFunc {
  [CmdletBinding()]
  param(
    [Parameter()]
    [string]
    $MyString,

    [Parameter()]
    $MyLooselyTypedParam
  )
}

# As an in-script function:
function New-MyFunc {
  param(
    [string]$MyString,

    $MyLooselyTypedParam
}

In all of the above cases, both $MyString and $MyLooselyTypedParam are not surfaced in the Outline View in VSCode.

However, I did notice that when using a function declaration, you can get the parameters to show up in the function's definition by using the in-line parameter declaration:

function New-MyFunc([string]$MyString) {
# ...
}

Where it will show up as function My-NewFunc ([string]$MyString) even if the parameters are split into multiple lines. In any case, using an in-line function declaration isn't exactly a solution to the problem, as it is a long string in a small sidebar.


Expected Behavior

I would expect the Outline View to behave similarly as it does in other .NET languages like C#.

For instance, using the above example, the outline would look more like:

[f(x) icon] New-MyFunc
  [(x) icon] $MyString
  [(x) icon] $MyLooselyTypedParam

Ideally, the parameters would be a child of a separate parent named something like param() and begin{} process{} end{} blocks would also be represented:

[icon] param()
  [(x) icon] $MyString
  [(x) icon] $MyLooselyTypedParam
[f(x) icon] New-MyFunc
  [icon] param()
    [(x) icon] $MyNewFuncString
    [(x) icon] $MyNewFuncLooselyTypedParam
  [(x) icon] $myLocalFuncString
  [(x) icon] $myLocalFuncInt
[icon] begin
  [(x) icon] $myLocalScriptString
[(x) icon] $myLocalScriptInt

representing:

[CmdletBinding()]
param(
  [Parameter()]
  [string]
  $MyString,

  [Parameter()]
  $MyLooselyTypedParam
)

function New-MyFunc {
  [CmdletBinding()]
  param(
    [Parameter()]
    [string]
    $MyString,

    [Parameter()]
    $MyLooselyTypedParam
  )

  $myLocalFuncString = "From Earth"
  $myLocalFuncInt = 12
}

begin {
  $myLocalScriptString = "Hello World"
}

$myLocalScriptInt = 55

But just having proper support for parameters in the outline would be extremely beneficial.


Conclusion

Unfortunately, without displaying parameters, the functionality of the Outline View is very limiting and only particularly useful for either a.) small scripts or b.) poorly made scripts that don't leverage the features of PowerShell that make it better than shell scripts (or actively work around intended usage, e.g., by applying parameters to variables according to argument position like a bash/shell script).

PowerShell Version

$PSVersionTable; $Host

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Arch Linux
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2025.0.0
InstanceId       : e8d9e3f0-3500-4140-8739-f7f403df2d5f
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

code --version

1.98.0
6609ac3d66f4eade5cf376d1cb76f13985724bcb
x64

Extension Version

code --list-extensions --show-versions --profile 'Shell Scripting' | Select-String powershell

[email protected]

Steps to Reproduce

See primary description outlining the issue; reproduction only requires the use of basic PowerShell features such as function and param().

Visuals

N/A

Logs

N/A

@BinaryInk BinaryInk added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Mar 7, 2025
@JustinGrote
Copy link
Collaborator

JustinGrote commented Mar 7, 2025

Thank you for your submission!

It is certainly possible to expose these via the Outline, we would probably make it an opt-in parameter. Marking this as Up For Grabs and changing it to enhancement.

This will probably first require semantic highlighting enabled and working, as the existing textmate grammer does not explicitly detect parameters, but rather just identifies them as variables.

Image

As an alternative, ctrl+T (Go to symbol in workspace) lets you quickly find and navigate to any symbol in the environment, and parameters are present there.

@JustinGrote JustinGrote added Up for Grabs Will shepherd PRs. Feature: VS Code Request to use or implement a VS Code feature. Area-UI Verified This issue has been determined to be a legitimate issue that requires a fix. and removed Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Mar 7, 2025
@JustinGrote JustinGrote changed the title Parameters do not appear in the Outline View Feature Request: Expose parameters to the Outline View Mar 7, 2025
@JustinGrote JustinGrote added the Issue-Enhancement A feature request (enhancement). label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-UI Feature: VS Code Request to use or implement a VS Code feature. Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs. Verified This issue has been determined to be a legitimate issue that requires a fix.
Projects
None yet
Development

No branches or pull requests

2 participants