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: function argument placeholders missing in Emacs #44165

Closed
trapperhoney opened this issue Feb 8, 2021 · 4 comments
Closed

x/tools/gopls: function argument placeholders missing in Emacs #44165

trapperhoney opened this issue Feb 8, 2021 · 4 comments

Comments

@trapperhoney
Copy link

@trapperhoney trapperhoney commented Feb 8, 2021

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

$ go version
go version go1.14.7 linux/amd64
$ gopls version
gopls, built in GOPATH mode master

Does this issue reproduce with the latest release?

Yes (I built gopls from HEAD today)

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.14/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/user/lsp-debug/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-build502378375=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm trying to migrate from using the company-go emacs package (which uses gocode) to the new gopls support in the lsp-mode package. For the most part, lsp-mode with gopls seems strictly better. I'm having trouble getting placeholders to appear during function auto completion, though. This feature seems to be supported through the lsp-go-use-placeholders option, which is on by default, but doesn't seem to do anything.

What did you expect to see?

Here's an example of what placeholders look like using company-go and selecting a function auto complete item from the menu:

company-go-complete

What did you see instead?

The gopls-backed menu has the argument list displayed properly:

gopls-menu

However, after selecting an item, no function arguments are displayed:

gopls-complete

I'm having a hard time figuring out if this is a problem with gopls, lsp-mode, or company. The fact that the arguments show up in the completion menu makes me think that gopls is successfully returning them (and the gopls log seems to support this). And company works correctly with the older company-go/gocode combo, so maybe lsm-mode simply isn't parsing the arguments returned by gopls correctly?

I'm using lsp-mode from melpa (20210207.705), gopls built from HEAD (today), and emacs in Ubuntu 20.10 (1:26.3+1-1ubuntu2). The screenshots above were generated while using this minimal .emacs configuration:

(require 'package)
(package-initialize)
(require 'company)
(setq lsp-go-gopls-server-args '("-logfile" "gopls.log" "-rpc.trace"))
(require 'lsp-mode)
(add-hook 'go-mode-hook #'lsp-deferred)
(add-hook 'go-mode-hook #'company-mode)

Here is a log from a session using lsp-mode and gopls: gopls.log

@gopherbot gopherbot added this to the Unreleased milestone Feb 8, 2021
@muirdm
Copy link

@muirdm muirdm commented Feb 9, 2021

It looks like you don't have yasnippet installed/loaded. Yasnippet provides lsp snippet support in conjunction with lsp-mode.

For Emacs Go questions I recommend asking in #emacs on https://invite.slack.golangbridge.org/ .

@stamblerre stamblerre removed this from the Unreleased milestone Feb 9, 2021
@stamblerre stamblerre changed the title x/tools/gopls: Function argument placeholders missing in Emacs x/tools/gopls: function argument placeholders missing in Emacs Feb 9, 2021
@trapperhoney
Copy link
Author

@trapperhoney trapperhoney commented Feb 9, 2021

Thank you! That was indeed the issue. I also needed to enable yas-minor-mode. I'm not completely sure I understand this dependency as most other company modes do this without yasnippet. It seems to be related to the documentation display feature somehow? That was previously not showing up either. Is there anyway to use placeholders without this new dependency? It's not a huge issue, but it seems like an unnecessary new minor mode as there don't seem to be any Go snippet packages either...

@muirdm
Copy link

@muirdm muirdm commented Feb 9, 2021

yasnippet is required to use snippets with lsp-mode (and placeholders are snippets). I don't know what company-go did for snippets. I don't think completion documentation depends on snippets, theoretically or in practice.

there don't seem to be any Go snippet packages

https://github.com/dominikh/yasnippet-go

You can also create your own snippets.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Feb 9, 2021

Thanks for diagnosing this issue, @muirdm! Going to close this as it seems like it's been resolved.

@stamblerre stamblerre closed this Feb 9, 2021
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
4 participants