You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactors, like 'move to a new file', butchers formatting by removing empty lines in code. As refactors are meant to improve code style and structure, I should not manually have to reformat my code after I've applied one.
TypeScript Version: 3.1.0-dev.20180922
Search Terms:
Move to new file removes newlines, refactor removes newlines, removes whitespace, removes trivia
This really is super annoying, so much that the much awaited "Move to new file" is practically useless - I prefer cutting & pasting manually to preserve formatting..
How large of a job is this to fix? Is it something that is doable for a one-time-contributor or would one need a deep understanding of parser, AST and emitter?
Ryan Cavanaugh (@RyanCavanaugh) spoke offline with Matt Bierner (@mjbvz) and I - while this doesn't seem like the desired behavior, this is going to involve a larger amount of work than it might seem since we're not equipped in our current refactoring machinery.
It really is too bad, since "the editor understanding and working with the code" is one of the selling points for typescript over javascript, at least for me. Great refactoring support is where typescript could really shine.
That is a correct-ish reading of the fix, but the example you just provided is really all about newlines. That said, this example works horribly in my branch, exposing some bugs in the implementation, so I’ll incorporate this as a test case.
Andrew Branch (@andrewbranch) Yeah, kind of realized after I posted, but there is also indentation and the added newlines in the function parameters. Glad I could provide a test case. Is it possible for me to try your branch with VS Code refactorings?
Does this PR handle this issue? I used TS 3.9 as Matt Bierner (@mjbvz) recommended in this comment, the empty lines issue is solved, but the moving to the next line isn't.
Activity
markusjohnsson commentedon Jul 26, 2019
This really is super annoying, so much that the much awaited "Move to new file" is practically useless - I prefer cutting & pasting manually to preserve formatting..
How large of a job is this to fix? Is it something that is doable for a one-time-contributor or would one need a deep understanding of parser, AST and emitter?
2 remaining items
cinderblock commentedon Jan 23, 2020
An adequate shortcut I've found is to add two simple steps:
This leaves the minor problem of whitespace preservation around
imports.DanielRosenwasser commentedon Jan 23, 2020
Ryan Cavanaugh (@RyanCavanaugh) spoke offline with Matt Bierner (@mjbvz) and I - while this doesn't seem like the desired behavior, this is going to involve a larger amount of work than it might seem since we're not equipped in our current refactoring machinery.
markusjohnsson commentedon Jan 24, 2020
Daniel Rosenwasser (@DanielRosenwasser) does that mean that it's not going to happen?
It really is too bad, since "the editor understanding and working with the code" is one of the selling points for typescript over javascript, at least for me. Great refactoring support is where typescript could really shine.
DanielRosenwasser commentedon Jan 24, 2020
No, I didn't mean to imply it wasn't going to happen, just that it's not happening in 3.8.
markusjohnsson commentedon Mar 6, 2020
I want to note that refactors not only removes blank lines, but alters other whitespace as well:
Before:
After (move to a new file):
If I'm reading the proposed fix correctly, it will only provide newlines. Other formatting will still get lost.
andrewbranch commentedon Mar 6, 2020
That is a correct-ish reading of the fix, but the example you just provided is really all about newlines. That said, this example works horribly in my branch, exposing some bugs in the implementation, so I’ll incorporate this as a test case.
markusjohnsson commentedon Mar 8, 2020
Andrew Branch (@andrewbranch) Yeah, kind of realized after I posted, but there is also indentation and the added newlines in the function parameters. Glad I could provide a test case. Is it possible for me to try your branch with VS Code refactorings?
minestarks commentedon Mar 11, 2020
FYI Jesse Trinity (@jessetrinity) working on a related class of bugs
AbdelrahmanHafez commentedon Apr 26, 2020
becomes
Does this PR handle this issue? I used TS 3.9 as Matt Bierner (@mjbvz) recommended in this comment, the empty lines issue is solved, but the moving to the next line isn't.
Should I create a new issue with this?
DanielRosenwasser commentedon Apr 26, 2020
Please try out https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-next and file a separate issue with repro steps if that doesn't fix it.