-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Comments on directives are lost when running Organize Imports #42515
Comments
I suspect that one of the reasons this hasn't been implemented well is because of the difficulty of getting the right heuristics. My opinion is that we should use the following heuristics:
I can't think of any other special cases that might need to be addressed, but I'm sure we'll find or hear about some. (Unfortunately for me, this code doesn't appear to be shared with the "sort members" feature. Perhaps if we fix this code someone can look at sharing the code between the two features.) |
(We really should allow |
It would be good to allow |
🎉 Thanks @jonas-jonas! |
Given the code:
If you sort it, the comment is removed:
@bwilkerson I think this is because this code works by replacing the whole block of directives with a newly computed one, but it only captures end-of-line comments when it builds the new text:
sdk/pkg/analysis_server/lib/src/services/correction/organize_directives.dart
Lines 68 to 76 in 93313eb
I think it could be easily extended to also capture preceding comments, however it might go bad if there's a "file header" comment before it:
Some thoughts on fixing it:
// ignore
comments (this might not solve the whole problem - eg. if the user added an explanatory comment to an import -// we're using this until the new library is ready
).What do you think?
The text was updated successfully, but these errors were encountered: