3
3
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
4
//
5
5
6
+ using System ;
6
7
using System . Collections . Generic ;
7
8
using System . Management . Automation . Language ;
8
9
using System . Text . RegularExpressions ;
@@ -28,24 +29,17 @@ internal static FoldingReference[] FoldableRegions(
28
29
{
29
30
List < FoldingReference > foldableRegions = new List < FoldingReference > ( ) ;
30
31
31
- // Find matching braces { -> }
32
- foldableRegions . AddRange (
33
- MatchTokenElements ( tokens , TokenKind . LCurly , TokenKind . RCurly , RegionKindNone )
34
- ) ;
35
-
36
- // Find matching braces ( -> )
37
- foldableRegions . AddRange (
38
- MatchTokenElements ( tokens , TokenKind . LParen , TokenKind . RParen , RegionKindNone )
39
- ) ;
40
-
41
- // Find matching arrays @( -> )
32
+ // Find matching braces { -> }
33
+ // Find matching hashes @{ -> }
42
34
foldableRegions . AddRange (
43
- MatchTokenElements ( tokens , TokenKind . AtParen , TokenKind . RParen , RegionKindNone )
35
+ MatchTokenElements ( tokens , new TokenKind [ ] { TokenKind . LCurly , TokenKind . AtCurly } , TokenKind . RCurly , RegionKindNone )
44
36
) ;
45
37
46
- // Find matching hashes @{ -> }
38
+ // Find matching parentheses ( -> )
39
+ // Find matching array literals @( -> )
40
+ // Find matching subexpressions $( -> )
47
41
foldableRegions . AddRange (
48
- MatchTokenElements ( tokens , TokenKind . AtCurly , TokenKind . RParen , RegionKindNone )
42
+ MatchTokenElements ( tokens , new TokenKind [ ] { TokenKind . LParen , TokenKind . AtParen , TokenKind . DollarParen } , TokenKind . RParen , RegionKindNone )
49
43
) ;
50
44
51
45
// Find contiguous here strings @' -> '@
@@ -146,19 +140,19 @@ static private FoldingReference CreateFoldingReference(
146
140
}
147
141
148
142
/// <summary>
149
- /// Given an array of tokens, find matching regions which start and end with a different TokenKind
143
+ /// Given an array of tokens, find matching regions which start (array of tokens) and end with a different TokenKind
150
144
/// </summary>
151
145
static private List < FoldingReference > MatchTokenElements (
152
146
Token [ ] tokens ,
153
- TokenKind startTokenKind ,
147
+ TokenKind [ ] startTokenKind ,
154
148
TokenKind endTokenKind ,
155
149
string matchKind )
156
150
{
157
151
List < FoldingReference > result = new List < FoldingReference > ( ) ;
158
152
Stack < Token > tokenStack = new Stack < Token > ( ) ;
159
153
foreach ( Token token in tokens )
160
154
{
161
- if ( token . Kind == startTokenKind ) {
155
+ if ( Array . IndexOf ( startTokenKind , token . Kind ) != - 1 ) {
162
156
tokenStack . Push ( token ) ;
163
157
}
164
158
if ( ( tokenStack . Count > 0 ) && ( token . Kind == endTokenKind ) ) {
0 commit comments