Skip to content

Modernize built-in snippets #3839

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

Merged
merged 14 commits into from
Mar 5, 2022
Merged

Modernize built-in snippets #3839

merged 14 commits into from
Mar 5, 2022

Conversation

JustinGrote
Copy link
Collaborator

@JustinGrote JustinGrote commented Feb 19, 2022

Evaluate and modernize existing snippets. This will be a breaking change in some cases, we should provide guidance for restoring existing snippets for any cranky people :).

After this PR, snippets may be further improved by moving them out of JSON definition and into typescript, the primary improvement being that we can define the description with a MarkdownString and include help links, etc. but how much of that should just be returned by the LSP vs. a snippet is TBD.

  • ArgumentCompleterAttribute ScriptBlock - Redundant and not useful since you cant use a variable with an ArgumentCompleter
  • ArgumentCompleterAttribute with ScriptBlock - Renamed and more descriptive help added. Added final tabstop after argumentcompleter
  • CalculatedProperty - description and help reference
  • Class - description and help reference
  • comment block
  • Comment-Help Replaced with Function Help
  • Constructor - description and help reference
  • do-until - description and help reference
  • do-while - description and help reference

Should DSC move to community snippets?

  • DSC Ensure Enum
  • DSC Resource Provider (class-based)
  • DSC Resource Provider (function-based)

  • else - description and help reference
  • elseif - description and help reference
  • Enum - description and help reference
  • Example-Advanced Workflow - Workflows are deprecated, we should encourage parallel instead.

Should we still have examples or should the examples be with placeholders?

  • Example-Class
  • Example-Cmdlet
  • Example-DSC Configuration
  • Example-DSC Resource Provider (class-based)
  • Example-DSC Resource Provider (function based)
  • Example-Path Processing for No Wildcards Allowed
  • Example-Path Processing for Non-Existing Paths
  • Example-Path Processing for Wildcards Allowed
  • Example-Splatting
  • Example-Switch

  • for - description and help reference,
  • for-reversed
  • foreach
  • function
  • Function-Advanced- description and help reference, update aliases
  • Function-Help- description and help reference, update aliases
  • Function-Inline- description and help reference, update aliases
  • Hashtable- description and help reference, update aliases
  • Hidden Property- description and help reference, update aliases
  • IArgumentCompleter Class - description and help reference, update aliases
  • if - description and help reference,
  • IfShouldProcess - description and help reference, update aliases
  • Method
  • ModuleManifest
  • Parameter - description and help reference, update aliases
  • Parameter_Block - description and help reference, update aliases
  • Parameter-LiteralPath - description and help reference, update aliases
  • Parameter-Path - description and help reference, update aliases
  • Parameter-Path-Wildcards - description and help reference, update aliases

Should Pester Move to Community Snippets since it is no longer bundled with Powershell?

  • PesterContext
  • PesterContextIt
  • PesterDescribeBlock
  • PesterDescribeContextIt
  • PesterIt

  • Property
  • PSCustomObject
  • Region Block

Intellisense now handles the requires, there was a comment that these should be removed when it does.

  • Requires Assembly
  • Requires Assembly Path
  • Requires Assembly Version
  • Requires Module
  • Requires Module RequiredVersion
  • Requires Module Version
  • Requires PSEdition
  • Requires PSSnapin
  • Requires PSSnapin Version
  • Requires RunAsAdministrator
  • Requires ShellId
  • Requires Version

  • Suppress PSScriptAnalyzer Rule - rewritten to multiline, description, and help reference
  • Suppress PSScriptAnalyzer Rule in Scope - rewritten to multiline, description, and help reference
  • Suppress PSScriptAnalyzer Rule on Parameter - rewritten to multiline, description, and help reference
  • switch - description and help reference
  • try-catch - description and help reference
  • try-catch-finally - description and help reference
  • try-finally - description and help reference
  • while - description and help reference

Workflows are deprecated and not supported in 6+, we should not be encouraging their use.

  • Workflow
  • Workflow ForEachParallel
  • Workflow InlineScript
  • Workflow Parallel
  • Workflow Sequence

NEW

  • Function Help - Better Comment based help with tabstopes
  • Pipeline Function - A simple definition of a function that is pipelineable
  • Parallel Pipeline Function - A simple definition of a function that uses foreach-parallel to process items in the pipeline in parallel.
  • Ternary - build a ternary condition
  • Splat - Select a function name and it will build a splat for it. This is not a refactor for an existing function.
  • Here String
  • Literal Here String

@JustinGrote
Copy link
Collaborator Author

JustinGrote commented Feb 20, 2022

@andschwa first pass done. There's a lot of things here that I think are more community questions: Should we retain legacy snippets for deprecated and discouraged features like workflows, should we retain pester now that it's no longer bundled with PS, etc.

All of which keeping in mind there is the community snippets section of docs, though I think it would warrant just being another mini-extension maybe.

@JustinGrote
Copy link
Collaborator Author

@andschwa Build failure is not me:

ERROR: The script 'PowerShellEditorServices.build.ps1' cannot be run because the following modules that are specified by the "#requires" statements of the script are missing: platyPS.

@andyleejordan
Copy link
Member

@andschwa Build failure is not me:

ERROR: The script 'PowerShellEditorServices.build.ps1' cannot be run because the following modules that are specified by the "#requires" statements of the script are missing: platyPS.

Fixed it! Sorry about that. 😅 Give it a rebase and it should work. This is looking great!

@andyleejordan
Copy link
Member

I rebased it!

@JustinGrote JustinGrote marked this pull request as ready for review February 24, 2022 22:07
@JustinGrote
Copy link
Collaborator Author

JustinGrote commented Feb 24, 2022

Should be good to go. A lot of these snippets support the vscode "snippet in place" method now. For example, type Invoke-Restmethod, highlight it, and then overwrite it with splat and hit tab or select the completion snippet.

I removed a lot of snippets based on my opinion and on some polling, need more opinions however as to should these stay with the "core" extension or should instead ship either as a community snippets extension or just provided guidance within the existing community snippets markdown file.

@andyleejordan andyleejordan changed the title WIP: Snippet Refactor Snippet overhaul Feb 28, 2022
@andyleejordan
Copy link
Member

@JustinGrote do you know what this issue means: #3404 ? 😂

@JustinGrote
Copy link
Collaborator Author

JustinGrote commented Feb 28, 2022

@andschwa it's a symptom of an issue closed for workaround that we may want to reopen
#3456

EDIT: Also #3378

@JustinGrote
Copy link
Collaborator Author

JustinGrote commented Feb 28, 2022

Disregard, I was mistaken, this is part of the snippet itself. It can be configured either way, but we should decide if we are going to change the consensus on whether $ is considered a word separator or not (e.g. double clicking $this if it highlights the whole thing or just "this"), whatever that decision, the snippets can follow suit. As of today I have them matching the existing behavior ($ is excluded), a user can always provide their own overriding user snippets for the other mode.

Ultimately I'd like to see the snippets converted to completions for multiple reasons:

  1. Markdown descriptions can be used for better help (e.g. links)
  2. This behavior could be configurable or could auto-detect wordseparators

But this PR just an easy first step to modernization

@JustinGrote
Copy link
Collaborator Author

Also I personally am team "$ is not a word separator" mostly because it makes double-click + ctrl-f2 to rename all symbols more error prone, unless we come up with a way to do a proper rename symbol in Powershell

@andyleejordan
Copy link
Member

Should DSC move to community snippets?

Eh, sure, if we have that setup.

Should we still have examples or should the examples be with placeholders?

I'm down to remove them. They could be in a help file if we wanted.

Should Pester Move to Community Snippets since it is no longer bundled with Powershell?

You'd be the expert on this! Perhaps they should? But also everyone uses Pester with PowerShell, it's the default test framework really.

Intellisense now handles the requires, there was a comment that these should be removed when it does.

Sweet!

Workflows are deprecated and not supported in 6+, we should not be encouraging their use.

Sounds good to me!

NEW

Loving it!

P.S. Sorry this took me a while to get to! Testing them out right now.

@andyleejordan andyleejordan force-pushed the feature/ModernSnippets branch from 496f912 to c1c06ca Compare March 4, 2022 22:55
@andyleejordan andyleejordan changed the title Snippet overhaul Modernize built-in snippets Mar 5, 2022
@andyleejordan andyleejordan added Area-Snippets Issue-Enhancement A feature request (enhancement). labels Mar 5, 2022
@andyleejordan andyleejordan enabled auto-merge (squash) March 5, 2022 00:24
@andyleejordan
Copy link
Member

Thanks so much @JustinGrote!

@andyleejordan andyleejordan merged commit eeba51e into master Mar 5, 2022
@andyleejordan andyleejordan deleted the feature/ModernSnippets branch March 5, 2022 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Snippets Issue-Enhancement A feature request (enhancement).
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants