cloudspannerecosystem / yo

yo is a command-line tool to generate Go code for Google Cloud Spanner.
MIT License
312 stars 52 forks source link

Implement a package registry #109

Closed shuheiktgw closed 9 months ago

shuheiktgw commented 1 year ago

Currently, golang.org/x/tools/imports manages to import proper go packages in generated files, and it works in most cases. However, it has certain limitations. For example, if users specify civil.Date golang.org/x/tools/imports cannot tell if they try to use cloud.google.com/go/civil or github.com/golang-sql/civil for sure.

Instead of leaving it to golang.org/x/tools/imports, this PR implements a package registry that imports an appropriate package based on fields of Spanner tables. I'll implement the following features once this PR gets merged.

kazegusuri commented 1 year ago

You should regenerate test files. I think there will be the unexpected differences. (I'm not sure why CI didn't warn it)

shuheiktgw commented 1 year ago

@kazegusuri I've updated the PR to import packages on demand, which means packages are imported if they are actually used in the file. I'll leave some follow-up comments below. Would you review the PR again? 🙏

shuheiktgw commented 9 months ago

I'm closing this issue for now since we must reconsider the interface.