11import * as vscode from 'vscode'
2- import { registerExtensionCommand } from 'vscode-framework'
2+ import { getExtensionSetting , registerExtensionCommand } from 'vscode-framework'
3+ import { Utils } from 'vscode-uri'
34
45export default ( ) => {
56 registerExtensionCommand ( 'reactAwareRename' , async ( _ , { execCommand = true } : { execCommand ?: boolean | string } = { } ) => {
@@ -12,12 +13,22 @@ export default () => {
1213 const definitions : vscode . LocationLink [ ] = await vscode . commands . executeCommand ( 'vscode.executeDefinitionProvider' , document . uri , pos )
1314 const definition = definitions [ 0 ]
1415 if ( ! definition || definition . targetUri . toString ( ) !== document . uri . toString ( ) ) return false
15- const { targetRange } = definition
16+ let { targetRange, targetSelectionRange } = definition
17+ if ( targetSelectionRange ) targetRange = targetSelectionRange
1618 // multiline isn't supported by design
1719 if ( targetRange . start . line !== targetRange . end . line ) return false
1820 const lineText = document . lineAt ( targetRange . end ) . text
1921 const useStatePatternMatch = / \s * c o n s t \[ ( .+ ) , s e t \1] = / i. exec ( lineText )
20- if ( ! useStatePatternMatch ) return false
22+ if ( ! useStatePatternMatch ) {
23+ const fileName = Utils . basename ( document . uri ) . replace ( / \. .+ $ / , '' )
24+ if ( getExtensionSetting ( 'reactAware.autoTriggerRenameComponent' ) && document . getText ( targetRange ) === fileName ) {
25+ await vscode . commands . executeCommand ( 'extraCommands.renameSymbolAndFile' )
26+ return true
27+ }
28+
29+ return false
30+ }
31+
2132 const newName = await vscode . window . showInputBox ( { value : useStatePatternMatch [ 1 ] } )
2233 if ( newName === undefined ) return
2334 const mainEdit : vscode . WorkspaceEdit = await vscode . commands . executeCommand (
0 commit comments