intellij: IntellIJ doesn't recognize generated grpc/protobuf for golang
Sorry for what is a very similar issue to the ones for Java & Python. Not sure if I’m doing something wrong, but IntelliJ won’t recognize protobuf-generated types in my go projeccts.
I have an example project that is open source: https://github.com/kopeio/etcd-manager/blob/master/pkg/apis/etcd/BUILD.bazel
For reference:
proto_library(
name = "etcd_proto",
srcs = ["etcdapi.proto"],
visibility = ["//visibility:public"],
)
go_grpc_library(
name = "etcd_go_proto",
importpath = "kope.io/etcd-manager/pkg/apis/etcd",
proto = ":etcd_proto",
visibility = ["//visibility:public"],
)
Not sure if I’m not setting up my project correctly in IntelliJ (GOPATHs? Marking as generated sources?) The workaround I’ve found is to symlink to ./bazel-bin/pkg/apis/etcd/etcd_go_proto~/kope.io/etcd-manager/pkg/apis/etcd/etcdapi.pb.go
.
Any better suggestions appreciated! Or if this should “just work” let me know if I can provide more diagnostic information.
Go plugin version: 173.3727.144 Bazel plugin version: 2017.11.20.0.4 Bazel version: 0.8.1 IntelliJ version: IU-173.4127.27 (aka 2017.3.2)
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 17
- Comments: 23
While creating an example project (https://github.com/vanti-public/ijwb_194) I stumbled across the cause of the issue: Vgo support.
Turning vgo support off in the IDE allows the generated proto files to resolve as expected. Turning it on causes the issues I’ve been having.
Hi! This seems to still be an issue unfortunately. As folks mentioned earlier this seems to stem from a conflict with GoLand’s Go Modules support, and turning support for it does in fact get rid of the issue. However, that creates another issue. Because Go Modules support is turned off GoLand doesn’t pick up any new modules if you update the
go.mod
file (a workaround seems to be to toggle go modules support, but that’s less than ideal!).I’m not familiar enough with how the plugin system works to fix it, but if someone can coach me through it I’m happy to work on a fix!
Update:
I added a comment in https://youtrack.jetbrains.com/issue/GO-9040#focus=Comments-27-4879464.0-0 because I’m assuming it’s IntelliJ’s Go Modules integration that is breaking this. I have also created an up-to-date repro at https://github.com/iamricard/goland-bazel-mods-repro.
Also, none of the fixes/patches above fix this issue. I think this is because the
go mod
integration is the culprit here. My assumptions is they’d need to expose something that would let the bazel plugin list the generated files as part of the module.I have little experience with both Go and this plugin, but managed to get generated
proto_library
files included using GoSource. Is this commit somewhere along the lines of what you had in mind @chaoren?actually another workaround is setting a $GOPATH and creating the “generated” files into the protobuf. I currently “play” with bazel and do not use a $GOPATH at all, but have it set to a completly different path than my project and generate the protos there for syntax highlighting. intellij with goglang will detect it than.