Skip to content

x/tools/gopls: excessive packages.Load calls with an ad-hoc package outside of GOPATH/module #42813

@RomanKornev

Description

@RomanKornev

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.15.2 darwin/amd64
  • Run gopls -v version to get version of Gopls if you are using the language server.
    • golang.org/x/tools/gopls v0.5.3
      golang.org/x/tools/gopls@v0.5.3 h1:C8QSrqjqaVzlVoHL1R9yWbROoOApRgI8gN1G+cHlPuw=
      github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
      github.com/google/go-cmp@v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
      github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
      golang.org/x/mod@v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
      golang.org/x/sync@v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
      golang.org/x/tools@v0.0.0-20201110032815-ae45d7cf37a9 h1:S0ATUNSw92bO7f5Z+1tSQsq48TdQs2Ye2rTGJdtf5qc=
      golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
      honnef.co/go/tools@v0.0.1-2020.1.6 h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YVc=
      mvdan.cc/gofumpt@v0.0.0-20200927160801-5bfeb2e70dd6 h1:z+/YqapuV7VZPvBb3GYmuEJbA88M3PFUxaHilHYVCpQ=
      mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.51.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.18.1
  • Run go env to get the go development environment details
    • GO111MODULE=""
      GOARCH="amd64"
      GOBIN=""
      GOCACHE="/Users/df/Library/Caches/go-build"
      GOENV="/Users/df/Library/Application Support/go/env"
      GOEXE=""
      GOFLAGS=""
      GOHOSTARCH="amd64"
      GOHOSTOS="darwin"
      GOINSECURE=""
      GOMODCACHE="/Users/df/go/pkg/mod"
      GONOPROXY=""
      GONOSUMDB=""
      GOOS="darwin"
      GOPATH="/Users/df/go"
      GOPRIVATE=""
      GOPROXY="https://proxy.golang.org,direct"
      GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
      GOSUMDB="sum.golang.org"
      GOTMPDIR=""
      GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
      GCCGO="gccgo"
      AR="ar"
      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/gd/ck6ncspn19115_7mxytyzw840000gp/T/go-build473384269=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

"go.useLanguageServer": true,

Describe the bug

When I save a file, it automatically adds any used package to import section. When that happens, I get a phantom error:

	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "could not import fmt (no package for import fmt)",
	"source": "compiler",

I still compiles, and if I comment/uncomment the import, the error goes away, but it's still very annoying.

Steps to reproduce the behavior:

  1. Paste following code - no errors
package main

import (
	"fmt"
)

func main() {
	fmt.Println(10)
}
  1. Remove line 8 and save a file - no errors
  2. Undo once - no errors
  3. Undo again - no errors
  4. Save a file - error above
  5. Add any code below the import - error still present
  6. Comment/uncomment import - error is gone

Screenshots or recordings

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions