New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Organize imports moving imports before file header #22731
Comments
Technically, they're following the import they were attached to as it moves down the list of imports. Either way, the behavior is undesirable. |
This bug makes organize imports pretty unusable in the vscode code base. Not sure how many people will hit it as well. Can we please look into for 2.8.2 |
It seems like it should be sufficient to suppress leading trivia on the (old) first import declaration and then leave the surrounding trivia in place when replacing or deleting it. However, that doesn't seem to be working. It looks like |
@andy-ms @mhegazy if this rings any bells, please let me know. Otherwise, I'll keep stepping through the emitter until I figure out why those comments aren't being suppressed. If this is urgent, we do have a stopgap solution - we can suppress all comments in the import declarations and leave the header where it is. Then, organizing imports will delete interior and trailing comments, but not touch the header. This may be an improvement, in practice. |
@weswigham agrees that this is probably a known deficiency in the emitter - the leading comments on the |
When organizing imports, we used to move the leading and trailing trivia of each individual import with that import as it was repositioned or deleted. This had the unfortunate effect of repositioning or deleting the header comment of the file. Our new approach is to leave the leading trivia of the first import ahead of the resulting block of imports (i.e. it no longer follows the first import as it is repositioned or deleted). Trailing trivia on the first import and trivia on subsequent imports are treated as before. Caveat: We had to hack around emitter limitation microsoft#22831. Fixes microsoft#22723 Fixes microsoft#22724 Fixes microsoft#22731
TypeScript Version: 2.8.0-dev20180320
Search Terms:
Repo Steps
webview.ts
Bug:
Imports split around file header comment:
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: