Skip to content
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

x/tools/gopls: show error message if nested module is not root #38089

Open
ymotongpoo opened this issue Mar 26, 2020 · 4 comments
Open

x/tools/gopls: show error message if nested module is not root #38089

ymotongpoo opened this issue Mar 26, 2020 · 4 comments
Labels
Milestone

Comments

@ymotongpoo
Copy link

@ymotongpoo ymotongpoo commented Mar 26, 2020

Please answer these questions before submitting your issue. Thanks!

What did you do?

I was developing a new package on VSCode + gopls and found VSCode constantly shows undefined error though they are defined in the package.

Reproducible code sets are here.
https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/tree/b628ab9ba3d8fe893ed9dcb63d07a75fe56a8b10

What did you expect to see?

The following types are resolved without errors:

What did you see instead?

Undefined errors on each types.

screenshot

Build info

golang.org/x/tools/gopls v0.3.4
    golang.org/x/tools/gopls@v0.3.4 h1:4GC7q/pXQ/tsxHBGVdsMdlB4gCxVC06m/7rIXg1Px4E=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a h1:hKrQy/q8/Xivoqgw6nGiz1jqpn1WGBLDcWLZwW0983E=
    golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info

go version go1.13.9 linux/amd64

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ymotongpoo/.cache/go-build"
GOENV="/home/ymotongpoo/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ymotongpoo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go/go1.13.9"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/go1.13.9/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ymotongpoo/src/projects/opentelemetry-operations-go/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-build957972558=/tmp/go-build -gno-record-gcc-switches"
@gopherbot gopherbot added this to the Unreleased milestone Mar 26, 2020
@gopherbot gopherbot added the Tools label Mar 26, 2020
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 26, 2020

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@gopherbot gopherbot added the gopls label Mar 26, 2020
@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Mar 26, 2020

Thanks for the detailed report! This issue is due to the fact that the metrics directory is a nested module. Right now, gopls requires you to open the module you are working on as your workspace root, so since https://github.com/GoogleCloudPlatform/opentelemetry-operations-go is also a module, gopls is treating that as the root. If you open github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metrics as your workspace root, gopls will treat that as your module and the types should be resolved.

I know that this is not the ideal behavior, and we are working on resolving this issue for gopls/v0.5.0. You can track progress for that here: https://github.com/golang/go/milestone/138. Closing this issue since this is already tracked.

@stamblerre stamblerre closed this Mar 26, 2020
@stamblerre stamblerre changed the title x/tools/gopls: can't resolve types in the same package in another file x/tools/gopls: show error message if nested module is not root Mar 26, 2020
@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Mar 26, 2020

Actually, I'll reopen this issue for now - we should show a better error message in this case.

@stamblerre stamblerre reopened this Mar 26, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.0 Mar 26, 2020
@ymotongpoo

This comment has been minimized.

Copy link
Author

@ymotongpoo ymotongpoo commented Mar 27, 2020

@stamblerre Thank you for the work around. It worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.