Closed hediet closed 1 year ago
Awesome, thanks for sharing the refactoring idea! This is somewhat similar to extract so it should be doable. How would you imagine the interaction, i.e. where would you want to trigger the refactoring?
Just realized that this is already possible with a refactoring combo:
flip(sourceNumber)
into e.g. targetNumber2
targetNumber
targetNumber2
to targetNumber
v1.112.0
now has a "replace with existing variable" refactoring that can be invoked on an expression. If there is a variable with the same expression, the expression will be replaced with the variable.
@hediet you said this would be a "second step after extracting a constant", which indicates to me that extract constant did not work as expected. The P42 extract constant should already extract all occurrences. Was there a specific case where the refactoring did not find all occurrences as expected?
The P42 extract constant should already extract all occurrences.
Oh, I was not aware of this. I used the typescript one, as it was suggested first I think. I really recommend hiding the obsolete typescript refactorings by default (and adding a setting to show them again)!
I really recommend hiding the obsolete typescript refactorings by default (and adding a setting to show them again)!
I agree, you convinced me this is the best way to proceed.
The typescript extract const
refactoring is not fully replaced by the JavaScript Assistant yet, I need to add an option to extract a single occurrence and to determine the target scope.
It would be awesome to have a refactoring that can replace expressions with a variable.
In this screenshot, I would like to replace all occurences of
flip(sourceNmbr)
withtargetNmbr
:This would basically be the second step after extracting a constant.