Skip to content

Syntax folding should differentiate between regions and comment blocks #1437

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

Closed
glennsarti opened this issue Jul 16, 2018 · 0 comments · Fixed by #1438
Closed

Syntax folding should differentiate between regions and comment blocks #1437

glennsarti opened this issue Jul 16, 2018 · 0 comments · Fixed by #1438
Labels
Area-Symbols & References Issue-Enhancement A feature request (enhancement).

Comments

@glennsarti
Copy link
Contributor

glennsarti commented Jul 16, 2018

System Details

  • Operating system name and version: N/A
  • VS Code version: N/A
  • PowerShell extension version: N/A
  • Output from $PSVersionTable: N/A

Issue Description

While working on #1428 I thought of another possible issue with the syntax folding. Currently regions and comment blocks are detected as the same thing which will cause issues when comments are not separated by empty lines.

Given a script of

# Comment Block 1
# Comment Block 1
# Comment Block 1
#region
# Comment Block 2
# Comment Block 2
# Comment Block 2
$something = $true
#endregion

Expected Folding Regions

# Comment Block 1  --+-- Folding Line 1-3
# Comment Block 1    |
# Comment Block 1  --+
#region                                   --+-- Folding Line 4-9
# Comment Block 2  --+-- Folding Line 5-7   |
# Comment Block 2    |                      |
# Comment Block 2  --+                      |
$something = $true                          |
#endregion                                --+

Actual Folding regions

# Comment Block 1  --+-- Folding Line 1-7
# Comment Block 1    |
# Comment Block 1    |
#region              |  --+-- Folding Line 4-9
# Comment Block 2    |    |
# Comment Block 2    |    |
# Comment Block 2  --+    |
$something = $true        |
#endregion              --+
glennsarti added a commit to glennsarti/vscode-powershell that referenced this issue Jul 16, 2018
Previously the syntax folding feature would not correctly identify comment
blocks and comment regions if they appeared all together.  This commit changes
the comment block detection to ignore line comments that start with region and
endregion, i.e. region block start/end directives.  This commit also adds test
for this scenario.
TylerLeonhardt pushed a commit that referenced this issue Jul 18, 2018
* (maint) Refactor region folding detection

Previously the region comment detection used a little convoluted method to
detect regions in a document.  This commit simplifies the detection by
extracting the line from the document and using regex's similar to that used by
the PowerShell language configuration.  This also removes the need for the
emptyline and subsequentText method calls.  While the performance of the folder
is pretty quick, this should in theory make it faster on larger documents by
doing less calls to the VSCode Document API.

* (GH-1437) Fix detecting contiguous comment blocks and regions

Previously the syntax folding feature would not correctly identify comment
blocks and comment regions if they appeared all together.  This commit changes
the comment block detection to ignore line comments that start with region and
endregion, i.e. region block start/end directives.  This commit also adds test
for this scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Symbols & References Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants