PowerShell / PowerShell/PowerShellEditorServices
Add an on snippet event to psEditor API
未关闭
还没有人认领这个 Issue。
Area-psEditor
Issue-Enhancement
- 主要语言
- C#
- 星标
- 767
- 派生
- 266
- 平均合并
- 3 天 16 小时
- 30 天内合并 PR
- 1
描述
It'd be nice to have an event we could hook into when a snippet is used. It would be great if the
the ast of the snippet, the variables, and maybe snippet metadata like name was passed to the handler.
Alternatively (or additionally) allow editor commands to act like snippets (e.g. set "variables" to
tab to, etc.) This would enable dynamic snippets that can expand or shape the snippet based on command
output.
A very simple mock up:
/* VSCode snippet example */
"Comment Help with PowerShell Output": {
"prefix": "CommentHelp",
"body": [
"<#",
".SYNOPSIS",
" ${Short description}",
".DESCRIPTION",
" ${Long description}",
".NOTES",
" Date: ${PowerShell1:Get-Date -Format MM-dd-yyyy}",
".LINK",
" ${PowerShell2:Get-Command -Module \\$MyInvocation.MyCommand.Module.Name}",
"#>"
]
}
# PowerShell event handler.
$eventHandler = {
param($snippetVariables)
foreach ($variable in $snippetVariables) {
if ($variable.Name.StartsWith('PowerShell')) {
$script = [scriptblock]::Create($variable.Value)
$output = & $script
$psEditor.GetEditorContext().CurrentFile.InsertText($output, $variable.Range)
}
}
}
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.NOTES
Date: 04-12-2017
.LINK
Get-Function1
Get-Function2
Get-Function3
#>
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 未指明文件、测试或实现入口。先定位 psEditor API 和现有的 snippet 处理路径,然后明确目标是事件、由命令支持的 snippets,还是两者兼有。完成内容应包括针对 snippet AST、变量和元数据的明确定义的 handler contract,以及覆盖所选范围的行为和测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, powershell
- 领域
- api, tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100