@@ -252,6 +252,40 @@ export class FoldingProvider implements vscode.FoldingRangeProvider {
252
252
return result ;
253
253
}
254
254
255
+ /**
256
+ * Given a textmate scope name, find a series of contiguous tokens which contain
257
+ * that scope name and pair them together.
258
+ * @param tokens List of grammar tokens to parse
259
+ * @param scopeName The name of the scope to match
260
+ * @param matchType The type of range this region represents e.g. A comment
261
+ * @param document The source text document
262
+ * @returns A list of LineNumberRange objects of the contiguous token scopes
263
+ */
264
+ private matchContiguousScopeElements (
265
+ tokens : ITokenList ,
266
+ scopeName : string ,
267
+ matchType : vscode . FoldingRangeKind ,
268
+ document : vscode . TextDocument ,
269
+ ) : ILineNumberRangeList {
270
+ const result = [ ] ;
271
+ let startToken ;
272
+
273
+ tokens . forEach ( ( token , index ) => {
274
+ if ( token . scopes . indexOf ( scopeName ) !== - 1 ) {
275
+ if ( startToken === undefined ) { startToken = token ; }
276
+
277
+ // If we're at the end of the token list, or the next token does not include the scopeName
278
+ // we've reached the end of the contiguous block.
279
+ if ( ( ( index + 1 ) >= tokens . length ) || ( tokens [ index + 1 ] . scopes . indexOf ( scopeName ) === - 1 ) ) {
280
+ result . push ( ( new LineNumberRange ( matchType ) ) . fromTokenPair ( startToken , token , document ) ) ;
281
+ startToken = undefined ;
282
+ }
283
+ }
284
+ } ) ;
285
+
286
+ return result ;
287
+ }
288
+
255
289
/**
256
290
* Given a list of tokens, return a list of line number ranges which could be folding regions in the document
257
291
* @param tokens List of grammar tokens to parse
@@ -280,6 +314,20 @@ export class FoldingProvider implements vscode.FoldingRangeProvider {
280
314
vscode . FoldingRangeKind . Region , document )
281
315
. forEach ( ( match ) => { matchedTokens . push ( match ) ; } ) ;
282
316
317
+ // Find contiguous here strings @' -> '@
318
+ this . matchContiguousScopeElements (
319
+ tokens ,
320
+ "string.quoted.single.heredoc.powershell" ,
321
+ vscode . FoldingRangeKind . Region , document )
322
+ . forEach ( ( match ) => { matchedTokens . push ( match ) ; } ) ;
323
+
324
+ // Find contiguous here strings @" -> "@
325
+ this . matchContiguousScopeElements (
326
+ tokens ,
327
+ "string.quoted.double.heredoc.powershell" ,
328
+ vscode . FoldingRangeKind . Region , document )
329
+ . forEach ( ( match ) => { matchedTokens . push ( match ) ; } ) ;
330
+
283
331
return matchedTokens ;
284
332
}
285
333
}
0 commit comments