SublimeText / PowerShell

Support for the MS PowerShell programming language.
MIT License
312 stars 80 forks source link

Allow code-folding for comment blocks #155

Closed alexqfredrickson closed 6 years ago

alexqfredrickson commented 6 years ago

It would be a nice feature to be allow code-folding for multi-line comment blocks.

Comment blocks are used to define documentation for functions, and they can get fairly verbose:

<#
.DESCRIPTION
Escapes characters in XML requests.
.EXAMPLE
Clean-XML -text "Hello <world>"
#>
Function Clean-XML() {
    param(
        [string]$text =$(throw "Parameter missing: -text")
    )
    #do things
    return $text
}
keith-hall commented 6 years ago

ST's code folding arrows in the gutter are currently based on indentation only, there is currently no way to configure that any differently. See https://github.com/SublimeTextIssues/Core/issues/101 for an open feature request.

However, you can always select any text that you want to fold and go to the Edit menu -> Code Folding -> Fold (or press the appropriate key binding). If you want to quickly select the entire comment, you could try Selection -> Expand Selection to Scope while the caret is inside the comment. And of course, as ST is customizable, you could combine the two into a new keybinding :)

alexqfredrickson commented 6 years ago

Thanks Keith! Ideally I wanted one of those clicky-arrow thingies, but I can absolutely live with this.

The "workaround" I have been using is that PowerShell also recognizes docstrings located immediately underneath function declarations (which are collapsible):

Function Clean-XML() {
<#
.DESCRIPTION
Escapes characters in XML requests.
.EXAMPLE
Clean-XML -text "Hello <world>"
#>
   param(
       [string]$text =$(throw "Parameter missing: -text")
   )

   #do things
   return $text
}