Skip to content

Add new snippet for #region #1368

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/community_snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ _To contribute, check out our [guide here](#contributing)._
| [PesterTestForMandatoryParameter](#pestertestformandatoryparameter) | _Create Pester test for a mandatory parameter_ |
| [PesterTestForParameter](#pestertestforparameter) | _Create Pester test for parameter_ |
| [PSCustomObject](#pscustomobject) | _A simple PSCustomObject by @brettmillerb_ |
| [Region Block](#region-block) | _Region Block for organizing and folding of your code_ |

## Snippets

Expand Down Expand Up @@ -271,6 +272,7 @@ Quickly create a Pester Test for existence of a parameter by @SQLDBAWithABeard
"description": "Pester Test for Parameter"
}
```

### PSCustomObject

A simple PSCustomObject by @brettmillerb. It has 4 properties that you can tab through to quickly fill in.
Expand All @@ -292,6 +294,24 @@ A simple PSCustomObject by @brettmillerb. It has 4 properties that you can tab t
}
```

### Region Block

Use the `#region` for organizing your code (including good code folding).

#### Snippet

```json
"Region Block": {
"prefix": "#region",
"body": [
"#region ${1}",
"${2}",
Copy link
Member

@TylerLeonhardt TylerLeonhardt Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do people typically put the region tag after #endregion?

I've always seen:

#region foo

#endregion

vs

#region foo

#endregion foo

I'm not sure

Copy link
Contributor

@rjmholt rjmholt Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C# the most common form I've seen is:

#region Private variables

private readonly IEnumerable<string> _strs = new [] { "hello", "goodbye" };

private string _greeting = "Aloha";

#endregion // Private variables

I would imagine the PowerShell version of that is:

#region My region
...
#endregion # My region

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in PowerShell the region is already commented out, but that's an implementation detail from the line-comment delimiter and the pragma start-char being the same in my mind.

Copy link
Contributor

@rkeithhill rkeithhill Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first pref (by a smidge) would be:

#endregion

Second would be:

#endregion <name>

But either would be fine by me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like if both @tylerl0706 and @rkeithhill agree on a first preference then it should be that 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"#endregion"
],
"description": "Region Block for organizing and folding of your code"
}
```

## Contributing

If you'd like to add a snippet to this list, [open a pull request](https://opensource.guide/how-to-contribute/#opening-a-pull-request) with the following changes:
Expand Down
9 changes: 9 additions & 0 deletions snippets/PowerShell.json
Original file line number Diff line number Diff line change
Expand Up @@ -943,5 +943,14 @@
"}"
],
"description": "Creates a Hashtable"
},
"Region Block": {
"prefix": "#region",
"body": [
"#region ${1}",
"${2}",
"#endregion"
],
"description": "Region Block for organizing and folding of your code"
}
}