File tree Expand file tree Collapse file tree 2 files changed +14
-16
lines changed Expand file tree Collapse file tree 2 files changed +14
-16
lines changed Original file line number Diff line number Diff line change @@ -467,6 +467,17 @@ namespace ts {
467
467
return result ;
468
468
}
469
469
470
+ export function flatMapIter < T , U > ( iter : Iterator < T > , mapfn : ( x : T ) => U [ ] | undefined ) : U [ ] {
471
+ const result : U [ ] = [ ] ;
472
+ while ( true ) {
473
+ const { value, done } = iter . next ( ) ;
474
+ if ( done ) break ;
475
+ const res = mapfn ( value ) ;
476
+ if ( res ) result . push ( ...res ) ;
477
+ }
478
+ return result ;
479
+ }
480
+
470
481
/**
471
482
* Maps an array. If the mapped value is an array, it is spread into the result.
472
483
* Avoids allocation if all elements map to themselves.
Original file line number Diff line number Diff line change @@ -33,22 +33,9 @@ namespace ts {
33
33
refactors . set ( refactor . name , refactor ) ;
34
34
}
35
35
36
- export function getApplicableRefactors ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
37
- let results : ApplicableRefactorInfo [ ] ;
38
- const refactorList : Refactor [ ] = [ ] ;
39
- refactors . forEach ( refactor => {
40
- refactorList . push ( refactor ) ;
41
- } ) ;
42
- for ( const refactor of refactorList ) {
43
- if ( context . cancellationToken && context . cancellationToken . isCancellationRequested ( ) ) {
44
- return results ;
45
- }
46
- const infos = refactor . getAvailableActions ( context ) ;
47
- if ( infos && infos . length ) {
48
- ( results || ( results = [ ] ) ) . push ( ...infos ) ;
49
- }
50
- }
51
- return results ;
36
+ export function getApplicableRefactors ( context : RefactorContext ) : ApplicableRefactorInfo [ ] {
37
+ return flatMapIter ( refactors . values ( ) , refactor =>
38
+ context . cancellationToken && context . cancellationToken . isCancellationRequested ( ) ? [ ] : refactor . getAvailableActions ( context ) ) ;
52
39
}
53
40
54
41
export function getEditsForRefactor ( context : RefactorContext , refactorName : string , actionName : string ) : RefactorEditInfo | undefined {
You can’t perform that action at this time.
0 commit comments