Add an on snippet event to psEditor API
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
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.
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
#>
- Dominant language
- C#
- Stars
- 767
- Forks
- 266
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
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.
More from PowerShell/PowerShellEditorServices
-
[Bug] None of the string overloads of `EditorExtensionServiceProvider.GetService()` work on .NET. Open
PowerShell/PowerShellEditorServices#2331 · 1 reaction · 2 assignees ·
-
Area-Language Server Issue-Enhancement
Difficulty 4/5 3-5 days Newbie friendliness 48/100
PowerShell/PowerShellEditorServices#2315 · 1 comment ·
-
Area-Debugging Issue-Enhancement
PowerShell/PowerShellEditorServices#2294 · 1 reaction · 2 assignees ·
-
Issue-Bug Needs: Triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
PowerShell/PowerShellEditorServices#2293 · 1 comment ·
-
PowerShell/PowerShellEditorServices#2282 · 1 comment · 1 reaction · 2 assignees ·
All issues in PowerShell/PowerShellEditorServices
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
nightscout/nocturne#1425 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Documentation
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
cake-build/cake#5024 ·
-
Frontend status/draft TechnicalDebt
Difficulty 2/5 1-2 days Newbie friendliness 75/100
Altinn/altinn-auth#4143 ·