Skip to content

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Aug 15, 2020

This PR adds a simple heuristic to AttachFileToModuleFix that tries to find a good place where to insert the mod item. If it finds an existing mod items in the file, it will append the new item after the last one. Otherwise, it will skip comments and attributes at the beginning of the module.

If there was a mod item before an attribute in the target module, it could still fail to compile after the fix, but in such case it would also fail to compile before the fix, so I think that is an edge case that we don't have to deal with.

I copied the firstItem implementation and changed it slightly so that it also works for empty modules. I can also check if the module is empty and do not use firstItem in such case.

Fixes: #5903
Fixes: #5934

@Kobzol Kobzol added the fix Pull requests that fix some bug(s) label Aug 15, 2020
@Kobzol Kobzol requested a review from Undin August 15, 2020 17:01
@Undin Undin self-assigned this Aug 17, 2020
@Undin Undin added this to the v129 milestone Aug 17, 2020
@Kobzol Kobzol force-pushed the insp-attach-mod-location-fix branch from 9d7551e to d543867 Compare August 17, 2020 14:32
Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
bors r+

@bors
Copy link
Contributor

bors bot commented Aug 17, 2020

Build succeeded:

@bors bors bot merged commit 6537a1e into intellij-rust:master Aug 17, 2020
@Kobzol Kobzol deleted the insp-attach-mod-location-fix branch August 18, 2020 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Pull requests that fix some bug(s)
Projects
None yet
2 participants