Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow snippet json prefix to be an array to support multiple prefixes for the same snippet #42838

Closed
TylerLeonhardt opened this issue Feb 2, 2018 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities release-notes Release notes issues snippets verification-needed Verification of issue is requested verified Verification succeeded

Comments

@TylerLeonhardt
Copy link
Member

We have several of the same snippets in our snippets json:

"Function-Advanced": {
        "prefix": "function-advanced",
        "body": [
            "function ${1:Verb-Noun} {",
            "\t[CmdletBinding()]",
            "\tparam (",
            "\t\t$0",
            "\t)",
            "\t",
            "\tbegin {",
            "\t}",
            "\t",
            "\tprocess {",
            "\t}",
            "\t",
            "\tend {",
            "\t}",
            "}"
        ],
        "description": "Script advanced function definition snippet"
    },
"Cmdlet": {
        "prefix": "cmdlet",
        "body": [
            "function ${1:Verb-Noun} {",
            "\t[CmdletBinding()]",
            "\tparam (",
            "\t\t$0",
            "\t)",
            "\t",
            "\tbegin {",
            "\t}",
            "\t",
            "\tprocess {",
            "\t}",
            "\t",
            "\tend {",
            "\t}",
            "}"
        ],
        "description": "Script cmdlet definition snippet"
    },

This could be avoided by supporting an array of prefixes like so:

"Cmdlet": {
        "prefix": ["function-advanced", "cmdlet"], // <--- here
        "body": [
            "function ${1:Verb-Noun} {",
            "\t[CmdletBinding()]",
            "\tparam (",
            "\t\t$0",
            "\t)",
            "\t",
            "\tbegin {",
            "\t}",
            "\t",
            "\tprocess {",
            "\t}",
            "\t",
            "\tend {",
            "\t}",
            "}"
        ],
        "description": "Script cmdlet definition snippet"
    }

It'd help slim down snippet json files and support snippets that might go by different names.

@jrieken jrieken added feature-request Request for new features or functionality snippets labels Feb 26, 2018
@jrieken jrieken added help wanted Issues identified as good community contribution opportunities good first issue Issues identified as good for first-time contributors labels Sep 10, 2018
@noamyogev84
Copy link
Contributor

Hi, can I try this one? I'm new to this repo. :)

@jrieken
Copy link
Member

jrieken commented Sep 18, 2018

Great. Some code pointers to get you started

  1. Update the JSON-schema so that prefix can be a string or an array here
  2. The serialised snippet (as defined in JSON) is declared here
  3. Creating snippets happens in the _parseSnippet-method. You are best off to create and push a new snippet per prefix when it is an array

@noamyogev84
Copy link
Contributor

Hi @jrieken thanks for this detailed howto.

@noamyogev84
Copy link
Contributor

@jrieken can you take a quick look at my implementation?

@jrieken jrieken added this to the September 2018 milestone Sep 21, 2018
@jrieken
Copy link
Member

jrieken commented Sep 21, 2018

Done! All thanks to @noamyogev84 👏 🏅

@jrieken jrieken closed this as completed Sep 21, 2018
@TylerLeonhardt
Copy link
Member Author

Nice work, @noamyogev84!! 🎉

@noamyogev84
Copy link
Contributor

@jrieken @tylerl0706
Thanks guys!

@jrieken jrieken added the verification-needed Verification of issue is requested label Sep 24, 2018
@roblourens roblourens added the verified Verification succeeded label Sep 26, 2018
@jrieken jrieken added the release-notes Release notes issues label Sep 27, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities release-notes Release notes issues snippets verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants