Open falun opened 8 years ago
To update -- I implemented suggestion solution 2 and it totally works! ... Except in the case where you have multiple type completions (because the second pass through the imports break imports.Process
since you shouldn't have imports in the middle of code).
I believe a modified version of 2 will work if you strip the imports only on pass >1; will take a shot at that soonish.
Problem
If your genny templates include renamed imports they'll be incorrectly removed from the output. Initially I thought this was a bug in
imports.Parse
but when runninggoimports
(which I believe uses theimports
lib as it's backend) i don't see the same behavior.I think what's going on is that because
genny
passes the generated code intoimports.Parse
without any imports included the renamed packages aren't able to resolve.Repro case genny-test
Possible solution
-trustImports
which will bypass the import processing fromimports
; I've made this modification locally and it works well enough. Two issues with it a) you lose the implicit formatting thatimports
does for you b) it doesn't remove thegeneric
import that you pick up from your template. I'm side stepped (b) by not compiling my templates and just leaving thegeneric
import out.imports.Process
. I think this should letimports
do its thing withoutgenny
intervention.I know 1 works, I didn't bother trying 2 as I found a suitable work around for my case.
Work around
Since 1 & 2 both require library changes some work arounds for anyone else that may hit this
package $name
differs from directory); this may necessitate changes in other places the package is imported but often works...genny
and implement solution 1 or 2 (and provide a PR 😀)