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: doesn't work on unsaved buffers #31467

Open
taigacute opened this issue Apr 15, 2019 · 10 comments

Comments

Projects
None yet
7 participants
@taigacute
Copy link

commented Apr 15, 2019

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

$ go version
go version go1.12.4 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/pendragon/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/pendragon/workstation"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ct/5f1j4fl91mz_sdsl_3ksr5ph0000gp/T/go-build198016486=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I am a vimer and gopher. Since gocode removed the autobuild feature, I switched to lsp and coc.nvim. At first I used go-langserver, which worked fine, but it was slow and high CPU usage. I tried the functions of bingo and gopls, bingo and gopls are problematic. The problem is always there and I didn't see it being fixed. problem with gopls
problem 1 GOPATH Project:
this file in $GOPATH/src/test/main.go,I can't get any completion information when i input these。

package main
import "net/http"
func main(){
       http.
}

save the file and reopen file gopls works。
go

problem 2 Go mod Project:
When I introduce a third party package, I can't get any completion information.
go1

What did you expect to see?

Completion of normal work

What did you see instead?

go -langserver. but its performance is terrible

@bradfitz bradfitz changed the title gopls: Bad experience with gopls!!! x/tools/cmd/gopls: auto-completion not working Apr 15, 2019

@gopherbot gopherbot added this to the Unreleased milestone Apr 15, 2019

@ianthehat

This comment has been minimized.

Copy link

commented Apr 15, 2019

I am only going to speak to gopls as that is the only solution the go team is likely to add features to moving forwards.
gopls currently cannot work correctly on any package that has no persisted files, the issue is being tracked in #31307
It also will not auto-complete for things that are not imported into the current file. We have a lot of plans to improve auto complete in the future, but there are other higher priority features we need to add first (like rename and find references)

@taigacute

This comment has been minimized.

Copy link
Author

commented Apr 16, 2019

@ianthehat
I think the focus of gopls should be on completion. The rename and reference features are supported in coc and other completion plugins. At present, I think the biggest problem is that there is no easy to use complement in vim and other editors.

@eddiezane

This comment has been minimized.

Copy link

commented Apr 16, 2019

Edit: I upgraded from Go 1.12.3 to 1.12.4 and it fixed my issue. Sorry for the noise.

Running into the first issue mentioned. Seems specific to net(/*) as an import—completion for everything breaks when imported.

Using gopls with vim-go but I'm thinking this isn't vim-go related since I can reproduce by making queries directly.

package main

import "fmt"
import "net"

func main() {
        fmt.Println("vim-go")
}
$GOPATH/bin/gopls query definition /home/eddiezane/Desktop/herp/main.go:#67
definition: /home/eddiezane/Desktop/herp/main.go:#67: no file information for file:///home/eddiezane/Desktop/herp/main.go
{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package main\n\nimport \"fmt\"\nimport \"net/http\"\n\nfunc main() {\n\tfmt.Pr
intln(\"vim-go\")\n\thttp.\n}\n"}],"textDocument":{"uri":"file:///home/eddiezane/Desktop/herp/main.go"}}}', '->
Content-Length: 175

{"method":"textDocument/completion","jsonrpc":"2.0","id":2,"params":{"textDocument":{"uri":"file:///home/eddiezane/Desktop/herp/main.go"},"position":{"character":6,"l
ine":7}}}', '<-
Content-Length: 135

{"jsonrpc":"2.0","error":{"code":0,"message":"no file information for file:///home/eddiezane/Desktop/herp/main.go","data":null},"id":2}']
@gopherbot

This comment has been minimized.

Copy link

commented Apr 17, 2019

Change https://golang.org/cl/172409 mentions this issue: go/packages: add support for entire packages defined in overlays

@stamblerre stamblerre changed the title x/tools/cmd/gopls: auto-completion not working x/tools/cmd/gopls: doesn't work on unsaved buffers Apr 17, 2019

@myitcv

This comment has been minimized.

Copy link
Member

commented Apr 18, 2019

@stamblerre - following https://go-review.googlesource.com/c/tools/+/172409/ I'm still seeing an issue in the test in #31338 (was closed in favour of this issue), i.e. completions are not working for unpersisted imports. Should I open another issue for that or ...?

@taigacute

This comment has been minimized.

Copy link
Author

commented Apr 18, 2019

I tested it and didn't see it fixed. My friend and I are making a new lsp instead of gopls, hope that gopls will become mature enough.

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Apr 18, 2019

The issue with this bug is it's difficult to reverse engineer the package path given the filename and the package declaration. #31522 is tracking further improvements to the overlays in go/packages, but right now we don't handle main packages or x_tests.

@myitcv: I expect that if you try the same case with a non-main file it should work. Filed #31542.

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2019

Closing this issue in favor of #31542.

@stamblerre stamblerre closed this Jun 5, 2019

@taigacute

This comment has been minimized.

Copy link
Author

commented Jun 27, 2019

@stamblerre #31542 is closed. but i dont find the problem solved. gopls also doesnt work on unsaved buffer when i import a new thirty package.

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jun 28, 2019

It's possible that there has been a recent regression. I will reopen this issue and investigate. Thanks for pointing this out.

@stamblerre stamblerre reopened this Jun 28, 2019

@stamblerre stamblerre changed the title x/tools/cmd/gopls: doesn't work on unsaved buffers x/tools/gopls: doesn't work on unsaved buffers Jul 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.