DevLoop for Go + Import + Bazel Deps

158 views
Skip to first unread message

Scott Greenup

unread,
Oct 19, 2022, 9:00:46 PM10/19/22
to bazel-discuss
Hi everyone,

Thanks for taking the time to read this.

I'm looking for help in improving the development loop for the following setup (which I'm happy to change) for the following actions. My problem is around the in-efficiency importing a new dependency in Go.

The setup:

* I'm using Go.
* I'm using Bazel to manage dependencies and build.
* I'm using Gazelle to generate Bazel files and update dependencies from `go.mod`.
* I'm using IntelliJ with the Bazel plugin.

The current development loop to import something (that already has a dependency in our WORKSPACE):

1. I have to use the import first in the Go file (so IntelliJ doesn't remove it).
2. I have to then import manually in the Go file (because IntelliJ + Bazel Plugin doesn't know it exists).
3. Then, run `gazelle` to update the build files, which will update the build file for the Go file we are editing. It will add the dependency for us.
4. Then, in Intellij, run "Menu Bar > Bazel > Sync > Sync Project with BUILD files". This allows IntelliJ to know about the import via the BUILD.bazel file. Therefore allowing me to have auto-completion and documentation.

If we don't have the dependency, we can add two steps between 2 & 3, which I'll add the full method here:

1. I have to use the import first in the Go file (so IntelliJ doesn't remove it).
2. I have to then import manually in the Go file (because IntelliJ + Bazel Plugin doesn't know it exists).
3. I can then `go get ...`, I could've done this first, but it doesn't matter.
4. Then, run `gazelle update-repos` to update `deps.bzl`, which is all of my deps which is imported into my WORKSPACE.
5. Then, run `gazelle` to update the build files, which will update the build file for the Go file we are editing. It will add the dependency for us.
6. Then, in Intellij, run "Menu Bar > Bazel > Sync > Sync Project with BUILD files". This allows IntelliJ to know about the import via the BUILD.bazel file. Therefore allowing me to have auto-completion and documentation.

Usually, I can just start using the import in IntelliJ and it will auto-import it for me. I'm wondering if there is anything I can do to get closer to that user experience... it's a lot slower and a lot more tedious at the moment.

I've tried finding something, but nothing yet. I'll report back if I do find something.

Thank you and kind regards,
Scott

ツ Sven Tiffe

unread,
Oct 20, 2022, 3:49:42 AM10/20/22
to Scott Greenup, Radhika Advani, bazel-discuss, intellij-b...@googlegroups.com
+intellij-b...@googlegroups.com for visibility (although most members might be on -discuss as well)

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/74ff19b6-1e8f-47c9-8eef-adbc305f894fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages