# Golang intellisence issue for protobuf auto-generated go packages in a nakama-based solution using VSCode

**URL:** https://forum.heroiclabs.com/t/golang-intellisence-issue-for-protobuf-auto-generated-go-packages-in-a-nakama-based-solution-using-vscode/1109
**Category:** Local Setup
**Created:** [November 5, 2020, 7:05pm UTC](https://forum.heroiclabs.com/t/golang-intellisence-issue-for-protobuf-auto-generated-go-packages-in-a-nakama-based-solution-using-vscode/1109 "2020-11-05T19:05:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mahdad-Baghani](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mahdad-baghani/32/465_2.png) [@Mahdad-Baghani](https://forum.heroiclabs.com/u/Mahdad-Baghani)
#### Post date: [November 5, 2020, 7:05pm UTC](https://forum.heroiclabs.com/t/golang-intellisence-issue-for-protobuf-auto-generated-go-packages-in-a-nakama-based-solution-using-vscode/1109/1 "2020-11-05T19:05:29Z")

</div>

Hi there. First of all, I have to say that I am using the word “intellisence” to refer to code-completion, linting, code formatting, and stuff like that. I am using the setup env provided by @novabyte in [this gist](https://gist.github.com/novabyte/cc6d57022e2d3baa40e98d8fc91dc4c8), with a small difference that I am using version 2.14.1 of Nakama and Nakama-pluginbuilder, and Nakama-common v1.9.0 due to a bug in matchmaking I encountered during [upgrade from Nakama-common 1.4.0 to 1.8.0](https://forum.heroiclabs.com/t/upgrading-nakama-runtime/1095/10).  
I am using vscode-insiders 1.51.0 and the official Go plugin v0.18.1.  
we have a monolithic repository consisting of seperate directories for our unity client, backend, and protobuffers which are shared between the other two.

```auto
davaa/
├── Backend
├── Client
└── ProtoBuffers

```

```auto
// ./Backend/go.mod

module gitlab.com/mahdad-baghani/davaa

go 1.14

require (
	github.com/golang/protobuf v1.4.3
	github.com/heroiclabs/nakama-common v1.9.0
	google.golang.org/protobuf v1.25.0
)

```

here is one simple protobuf I defined:

```auto
// ./ProtoBuffers/netcode_message_buffers.proto
syntax = "proto3";
package netcode;

option go_package = "gitlab.com/mahdad-baghani/davaa/protobuffers;netcode_buffers";
option csharp_namespace="Davaa.ProtocolBuffers";

message MatchResultBuf {
    string winner = 1;
    string loser = 2;
    string sender = 3;
}

```

I compile protobufs to specific folders. In the case of my backend, its `./Backend/protobuffers/`. Up to now, everything is fine when it comes to “intellisence”. I have code completion, function signature tooltips, linter suggestions, error squigglies, etc. When I try to start my backend using `docker-compose -f my_yml.yml up --build nakama`, I get the following error:  
`match/match.go:10:2: cannot find package "." in: /backend/protobuffers`  
In line 10, I am importing my compiled protobuf package as following :

```auto
netcode_buffers "gitlab.com/mahdad-baghani/davaa/protobuffers"

```

I suspect that it has to do with my this specific line in my Dockerfile:

```auto
WORKDIR /backend

```

and

```auto
COPY --from=builder /backend/backend.so /nakama/data/modules

```

as the error indicates that the package was not found in ` /backend/protobuffers`.

I can compile by changing the `go_package` option in my protobuf definition by adding the `/Bakcend/ ` so it actually points to the physical file that exists on disk

```auto
option go_package = "gitlab.com/mahdad-baghani/davaa/Backend/protobuffers;netcode_buffers";

```

Now I can compile regardless of VS Code showing just one error: `cannot find package "gitlab.com/mahdad-baghani/davaa/protobuffers" in any of ...`. But, now, I cannot have intellisence if I want to use my type MatchResultBuf, or any other auto-generated types from protobuffer definitions for that matter.

What am I doing wrong?

```auto

```

---

<div class="post-metadata">

### Author: ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)
#### Post date: [November 5, 2020, 8:22pm UTC](https://forum.heroiclabs.com/t/golang-intellisence-issue-for-protobuf-auto-generated-go-packages-in-a-nakama-based-solution-using-vscode/1109/2 "2020-11-05T20:22:04Z")

</div>

@Mahdad-Baghani At a glance it looks like you might be misusing some paths.

> match/match.go:10:2: cannot find package “.” in: /backend/protobuffers

This one usually means there are no Go files in a given path. Make sure whenever you run `docker-compose up` you do so from the root of your backend code, not from within your protobuf package.

> cannot find package “[gitlab.com/mahdad-baghani/davaa/protobuffers](http://gitlab.com/mahdad-baghani/davaa/protobuffers)” in any of …

You’re trying to import `gitlab.com/mahdad-baghani/davaa/protobuffers` but you’ve defined your proto output package as `gitlab.com/mahdad-baghani/davaa/Backend/protobuffers`. There’s a missing/extra “Backend” in there.

Start by making sure your `go.mod`’s `module` directive is `"gitlab.com/mahdad-baghani/davaa"`, your proto files are in `Backend/protobuffers`, your proto `go_package` directive is `"gitlab.com/mahdad-baghani/davaa/protobuffers"`, and any imports for your proto stubs are `gitlab.com/mahdad-baghani/davaa/protobuffers`. Also make sure you clean up any running containers and delete existing images before you rebuild, just in case.

I’d also recommend avoiding mixed-case package names and/or directories where possible.

---

<div class="post-metadata">

### Author: ![Mahdad-Baghani](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mahdad-baghani/32/465_2.png) [@Mahdad-Baghani](https://forum.heroiclabs.com/u/Mahdad-Baghani)
#### Post date: [November 6, 2020, 8:06am UTC](https://forum.heroiclabs.com/t/golang-intellisence-issue-for-protobuf-auto-generated-go-packages-in-a-nakama-based-solution-using-vscode/1109/3 "2020-11-06T08:06:57Z")

</div>

Thanks for the reply.

> [@zyro](#):
>
> This one usually means there are no Go files in a given path

I compile my .proto file from `./ProtoBuffers/` in two different locations, one of which is `./Backend/protobuffers`. So this is the part I suspected it is related to my dockerfile. Because `backend/` is defined as the working directory in dockerfile.

> [@zyro](#):
>
> Make sure whenever you run `docker-compose up` you do so from the root of your backend code

That’s what I do.

> [@zyro](#):
>
> You’re trying to import `gitlab.com/mahdad-baghani/davaa/protobuffers` but you’ve defined your proto output package as `gitlab.com/mahdad-baghani/davaa/Backend/protobuffers`. There’s a missing/extra “Backend” in there.

As I mentioned, I started with the corrected version of the path that you mentioned here. The thing was I had intellisence but also had compile errors. When I added the extra /Backend/ in between my path, neither I had intellisence, nor compile errors.

---

<div class="post-metadata">

### Author: ![Mahdad-Baghani](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mahdad-baghani/32/465_2.png) [@Mahdad-Baghani](https://forum.heroiclabs.com/u/Mahdad-Baghani)
#### Post date: [November 6, 2020, 10:29pm UTC](https://forum.heroiclabs.com/t/golang-intellisence-issue-for-protobuf-auto-generated-go-packages-in-a-nakama-based-solution-using-vscode/1109/4 "2020-11-06T22:29:57Z")

</div>

Here is how I managed to solve the problem in case anyone is curious.

First, I changed my module name to not be mixed case anymore as @zyro suggested. The name was mixed-case because my gitlab account was named that way, but I also changed that, so my module name actually points to a valid remote git repo.

Second, I changed my module name from `gitlab.com/name/reponame` to `gitlab.com/name/reponame/backend` so it respects the hierarchy I had in my monolithic repository. My backend was in `backend` directory, and I named my module that way.

Third, I change all my import paths to include the `/backend` subdirectory. In the case of my auto-generated protobuf stubs, I changed the import path from  
`netcode_buffers "gitlab.com/mahdad-baghani/davaa/protobuffers"`  
to  
`netcode_buffers "gitlab.com/newname/davaa/backend/protobuffers"`  
and I changed the package name of the protobuf definition to match this name exactly.
