@@ -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 = [ ] ;
@@ -202,6 +227,20 @@ export class FoldingProvider implements vscode.FoldingRangeProvider {
202
227
MatchType . Region , document )
203
228
. forEach ( ( match ) => { matchedTokens . push ( match ) ; } ) ;
204
229
230
+ // Find contiguous here strings @' -> '@
231
+ this . matchContiguousScopeElements (
232
+ tokens ,
233
+ "string.quoted.single.heredoc.powershell" ,
234
+ MatchType . Region , document )
235
+ . forEach ( ( match ) => { matchedTokens . push ( match ) ; } ) ;
236
+
237
+ // Find contiguous here strings @" -> "@
238
+ this . matchContiguousScopeElements (
239
+ tokens ,
240
+ "string.quoted.double.heredoc.powershell" ,
241
+ MatchType . Region , document )
242
+ . forEach ( ( match ) => { matchedTokens . push ( match ) ; } ) ;
243
+
205
244
return matchedTokens ;
206
245
}
207
246
0 commit comments