@@ -100,14 +100,17 @@ export const handleFunctionRefactorEdits = (
100
100
const oldFunctionText = functionChange . newText
101
101
const sourceFile = languageService . getProgram ( ) ! . getSourceFile ( fileName ) !
102
102
if ( actionName . endsWith ( '_jsx' ) ) {
103
+ // refactor.extract.jsx implementation
103
104
const lines = oldFunctionText . trimStart ( ) . split ( '\n' )
104
105
const oldFunctionSignature = lines [ 0 ] !
105
106
const componentName = tsFull . getUniqueName ( 'ExtractedComponent' , sourceFile as unknown as FullSourceFile )
106
- const newFunctionSignature = changeArgumentsToDestructured ( oldFunctionSignature , formatOptions , sourceFile , componentName )
107
-
108
107
const insertChange = textChanges . at ( - 2 ) !
109
- let args = insertChange . newText . slice ( 1 , - 2 )
110
- args = args . slice ( args . indexOf ( '(' ) + 1 )
108
+ const args = insertChange . newText . slice ( insertChange . newText . indexOf ( '(' ) + 1 , insertChange . newText . lastIndexOf ( ')' ) )
109
+
110
+ const newFunctionSignature = changeArgumentsToDestructured ( oldFunctionSignature , formatOptions , sourceFile , componentName ) . replace ( '{}: {}' , '' )
111
+
112
+ const oldSpan = sourceFile . text . slice ( 0 , functionChange . span . start ) . length
113
+
111
114
const fileEdits = [
112
115
{
113
116
fileName,
@@ -130,11 +133,17 @@ export const handleFunctionRefactorEdits = (
130
133
] ,
131
134
} ,
132
135
]
136
+ const diff = fileEdits [ 0 ] ! . textChanges . slice ( 0 , - 1 ) . reduce ( ( diff , { newText, span } ) => {
137
+ const oldText = sourceFile . text . slice ( span . start , span . start + span . length )
138
+ const newSpan = newText . length
139
+ const oldSpan = oldText . length
140
+ diff += newSpan - oldSpan
141
+ return diff
142
+ } , 0 )
133
143
return {
134
144
edits : fileEdits ,
135
145
renameFilename,
136
- renameLocation : insertChange . span . start + 1 ,
137
- // renameLocation: tsFull.getRenameLocation(fileEdits, fileName, componentName, /*preferLastLocation*/ false),
146
+ renameLocation : functionChange . span . start + diff ,
138
147
}
139
148
}
140
149
0 commit comments