You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 running goimports (which I believe uses the imports 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 into imports.Parse without any imports included the renamed packages aren't able to resolve.
Add -trustImports which will bypass the import processing from imports; I've made this modification locally and it works well enough. Two issues with it a) you lose the implicit formatting that imports does for you b) it doesn't remove the generic import that you pick up from your template. I'm side stepped (b) by not compiling my templates and just leaving the generic import out.
Don't strip imports from the cleaned output that gets passed into imports.Process. I think this should let imports do its thing without genny 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
Just stop renaming! If that's not possible...
declare your package imported as the name you're trying to use (i.e. package $name differs from directory); this may necessitate changes in other places the package is imported but often works...
add a non-generated file that references the things you need access to within the imported package (in limited cases this is sufficient).
and, lest we forget, fork genny and implement solution 1 or 2 (and provide a PR 😀)
The text was updated successfully, but these errors were encountered:
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 😀)The text was updated successfully, but these errors were encountered: