golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.06k stars 17.68k forks source link

x/tools/cmd/gopls: fails on certain projects #31712

Closed bitfield closed 5 years ago

bitfield commented 5 years ago
go version go1.12.4 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/john/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/john/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.4/libexec/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/q3/ybqqxyh92yd0yc865zqk0vpm0000gn/T/go-build749386462=/tmp/go-build -gno-record-gcc-switches -fno-common"

VS Code 1.33.1 51b0b28134d51361cf996d2f0a1c698247aeabd8 x64
vscode-go 0.10.1

gopls settings as here: https://github.com/golang/go/wiki/gopls

Steps to reproduce:

  1. Create a main.go file in a new directory.
  2. Enter this code:
package main

func main() {
    os.Exit(1)
}
  1. Save

An automatic import "os" is added. I can hover the mouse over os.Exit and see pop-up information about the function. If I delete the Exit(1), place the cursor after os. and hit Ctrl-Space, I see an auto-complete menu showing the available functions in os.

  1. Add a go.mod file with go mod init tmp.

  2. Delete the import "os" line and save the file again. Now the auto import is no longer added, the hover doc does not appear, and there is no auto-complete menu.

(Transferred from https://github.com/Microsoft/vscode-go/issues/2476)

stamblerre commented 5 years ago

@marco-m: The follow-up to this was in https://github.com/golang/go/issues/32142, which was ultimately closed as working as intended. If you are experiencing a problem with gopls, please file a separate issue with information about your environment and logs. Even though these issues can look similar to one another, they can often be traced back to different underlying causes.

bitfield commented 5 years ago

@marco-m the TL;DR of that issue was 'without a go.mod file, gopls can do nothing'.

stamblerre commented 5 years ago

We are, however, working on changing this, as tracked in https://github.com/golang/go/issues/32587.