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 {
467467 return result ;
468468 }
469469
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+
470481 /**
471482 * Maps an array. If the mapped value is an array, it is spread into the result.
472483 * Avoids allocation if all elements map to themselves.
Original file line number Diff line number Diff line change @@ -33,22 +33,9 @@ namespace ts {
3333 refactors . set ( refactor . name , refactor ) ;
3434 }
3535
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 ) ) ;
5239 }
5340
5441 export function getEditsForRefactor ( context : RefactorContext , refactorName : string , actionName : string ) : RefactorEditInfo | undefined {
You can’t perform that action at this time.
0 commit comments