Skip to content

Variables and types marked as Undeclared when they are declared in another .go file of the same package #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
saulortega opened this issue Jul 1, 2020 · 10 comments
Labels
FrozenDueToAge upstream-tools Issues that are caused by problems in the tools that the extension depends on.

Comments

@saulortega
Copy link

saulortega commented Jul 1, 2020

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go1.14.3 linux/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.46.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.15.0
  • Run go env to get the go development environment details
    GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/saul/.cache/go-build" GOENV="/home/saul/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/saul/go:/home/saul/go/src/algo/Librerias" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build371168830=/tmp/go-build -gno-record-gcc-switches"

Describe the bug

A few days ago I was prompted for install the Go extension (I already had it installed and working well, but I clicked in order to maybe update)
After that new installation, it doesn't recognize the variables/types in another file of the same package. They are marked as Undeclared.

Screenshots or recordings

"Sitio" type defined in sitio.go:

image

Sitio declared in another file:

image

image

@saulortega saulortega changed the title Variables and types marked as Undeclared when they are in another .go file of the same package Variables and types marked as Undeclared when they are declared in another .go file of the same package Jul 1, 2020
@hyangah
Copy link
Contributor

hyangah commented Jul 1, 2020

Thanks for the report @saulortega
Can you please provide the following details?

  • Go related settings: any fields starting with "go", "[go]", "gopls" from Preferences: Open Settings (JSON) and Preferences: Open Workspace Settings (JSON) commands.

  • Where your source files located (the directory structure relative to your GOPATH directory).

  • If "go.useLanguageServer": true, set

"go.languageServerFlags": [
  "-rpc.trace"
]

and capture the traces from gopls (server) Output channel.

@saulortega
Copy link
Author

saulortega commented Jul 1, 2020

I'm not sure where is that menu. The closest is this:

image

The files are out of GOPATH. Is that the reason? However, it was working before updating the extension.

@hyangah
Copy link
Contributor

hyangah commented Jul 1, 2020

@saulortega You can select commands from the Command Palette (Ctrl+Shift+P) https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette

The project should be under GOPATH/src if you work in the GOPATH mode (not the modules mode).

You can install the previous extension version following this instruction https://code.visualstudio.com/updates/v1_30#_install-previous-versions

@saulortega
Copy link
Author

Ok.

"go.formatTool": "goimports",
"go.useLanguageServer": true

I added this:

"go.languageServerFlags": [
	"-rpc.trace"
]

But, I dont know how to do the traces from gopls.

@hyangah
Copy link
Contributor

hyangah commented Jul 1, 2020

@saulortega If you are using the language server and your project is outside the GOPATH (assuming you are working in GOPATH mode - i.e. no go.mod file in the project root), that's the culprit.

The traces is in the gopls (server) item from OUTPUT window.
Command Palette (Ctrl+Shift+P) -> View: Toggle Output, then select the 'gopls (server)'

@hyangah
Copy link
Contributor

hyangah commented Jul 1, 2020

To install the previous version (more than a month old code base, so I guess that's sufficient for testing),
visit https://github.com/golang/vscode-go/releases/tag/v0.14.4 and download the vsix file.
From the Command Palette again, choose the "Extensions: Install from VSIX" command and provide the donwloaded vsix file.

@saulortega
Copy link
Author

What is "language server"?

The project is outside the GOPATH. I'm using go.mod in the root (it can be seen in the last image I uploaded above (bottom left)).

The output is large. Here a small part:

image

When I click on Install Another Version:

image

Thank you, I will follow that last instructions.

@hyangah
Copy link
Contributor

hyangah commented Jul 1, 2020

It seems like the VS Code's "Install another version" feature doesn't work for our extension for now. I filed microsoft/vscode#101509

Language server is the one that compute intellisense, and Go program analysis. https://github.com/golang/vscode-go#language-server

From your original report, I see GOMOD="" which indicates there is no go.mod file in the directory where you ran go env. So, I assumed you were not using the modules mode.

If you are using the modules mode, check the pinned issue #275 explaining the current limitation depending on how the repository is origanized.

If the previous version works, let us know.

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 1, 2020
@saulortega
Copy link
Author

saulortega commented Jul 1, 2020

Well, y ran that outside of my Go root directory. Here is go env again inside Go work directory:

GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/saul/.cache/go-build" GOENV="/home/saul/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/saul/go:/home/saul/go/src/algo/Librerias" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/saul/repositorios/sitios/servidor/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build843390947=/tmp/go-build -gno-record-gcc-switches"

The previous version doesn't work.

Ok, I realized the checks work fine when I open VS Code from my Go code's root directory. I was opening it one level above, same as the go env. I have in my repository two directories: One for backend in Go, and another for frontend in Javascript.

@hyangah
Copy link
Contributor

hyangah commented Jul 2, 2020

@saulortega Thanks for the update. Yes, currently, the workspace root and the module root need to be aligned when working in modules mode. #275 describes a workaround. We hope to be fixed in the future releases of the language server (gopls).

I will close this issue because we already have open cases for this problem.

BTW if the frontend/backend are developed/released together, it's not a bad idea to place go.mod at the root of the repo. By placing go.mod in a directory that's not the root of the repo, you are creating a multi-module repository (the repo root is a module too). In many cases, we observed multi-module repositories need a lot more care. For details about maintaining multi-module repositories, see https://github.com/golang/go/wiki/Modules#faqs--multi-module-repositories

@hyangah hyangah closed this as completed Jul 2, 2020
@hyangah hyangah added upstream-tools Issues that are caused by problems in the tools that the extension depends on. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 2, 2020
@golang golang locked and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge upstream-tools Issues that are caused by problems in the tools that the extension depends on.
Projects
None yet
Development

No branches or pull requests

3 participants