Skip to content

x/tools/gopls: doesn't work on unsaved buffers in module mode #31467

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
glepnir opened this issue Apr 15, 2019 · 16 comments
Closed

x/tools/gopls: doesn't work on unsaved buffers in module mode #31467

glepnir opened this issue Apr 15, 2019 · 16 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@glepnir
Copy link

glepnir 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
@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 15, 2019
@ianthehat ianthehat added gopls Issues related to the Go language server, gopls. FeatureRequest Issues asking for a new feature that does not need a proposal. labels Apr 15, 2019
@ianthehat
Copy link

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)

@ianthehat ianthehat removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 15, 2019
@glepnir
Copy link
Author

glepnir 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
Copy link

eddiezane 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
Copy link
Contributor

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
Copy link
Member

myitcv 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 ...?

@glepnir
Copy link
Author

glepnir 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
Copy link
Contributor

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
Copy link
Contributor

Closing this issue in favor of #31542.

@glepnir
Copy link
Author

glepnir 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
Copy link
Contributor

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 added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed FeatureRequest Issues asking for a new feature that does not need a proposal. labels 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
@stamblerre stamblerre changed the title x/tools/gopls: doesn't work on unsaved buffers x/tools/gopls: doesn't work on unsaved buffers in module mode Aug 5, 2019
@stamblerre
Copy link
Contributor

It seems like this is actually an issue with go/packages, so I filed a new bug: #33482. Closing this issue in favor of the new one.

@glepnir
Copy link
Author

glepnir commented Sep 17, 2019

@stamblerre hi, i found the #33482 is closed.but i found this issue still exist. I believe that many developers import many third-party packages in their daily work, but gopls can't work in this kind of scenario. I have discussed this problem with my colleagues, we are bothered by this, every time I import a thirty package ,I need to save and restart vim or emacs . I would like to know the go team's view on this issue. This problem has been around for a long time. At least I created this issue last year.
this gif worked in master gopls by go get golang.org/x/tools/gopls@master
git

@stamblerre
Copy link
Contributor

@taigacute: I am not able to reproduce this issue myself. We have added a lot of overlay support to go/packages, so almost everything should work out of the box. Which client are you using for Vim or Emacs? Is the third-party package that you are importing in your module cache?

@glepnir
Copy link
Author

glepnir commented Sep 18, 2019

@stamblerre gif is vim,also i use emacs。reproduce step。

  1. mkdir test
  2. go mod init test
  3. touch main.go
  4. import a thirty package

what i missed ?

@stamblerre
Copy link
Contributor

Sorry, by client I meant - which plugin are you using for the LSP? Is this with vim-go, ale, etc. (see https://github.com/golang/tools/blob/master/gopls/doc/vim.md for a full list)? Is this package something that you've imported before, i.e. is it available in your module cache ($GOPATH/pkg/mod)?

@glepnir
Copy link
Author

glepnir commented Sep 19, 2019

@stamblerre i used coc.nvim .yeah the package in my $GOPATH/pkg/mod

@golang golang locked and limited conversation to collaborators Sep 18, 2020
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants