xsburg / vscode-javascript-booster

Sprinkle extra refactorings, code actions and commands over your JavaScript! 🍩 TypeScript and Flow are first class citizens as well!
https://marketplace.visualstudio.com/items?itemName=sburg.vscode-javascript-booster
160 stars 13 forks source link

Feature Request: Inline usage(s) #22

Open maricn opened 4 years ago

maricn commented 4 years ago

I find inline refactoring very useful (coming from IntelliJ world: https://www.jetbrains.com/help/idea/inline.html).

before:

method() {
    const number = anotherClass.intValue();
    const b = a + number;
}

after:

method() {
    const b = a + anotherClass.intValue();
}

could be done with objects, statements and functions.

xsburg commented 4 years ago

Hi @maricn,

That's a good idea for a refactoring!

I need however to do some additional research to see what would be the best place to implement this feature.

This refactoring requires to have the information about variables in the current scope and also locate all the usages in order to inline them. Right now what we operate with is just a bare syntax tree (that's enough for most code fixes).

On the other hand, the TypeScript compiler team has a way to provide JavaScript (not only TypeScript) refactorings using the TypeScript services. It might be worth investigating for this feature because they have way more information about the code since they have the compiler at their disposal.

I will do the research and find a better way to go forward.

Thanks for reporting!