cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 127 forks source link

[Fixes #19] Correctly handle package renaming #20

Closed falun closed 4 years ago

falun commented 8 years ago

Problem: tl;dr—Previously the generation approach was just to ignore all import statements and let goimports generate the correct import block. This mostly worked but broke down in the case of an import being renamed.

Described more thoroughly in #19.

Solution: The naive approach was to just pull out the imports on the first pass then reinsert them in an import ( ... ) block at the top but that fails in the case that imports were done as a series of import "..." statements. This change collects all imports for each pass through the file (meaning duplicates will be found in the case of multiple type assignments) then reconstructs the file before passing to imports.Process.

I added a test for the broken case this change resolves and updated the test where this changes output.

boz commented 7 years ago

The failing test is unrelated to this PR and was fixed in #22.

matoous commented 5 years ago

Hey @falun , can you please rebase it? We are seeing the same problem and would love this MR to be merged.