PowerShell / PowerShell/PowerShellEditorServices
Add an on snippet event to psEditor API
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 767
- Forks
- 266
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
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
#>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or implementation entry points. Start by locating the psEditor API and the existing snippet-handling path, then clarify whether the goal is an event, command-backed snippets, or both. Done should include a defined handler contract for snippet AST, variables, and metadata, with behavior and tests covering the chosen scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100