@@ -9,16 +9,16 @@ import {
99} from '../utils'
1010
1111export const processApplicableRefactors = (
12- refactor : ts . ApplicableRefactorInfo | undefined ,
12+ refactorActions : ts . RefactorActionInfo [ ] | undefined ,
1313 c : GetConfig ,
1414 posOrRange : number | ts . TextRange ,
1515 sourceFile : ts . SourceFile ,
1616) => {
17- if ( ! refactor ) return
18- const functionExtractors = refactor ?. actions . filter ( ( { notApplicableReason } ) => ! notApplicableReason )
17+ if ( ! refactorActions ) return
18+ const functionExtractors = refactorActions . filter ( ( { notApplicableReason } ) => ! notApplicableReason )
1919 if ( functionExtractors ?. length ) {
2020 const kind = functionExtractors [ 0 ] ! . kind !
21- const blockScopeRefactor = functionExtractors . find ( e => e . description . startsWith ( 'Extract to inner function in ') )
21+ const blockScopeRefactor = functionExtractors . find ( e => e . description . includes ( ' inner function') )
2222 const addArrowCodeActions : ts . RefactorActionInfo [ ] = [ ]
2323 if ( blockScopeRefactor ) {
2424 addArrowCodeActions . push ( {
@@ -28,9 +28,7 @@ export const processApplicableRefactors = (
2828 } )
2929 }
3030 let addExtractToJsxRefactor = false
31- const globalScopeRefactor = functionExtractors . find ( e =>
32- [ 'Extract to function in global scope' , 'Extract to function in module scope' ] . includes ( e . description ) ,
33- )
31+ const globalScopeRefactor = functionExtractors . at ( - 1 )
3432 if ( globalScopeRefactor ) {
3533 addArrowCodeActions . push ( {
3634 description : 'Extract to arrow function in global scope above' ,
@@ -42,16 +40,20 @@ export const processApplicableRefactors = (
4240 }
4341
4442 if ( addExtractToJsxRefactor ) {
45- refactor . actions = refactor . actions . filter ( action => ! action . name . startsWith ( 'function_scope' ) )
46- refactor . actions . push ( {
43+ for ( const refactorAction of refactorActions ) {
44+ if ( refactorAction . name . startsWith ( 'function_scope' ) ) {
45+ refactorAction . notApplicableReason = 'JSX Element Selected. Use Extract to JSX component'
46+ }
47+ }
48+ refactorActions . push ( {
4749 description : 'Extract to JSX component' ,
4850 kind : 'refactor.extract.jsx' ,
4951 name : `${ globalScopeRefactor ! . name } _jsx` ,
5052 } )
5153 return
5254 }
5355
54- refactor . actions . push ( ...addArrowCodeActions )
56+ refactorActions . push ( ...addArrowCodeActions )
5557 }
5658}
5759
0 commit comments