Ask questionsx/tools/gopls: VSCode with go module suddenly shows undeclared name: L LSP[line, character]

<!-- Please answer these questions before submitting your issue. Thanks! -->

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

<pre> $ go version go version go1.12.7 linux/amd64 </pre>

Does this issue reproduce with the latest release?

Yes, but only on my current Ubuntu 18.04, on a fresh Debian 10 it works as expected.

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

Ubuntu 18.04 <details><summary><code>go env</code> Output</summary><br><pre> $ go env GOARCH="amd64" GOBIN="/home/eliezer/go_projects/bin" GOCACHE="/home/eliezer/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/eliezer/go_projects" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build997023063=/tmp/go-build -gno-record-gcc-switches" </pre></details>

What did you do?

Open Visual Studio Code. Add the project folder V1. Add three new xyz.go files into the project folder making it a basic V2 Opened one of the new files tls.go

What did you expect to see?

I expected the go module which uses gopls to show missing variables and other parts of the code as errors.

What did you see instead?

An screenshot link:

Lots of error lines such as below which ends with the source as LSP:

	"resource": "/home/eliezer/Scripts/golang-http-proxy2/filtering.go",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "undeclared name: RequestTimeout",
	"source": "LSP",
	"startLineNumber": 36,
	"startColumn": 27,
	"endLineNumber": 36,
	"endColumn": 41

	"resource": "/home/eliezer/Scripts/golang-http-proxy2/filtering.go",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "undeclared name: MaxIdleConnections",
	"source": "LSP",
	"startLineNumber": 41,
	"startColumn": 26,
	"endLineNumber": 41,
	"endColumn": 44

Answer questions stamblerre

Also, please note that you have to open VSCode at the module root, i.e., with the directory that contains the go.mod file (see #32394) -- I don't see a go.mod file in your screenshot.

Github User Rank List