krizzdewizz / vscode-refactorix

TypeScript refactoring tools for Visual Studio Code
Apache License 2.0
19 stars 6 forks source link

Arrow function: bad formatting when converting from multiline single expression #9

Open OliverJAsh opened 7 years ago

OliverJAsh commented 7 years ago

Hey! First of all, thanks for this extension. I've longed for an arrow function refactoring like the one provided here. I've lost count of the number of times I've switched back and forth.

--

Given:

const foo = () => (
    1
);

If I use the refactoring to convert this single expression function to a block, I get:

const foo = () => {
        return (
    1
);
    };

Is there something we could do to fix the formatting here?

krizzdewizz commented 7 years ago

Hi, thanks. Glad that it's of use to you. Refactorix could invoke one of the two VS Code commands "Format Selection" / "Format Document" after a refactoring has been made. "Format Selection" is kind of hard to detect the new range and one has to alter the selection before invoking the command which could flicker. I suggest a new configurable Refactorix option "Format Document on Refactoring" (default is false to preserve backward compatibility). Would that suffice your needs?

OliverJAsh commented 7 years ago

@krizzdewizz When I read through the source code, it seemed like you were doing some work to retain indentation—I'm guessing this has limits though? I agree this is probably a job better handled by another tool.

I suggest a new configurable Refactorix option "Format Document on Refactoring" (default is false to preserve backward compatibility). Would that suffice your needs?

I think so. I use Prettier so that will just format the new function in addition to everything else, but there shouldn't be any changes elsewhere.

Maybe we should hang on to this and see what other people’s needs are.