@@ -182,6 +182,31 @@ export class FoldingProvider implements vscode.FoldingRangeProvider {
182
182
return result . reverse ( ) ;
183
183
}
184
184
185
+ // Given a textmate scope name, find a series of contiguous tokens which contain
186
+ // that scope name and pair them together.
187
+ private matchContiguousScopeElements ( tokens ,
188
+ scopeName : string ,
189
+ matchType : MatchType ,
190
+ document : vscode . TextDocument ) {
191
+ const result = [ ] ;
192
+ let startToken ;
193
+
194
+ tokens . forEach ( ( token , index ) => {
195
+ if ( token . scopes . includes ( scopeName ) ) {
196
+ if ( startToken === undefined ) { startToken = token ; }
197
+
198
+ // If we're at the end of the token list, or the next token does not include the scopeName
199
+ // we've reached the end of the contiguous block.
200
+ if ( ( ( index + 1 ) >= tokens . length ) || ( ! tokens [ index + 1 ] . scopes . includes ( scopeName ) ) ) {
201
+ result . push ( new MatchedToken ( startToken , token , null , null , matchType , document ) ) ;
202
+ startToken = undefined ;
203
+ }
204
+ }
205
+ } ) ;
206
+
207
+ return result ;
208
+ }
209
+
185
210
// Given a list of tokens, return a list of matched tokens/line numbers regions
186
211
private matchGrammarTokens ( tokens , document : vscode . TextDocument ) : IMatchedTokenList {
187
212
const matchedTokens = [ ] ;
@@ -200,6 +225,18 @@ export class FoldingProvider implements vscode.FoldingRangeProvider {
200
225
MatchType . Region , document )
201
226
. forEach ( ( x ) => { matchedTokens . push ( x ) ; } ) ;
202
227
228
+ // Find contiguous here strings @' -> '@
229
+ this . matchContiguousScopeElements ( tokens ,
230
+ "string.quoted.single.heredoc.powershell" ,
231
+ MatchType . Region , document )
232
+ . forEach ( ( x ) => { matchedTokens . push ( x ) ; } ) ;
233
+
234
+ // Find contiguous here strings @" -> "@
235
+ this . matchContiguousScopeElements ( tokens ,
236
+ "string.quoted.double.heredoc.powershell" ,
237
+ MatchType . Region , document )
238
+ . forEach ( ( x ) => { matchedTokens . push ( x ) ; } ) ;
239
+
203
240
return matchedTokens ;
204
241
}
205
242
0 commit comments