powershellvisual-studio-code

See the docstring of my function with Visual Studio Code


I'm new to Visual Studio Code, I'm starting to use it to develop PowerShell scripts.

Function declaration

I see that when I let my cursor on the name of a function I get an overview of the parameters of the function, yet when I do it with my own custom functions, it does not do it.

How do I declare a documentation for my PowerShell functions that can be displayed in the overview by Visual Studio Code ?

I tried to do this :

<#
.Description
Get-Function displays the name and syntax of all functions in the session.
#>
function test([string]$print){}


<# Setup the working directories if they do not exist #>
If(!(Test-Path $WORKING_DIRECTORY)) {test}

But that doesn't seem to work.

Thanks a lot


Solution

  • Adding .PARAMETER to the description worked for me. Also note I believe you have to save and run the script once for it to show.

    <#
    .Description
    Get-Function displays the name and syntax of all functions in the session.
    .PARAMETER  
    #>
    
    function test([string]$print){Write-Host $print}
    
    If(Test-Path $env:userprofile) {test -print "Test123"}
    

    enter image description here

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-6