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: autocompletion for dependencies not working in Emacs #43414

Closed
magandrez opened this issue Dec 29, 2020 · 4 comments
Closed

x/tools/gopls: autocompletion for dependencies not working in Emacs #43414

magandrez opened this issue Dec 29, 2020 · 4 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@magandrez
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.15.6 linux/amd64

Does this issue reproduce with the latest release?

Yes, with Go, gopls and Emacs latest versions available for my architecture and distribution, the issue described below is reproducible.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/manuel/.cache/go-build"
GOENV="/home/manuel/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/manuel/workbench/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/manuel/workbench/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.15"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.15/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-build414655594=/tmp/go-build -gno-record-gcc-switches"

Emacs environment:

GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0) of 2020-11-08, modified by Debian
$ gopls version
golang.org/x/tools/gopls v0.6.0
    golang.org/x/tools/gopls@v0.6.1 h1:vD171EDBkyUVyp9B45IYXklV/VEfbHgX0FKw0Q0dO30=

What did you do?

I was redirected to create a new issue from #36165 and, as suggested by @stamblerre I also installed the latest version of gopls.

With my $GOPATH set, I open a file in a buffer in my Emacs setup with LSP server and go-mode as stated here and with no specific settings for lsp. The issue I come across is missing autocompletion for external packages (that is, dependencies declared in go.mod and installed with go get), at the same time, the editor highlights the import of external packages as errors, as well as any use of the imports within the file.

Below, an (edited -- removed references to private repo) extract of the output

lsp-log buffer
Command "gopls" is present on the path.
Command "gopls" is present on the path.
Found the following clients for /home/manuel/workbench/go/src/github.com/EDITED/api/handle_checkout.go: (server-id gopls, priority 0)
The following clients were selected based on priority: (server-id gopls, priority 0)
2020/12/29 10:34:50 go env for /home/manuel
(root /home/manuel)
(go version go version go1.15.6 linux/amd64)
(valid build configuration = false)
(build flags: [])
GOMODCACHE=/home/manuel/workbench/go/pkg/mod
GONOPROXY=
GOPRIVATE=
GONOSUMDB=
GOPATH=/home/manuel/workbench/go
GOINSECURE=
GOROOT=/usr/lib/go-1.15
GOCACHE=/home/manuel/.cache/go-build
GOMOD=
GOPROXY=https://proxy.golang.org,direct
GOSUMDB=sum.golang.org
GO111MODULE=
GOFLAGS=

2020/12/29 10:34:50 go/packages.Load
snapshot=0
directory=/home/manuel
query=[./ builtin]
packages=2

2020/12/29 10:34:50 go/packages.Load
snapshot=0
directory=/home/manuel
query=[./]
packages=1

2020/12/29 10:34:50 go/packages.Load
snapshot=1
directory=/home/manuel
query=[file=/home/manuel/workbench/go/src/github.com/EDITED/api/handle_checkout.go]
packages=1

2020/12/29 10:34:50 go/packages.Load
snapshot=1
package_path="github.com/EDITED/api"
files=[/home/manuel/workbench/go/src/github.com/EDITED/api/api.go /home/manuel/workbench/go/src/github.com/EDITED/api/handle_checkout.go /home/manuel/workbench/go/src/github.com/EDITED/api/handle_webhook.go /home/manuel/workbench/go/src/github.com/EDITED/api/routes.go]

2020/12/29 10:34:50 go/packages.Load
snapshot=1
package_path="github.com/EDITED/api"
files=[/home/manuel/workbench/go/src/github.com/EDITED/api/api.go /home/manuel/workbench/go/src/github.com/EDITED/api/handle_checkout.go /home/manuel/workbench/go/src/github.com/EDITED/api/handle_webhook.go /home/manuel/workbench/go/src/github.com/EDITED/api/routes.go]

2020/12/29 10:34:50 go/packages.Load
snapshot=1
directory=/home/manuel
query=[file=/home/manuel/workbench/go/src/github.com/EDITED/api/handle_checkout.go]
packages=1

2020/12/29 10:34:50 github.com/EDITED/lib/server/middleware/opencensus: no dep handle for contrib.go.opencensus.io/exporter/stackdriver/propagation: no metadata for contrib.go.opencensus.io/exporter/stackdriver/propagation
snapshot=1

2020/12/29 10:34:50 github.com/EDITED/lib/server/middleware/opencensus: no dep handle for go.opencensus.io/plugin/ochttp: no metadata for go.opencensus.io/plugin/ochttp
snapshot=1

2020/12/29 10:34:50 github.com/EDITED/lib/server/middleware/opencensus: no dep handle for go.opencensus.io/trace: no metadata for go.opencensus.io/trace
snapshot=1

2020/12/29 10:34:50 github.com/EDITED/lib/server/middleware/opencensus: no dep handle for go.opencensus.io/trace/propagation: no metadata for go.opencensus.io/trace/propagation
snapshot=1

2020/12/29 10:34:50 github.com/EDITED/lib/server/middleware/opencensus: no dep handle for contrib.go.opencensus.io/exporter/stackdriver: no metadata for contrib.go.opencensus.io/exporter/stackdriver
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/swaggo/http-swagger: no metadata for github.com/swaggo/http-swagger
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/alecthomas/template: no metadata for github.com/alecthomas/template
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/swaggo/http-swagger: no metadata for github.com/swaggo/http-swagger
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/alecthomas/template: no metadata for github.com/alecthomas/template
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72: no metadata for github.com/stripe/stripe-go/v72
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/customer: no metadata for github.com/stripe/stripe-go/v72/customer
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for contrib.go.opencensus.io/exporter/stackdriver/propagation: no metadata for contrib.go.opencensus.io/exporter/stackdriver/propagation
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for go.opencensus.io/plugin/ochttp: no metadata for go.opencensus.io/plugin/ochttp
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/webhook: no metadata for github.com/stripe/stripe-go/v72/webhook
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/taxrate: no metadata for github.com/stripe/stripe-go/v72/taxrate
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/checkout/session: no metadata for github.com/stripe/stripe-go/v72/checkout/session
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/price: no metadata for github.com/stripe/stripe-go/v72/price
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72: no metadata for github.com/stripe/stripe-go/v72
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/checkout/session: no metadata for github.com/stripe/stripe-go/v72/checkout/session
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for contrib.go.opencensus.io/exporter/stackdriver/propagation: no metadata for contrib.go.opencensus.io/exporter/stackdriver/propagation
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/customer: no metadata for github.com/stripe/stripe-go/v72/customer
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/price: no metadata for github.com/stripe/stripe-go/v72/price
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/taxrate: no metadata for github.com/stripe/stripe-go/v72/taxrate
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for go.opencensus.io/plugin/ochttp: no metadata for go.opencensus.io/plugin/ochttp
snapshot=1

2020/12/29 10:34:50 github.com/EDITED: no dep handle for github.com/stripe/stripe-go/v72/webhook: no metadata for github.com/stripe/stripe-go/v72/webhook
snapshot=1

2020/12/29 10:34:51 errors loading workspace: You are outside of a module and outside of $GOPATH/src.
If you are using modules, please open your editor to a directory in your module.
If you believe this warning is incorrect, please file an issue: https://github.com/golang/go/issues/new.
snapshot=1
directory=file:///home/manuel

2020/12/29 10:35:20 background imports cache refresh starting

2020/12/29 10:35:20 background refresh finished after 34.49514ms

NOTE: The above log is running latest gopls, the log posted in my last comment in #36165 was extracted when running "gopls build in $GOPATH mode" (i.e.: installed like go get golang.org/x/tools/gopls).

Additional information in the

*Messages* buffer
Loading /etc/emacs/site-start.d/00debian.el (source)...done
Loading /etc/emacs/site-start.d/50autoconf.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...done
Loading debian-ispell...done
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50figlet.el (source)...done
Loading /etc/emacs/site-start.d/50mu4e.el (source)...done
Wrote /home/manuel/.emacs.d/config.el [83 times]
Tangled 83 code blocks from config.org
Loading /home/manuel/.emacs.d/config.el (source)...done
Loaded /home/manuel/.emacs.d/config.el
Starting Emacs daemon.
When done with this frame, type C-x 5 0
[yas] Prepared just-in-time loading of snippets successfully.
LSP :: Connected to [gopls:761133 status:starting].
LSP :: gopls:761133 initialized successfully
LSP :: gopls setting "codelens" is deprecated, use "codelenses" instead
### What did you expect to see?

Autocompletion working for external packages, that is, in Emacs, M-x completion-at-point should return completions for dependencies.

What did you see instead?

M-x completion-at-point returns nothing when attempting to complete external packages, as opposed to, e.g. running M-x completion-at-point over fmt.Er, which returns fmt.Errorf(format string, a ...interface{})

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Dec 29, 2020
@gopherbot gopherbot added this to the Unreleased milestone Dec 29, 2020
@stamblerre
Copy link
Contributor

It sounds like you're using modules, but gopls isn't finding a go.mod file in your workspace. Please make sure to open Emacs with your workspace root configured to your module root (the directory containing the go.mod file).

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Dec 29, 2020
@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 29, 2020
@magandrez
Copy link
Author

Indeed I am using modules. I am not sure what do you mean with "opening Emacs with the workspace root configured to the module root". I include below the structure of the repo, which is based on a "monorepo" structure (several services hanging from the root folder + lib and other tooling, with go.mod at the root).

. 
├── core
│   ├── api
│   │   ├── ...
│   ├── app
│   │   ├── ...
│   ├── db
│   │   ├── ...
│   ├── Dockerfile
│   ├── main.go
│   ├── Makefile
│   ├── README.md
│   ├── scripts
│   ├── ...
├── docker-compose.yml
├── go.mod
├── go.sum
├── lib
│   └── server
│       ├── ...
├── Makefile
│   ...

The logs shown on my previous comment are tied to opening a file from ./core/api.

@stamblerre
Copy link
Contributor

The ./core/api workspace folder should work as long as there is only 1 go.mod file in the workspace, but to be sure, I would open the directory containing the go.mod file. I'm not sure exactly how to configure your workspace folder, but I believe you should have seen a prompt, and if not, there may be a command you can run to set it.

@magandrez
Copy link
Author

Wow, this took me quite a while.

The key thing here being the "workspace". It turns out I had to add my projects to a "workspace". I got the hint for doing this from the Keybindings available for lsp-mode in Emacs, so not a problem of the tooling, but rather PEBCAK 😃

Thanks for the help!

@stamblerre stamblerre removed this from the gopls/v1.0.0 milestone Dec 31, 2020
@golang golang locked and limited conversation to collaborators Dec 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants