p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
119 stars 7 forks source link

Refactor Idea: Replace usages with const declaration #45

Open hediet opened 1 year ago

hediet commented 1 year ago

Replace usages with const declaration, when the cursor is at the const declaration.

image

lgrammel commented 1 year ago

Nice idea! For my understanding, how would this be different from inline variable?

hediet commented 1 year ago

It is the opposite direction: I want to replace all duplicate expressions with the const at the cursor.

lgrammel commented 1 year ago

Ah I see, this would be useful!

In the meantime, you can achieve the same by combining the following refactorings:

  1. Extract the right hand side of the const into a new variable (here: top + height - checkBoxHeight - margin)
  2. Inline the original const (here: bottomBoundary)
  3. Rename the new variable to the name of the original const (here: to bottomBoundary)
lgrammel commented 1 year ago

Just realized that one variant of the refactoring already exists, you should be able to go over top + height - checkboxHeight - margin and use "Replace with existing variable": https://p42.ai/documentation/code-assist/replace-expression-with-existing-variable

hediet commented 1 year ago

Just realized that one variant of the refactoring already exists, you should be able to go over top + height - checkboxHeight - margin and use "Replace with existing variable": https://p42.ai/documentation/code-assist/replace-expression-with-existing-variable

Then I can also just use copy&paste.