AutoDocString用于Powershell函数



我们是否有任何VScode扩展类似于https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring或任何其他方式为PowerShell功能提供自动文档字符串?目前,我必须像这样手动添加文档字符串:

<#
.SYNOPSIS
A brief description of the function or script.
.DESCRIPTION
A longer description.
.PARAMETER FirstParameter
Description of each of the parameters.
Note:
To make it easier to keep the comments synchronized with changes to the parameters,
the preferred location for parameter documentation comments is not here,
but within the param block, directly above each parameter.
.PARAMETER SecondParameter
Description of each of the parameters.
.INPUTS
Description of objects that can be piped to the script.
.OUTPUTS
Description of objects that are output by the script.
.EXAMPLE
Example of how to run the script.
.LINK
Links to further documentation.
.NOTES
Detail on what the script does, if this is needed.
#>

它是内置的PowerShell扩展!

您可以简单地在函数上方的行输入##。它会自动展开成一个基于注释的帮助块,它会考虑到当前定义的参数。

我尝试了在接受的答案中描述的方法,但它不适合我。我建议以下两种选择之一:

替代1:

使用本文中的提示:如何创建描述性PowerShell注释

效果很好。只要输入

comment-help

,它工作得很好。

替代2:

在VSCODE中创建自己的用户代码片段。

按下F1CTRL+SHIFT+P,输入Snippets: Configure User Snippets

选择PowerShell。文件的内容应该像这样:

{
// File location:
// C:Users<username>AppDataRoamingCodeUsersnippets
"Document PowerShell code": {
"prefix": "doc",
"body": [
"<#",
".SYNOPSIS",
"    ${1:Short description}",
".DESCRIPTION",
"    ${2:Long description}",
".PARAMETER <ParamenterName>",
"    ${3:Parameter description}",
".OUTPUTS",
"    ${4:Return description}",
".NOTES",
"    Information or caveats about the function e.g. 'This function is not supported in Linux'",
".LINK",
"    # Link description",
"    http://www.fabrikam.com/extension.html",
".EXAMPLE",
"    PS> extension -name "File"",
"    File.txt",
"#>"
],
"description": "Template documentation block."
}
}

当然,你应该根据自己的需要定制

保存后,它应该位于

C:Users<username>AppDataRoamingCodeUsersnippets
现在,当你输入doc(在"prefix": "doc",行中指定),它出现在选择界面中。

最新更新