Closed donovanrost closed 2 years ago
Hey @donovanrost! I just tried running those commands and unfortunately I'm not able to reproduce the error you mentioned above.
Can you share what's in your controllers/
directory? Function bodies aren't necessary if its private code. I bet that will point to the root cause.
@matthewmueller I just created a new project and ran those generators to reproduce.
Under controllers/
I have:
academies/controller.go
associations/controller.go
associations/academies/controller.go
I'm not sure what you mean by:
Function bodies aren't necessary if its private code. I bet that will point to the root cause.
Hmm, okay. Can you try again and make sure you're on the latest?
$ bud version
bud: 0.1.7
svelte: 3.47.0
react: 18.0.0
I also just ran those 3 commands:
bud new controller associations index show
bud new controller academies index show
bud new controller associations/academies index show
But it was working for me when I ran bud run
. If you're able to reproduce, please post exact steps and I'll have another look!
@matthewmueller I emailed you a video of me reproducing the issue. I hope that's ok
I got the same issue on linux
# 1/bud/.app/controller
bud/.app/controller/controller.go:7:2: imported and not used: "1/controller/associations/academies" as academies1
| exit status 2
I'm able to reproduce this now! Definitely a bug.
The problem is that the following should refer to academies1
, not academies
.
func loadAssociationsAcademiesController() *academies.Controller {
academiesController := &academies.Controller{}
return academiesController
}
This happens because these generated functions are unaware of previous functions. The previous function is already using the acadamies package, so this one needs to use the academies1 package.
I think the solution is to allow the dependency injection provider to change import names after wiring but before generating code. This would allow the generator to take into account existing imports.
Maybe something like this:
// Add generated imports
for i, imp := range provider.Imports {
provider.Imports[i].Name = l.imports.Add(imp.Path)
}
Unfortunately, this doesn't work yet. package/di
would need to be adjusted.
In the meantime, avoiding duplicate package names in the controller/
directory is the workaround.
I ran:
This laid out out the appropriate controllers in the /controller directory. However, I'm getting an error
looking at bud/.app/controller/controller.go, we can see that
bud-test/controller/associations/academies
is imported at asacademies1
but that import isn't used. I can't delete it because the framework automatically generates it again.Is there a correct way to create nested controllers like this?