Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 634
Maxime Avatar asked Oct 30 '25 12:10

Maxime


1 Answers

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

like image 107
Nick Avatar answered Nov 01 '25 10:11

Nick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!