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

(GH-811) Fix folding with spanning regions #805

Merged
merged 4 commits into from
Dec 12, 2018
Merged
Changes from 1 commit
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: 18 additions & 2 deletions src/PowerShellEditorServices/Language/TokenOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@ namespace Microsoft.PowerShell.EditorServices
/// </summary>
internal static class TokenOperations
{
// Region kinds to align with VSCode's region kinds
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for adding that

private const string RegionKindComment = "comment";
private const string RegionKindRegion = "region";
private const string RegionKindNone = null;

// Opening tokens for { } and @{ }
private static readonly TokenKind[] s_openingBraces = new []
{
TokenKind.LCurly,
TokenKind.AtCurly
};

// Opening tokens for ( ), @( ), $( )
private static readonly TokenKind[] s_openingParens = new []
{
TokenKind.LParen,
TokenKind.AtParen,
TokenKind.DollarParen
};

/// <summary>
/// Extracts all of the unique foldable regions in a script given the list tokens
/// </summary>
Expand All @@ -32,14 +48,14 @@ internal static FoldingReference[] FoldableRegions(
// Find matching braces { -> }
// Find matching hashes @{ -> }
TylerLeonhardt marked this conversation as resolved.
Show resolved Hide resolved
foldableRegions.AddRange(
MatchTokenElements(tokens, new TokenKind[] { TokenKind.LCurly, TokenKind.AtCurly }, TokenKind.RCurly, RegionKindNone)
MatchTokenElements(tokens, s_openingBraces, TokenKind.RCurly, RegionKindNone)
);

// Find matching parentheses ( -> )
// Find matching array literals @( -> )
// Find matching subexpressions $( -> )
foldableRegions.AddRange(
MatchTokenElements(tokens, new TokenKind[] { TokenKind.LParen, TokenKind.AtParen, TokenKind.DollarParen }, TokenKind.RParen, RegionKindNone)
MatchTokenElements(tokens, s_openingParens, TokenKind.RParen, RegionKindNone)
);

// Find contiguous here strings @' -> '@
Expand Down