PowerShell / PowerShell/PowerShellEditorServices

Add an on snippet event to psEditor API

Open
#439 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-psEditor Issue-Enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.