@@ -9,16 +9,16 @@ import {
9
9
} from '../utils'
10
10
11
11
export const processApplicableRefactors = (
12
- refactor : ts . ApplicableRefactorInfo | undefined ,
12
+ refactorActions : ts . RefactorActionInfo [ ] | undefined ,
13
13
c : GetConfig ,
14
14
posOrRange : number | ts . TextRange ,
15
15
sourceFile : ts . SourceFile ,
16
16
) => {
17
- if ( ! refactor ) return
18
- const functionExtractors = refactor ?. actions . filter ( ( { notApplicableReason } ) => ! notApplicableReason )
17
+ if ( ! refactorActions ) return
18
+ const functionExtractors = refactorActions . filter ( ( { notApplicableReason } ) => ! notApplicableReason )
19
19
if ( functionExtractors ?. length ) {
20
20
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') )
22
22
const addArrowCodeActions : ts . RefactorActionInfo [ ] = [ ]
23
23
if ( blockScopeRefactor ) {
24
24
addArrowCodeActions . push ( {
@@ -28,9 +28,7 @@ export const processApplicableRefactors = (
28
28
} )
29
29
}
30
30
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 )
34
32
if ( globalScopeRefactor ) {
35
33
addArrowCodeActions . push ( {
36
34
description : 'Extract to arrow function in global scope above' ,
@@ -42,16 +40,20 @@ export const processApplicableRefactors = (
42
40
}
43
41
44
42
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 ( {
47
49
description : 'Extract to JSX component' ,
48
50
kind : 'refactor.extract.jsx' ,
49
51
name : `${ globalScopeRefactor ! . name } _jsx` ,
50
52
} )
51
53
return
52
54
}
53
55
54
- refactor . actions . push ( ...addArrowCodeActions )
56
+ refactorActions . push ( ...addArrowCodeActions )
55
57
}
56
58
}
57
59
0 commit comments