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: error when adding a new file to a package #32602

Closed
mgxian opened this issue Jun 13, 2019 · 15 comments
Closed

x/tools/gopls: error when adding a new file to a package #32602

mgxian opened this issue Jun 13, 2019 · 15 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@mgxian
Copy link

mgxian commented Jun 13, 2019

I am using the latest version of gopls in vscode. when create a new directory, and create a new go file in the directory, open the new go file, I type the package hello.

image

I get the error:

file:///d:/code/go/src/github.com/mgxian/tdd-practice/hello/hello_test.go is not part of a package

When I reload the vscode window, the error disappear.

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

$ go version
go version go1.12.5 windows/amd64

$ gopls version
golang.org/x/tools/cmd/gopls
    golang.org/x/tools@v0.0.0-20190606050223-4d9ae51c2468 h1:fTfk6GjmihJbK0mSUFgPPgYpsdmApQ86Mcd4GuKax9U=
go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\will\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\code\go
set GOPROXY=https://goproxy.io
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\code\go\src\github.com\mgxian\tdd-practice\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\will\AppData\Local\Temp\go-build905230974=/tmp/go-build -gno-record-gcc-switches

What did you do?

@ALTree ALTree changed the title xxx is not part of a package x/tools/gopls: xxx is not part of a package Jun 13, 2019
@gopherbot gopherbot added this to the Unreleased milestone Jun 13, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jun 13, 2019
@stamblerre
Copy link
Contributor

Can you sync to the latest version of gopls (go get -u golang.org/x/tools/cmd/gopls) and confirm that you still have this error? There were a number of fixes this week that should have solved this issue.

@glepnir
Copy link

glepnir commented Jun 13, 2019

got same issue, the latest gopls

@stamblerre
Copy link
Contributor

Does the error go away if you save the file?

@stamblerre stamblerre changed the title x/tools/gopls: xxx is not part of a package x/tools/gopls: error when adding a new file to a package Jun 13, 2019
@glepnir
Copy link

glepnir commented Jun 13, 2019

@stamblerre if type package name ,reopen the file . its ok .i just create a isse for some other problems, please check it.

@muirdm
Copy link

muirdm commented Jun 15, 2019

I can reproduce it, but the problem goes away when I save the file. The problem is likely that go/packages doesn't support test overlays/variants.

@danmux
Copy link

danmux commented Jun 20, 2019

I have "... is not part of a package" on an existing project, saving does not fix it, as no Save actions happen.

➜ build-agent (master) ✗ gopls version
golang.org/x/tools/cmd/gopls v0.1.0-cmd.gopls
golang.org/x/tools@v0.0.0-20190620154339-431033348dd0 h1:qUGDNmGEM+ZBtwF9vuzEv+9nQQPL+l/oNBZ+DCDTAyo=

@gabstv
Copy link

gabstv commented Jun 25, 2019

It's also happening on existing files (pretty often). You need to restart gopls to make it go away (or use the vscode reload window command if you're using vscode)

@stamblerre
Copy link
Contributor

stamblerre commented Jun 27, 2019

@gabstv: Can you sync to the latest version of gopls on master (go get -u golang.org/x/tools/gopls@master)? We have made some changes recently that should have solved most of those problems.

There will still be some latency in adding a new file because gopls can't distinguish between a new file and a newly-opened one, so, leaving this issue open.

@Thomas2500
Copy link

I got the same issue within VScode and I am also on master with gopls. gopls keeps crashing now when editing a file.

[Info  - 13:08:18] Build info
----------
golang.org/x/tools/gopls v0.1.1
    golang.org/x/tools/gopls@v0.1.2-0.20190628222527-fb37f6ba8261 h1:3A2gqKo+Ks0waBO08n+uxOsSGD0r1bsVmYOL1ljVrfk=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261 h1:KP5slYyJf3GFQbPLTWjQ0TCqBQ73hYpqtCElF+iSruQ=

Go info
-------
go version go1.12.5 linux/amd64

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/thomas2500/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/thomas2500/go"
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="/home/thomas2500/Sync/Projekte/Thomas Bella/circe/go.mod"
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-build466019991=/tmp/go-build -gno-record-gcc-switches"

[Error - 13:08:19] unable to check package for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go: no packages found for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
[Error - 13:08:19] unable to check package for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go: no packages found for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
[Error - 13:08:19] unable to check package for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go: no packages found for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
[Error - 13:08:19] unable to check package for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go: no packages found for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
[Error - 13:08:19] Request textDocument/documentSymbol failed.
  Message: no AST for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
  Code: 0 
[Error - 13:08:19] unable to check package for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go: no packages found for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
[Error - 13:08:19] unable to check package for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go: no packages found for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
[Error - 13:08:19] unable to check package for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go: no packages found for file:///home/thomas2500/Sync/Projekte/Thomas%20Bella/circe/internal/tlsconfig/tlsconfig.go
[Error - 13:08:19] Request textDocument/codeAction failed.
  Message: method "textDocument/codeAction" did not reply
  Code: -32603 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x8cc1d3]

goroutine 44 [running]:
golang.org/x/tools/internal/lsp/source.Imports(0xb85e20, 0xc0002e1980, 0xb8e260, 0xc0000c8dc0, 0xc004543b40, 0x1552, 0x1557, 0x20, 0x1551, 0x82, ...)
	/home/thomas2500/go/pkg/mod/golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261/internal/lsp/source/format.go:55 +0x103
golang.org/x/tools/internal/lsp.organizeImports(0xb85e20, 0xc0002e1980, 0xb8efe0, 0xc0001a6c30, 0xc0001c5680, 0x5a, 0x82, 0x20, 0x1551, 0x82, ...)
	/home/thomas2500/go/pkg/mod/golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261/internal/lsp/code_action.go:88 +0x117
golang.org/x/tools/internal/lsp.(*Server).codeAction(0xc0001b9380, 0xb85e20, 0xc0002e1980, 0xc00222a9c0, 0xc00222a9c0, 0x0, 0x0, 0x0, 0xc0000e21e0)
	/home/thomas2500/go/pkg/mod/golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261/internal/lsp/code_action.go:31 +0x20b
golang.org/x/tools/internal/lsp.(*Server).CodeAction(0xc0001b9380, 0xb85e20, 0xc0002e1980, 0xc00222a9c0, 0xc00222a9c0, 0x0, 0x0, 0x0, 0x0)
	/home/thomas2500/go/pkg/mod/golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261/internal/lsp/server.go:201 +0x4d
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0xb85e20, 0xc0002e1980, 0xc0002069c0)
	/home/thomas2500/go/pkg/mod/golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261/internal/lsp/protocol/tsserver.go:355 +0x2b50
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc0001c45a0, 0xc0002069c0, 0xc000220000, 0xb85e20, 0xc0002e1980, 0xc0001c18b0, 0xc0001a3c50)
	/home/thomas2500/go/pkg/mod/golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261/internal/jsonrpc2/jsonrpc2.go:441 +0x117
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/home/thomas2500/go/pkg/mod/golang.org/x/tools@v0.0.0-20190628222527-fb37f6ba8261/internal/jsonrpc2/jsonrpc2.go:428 +0x6fc
[Error - 13:08:19] Connection to server got closed. Server will not be restarted.
[Error - 13:08:19] Request textDocument/documentLink failed.
Error: Connection got disposed.
	at Object.dispose (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-languageclient/lib/client.js:57:35)
	at LanguageClient.handleConnectionClosed (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-languageclient/lib/client.js:2036:42)
	at LanguageClient.handleConnectionClosed (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-languageclient/lib/main.js:127:15)
	at closeHandler (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-languageclient/lib/client.js:2023:18)
	at CallbackList.invoke (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/home/thomas2500/.vscode/extensions/ms-vscode.go-0.11.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:182:13)
	at Pipe.Socket._destroy._handle.close [as _onclose] (net.js:596:12)

@stamblerre
Copy link
Contributor

This particular error should be fixed as of https://go-review.googlesource.com/c/tools/+/184258. Please update to master to get the fix.
However, it looks like there is something else going wrong when type-checking your package. Are you opening VSCode to the directory of your module root?

@rssathe
Copy link

rssathe commented Jul 1, 2019

It's still happening to me and I'm on master

@stamblerre
Copy link
Contributor

@rssathe: Are you able to share the gopls logs for this case? Also, can you please confirm your gopls version by running the gopls version command?

@rssathe
Copy link

rssathe commented Jul 1, 2019

@stamblerre The workflow was to just add a new file in an existing package

----------

version v0.1.1, built in $GOPATH mode

Go info
-------
go version go1.12.1 darwin/amd64

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rohansathe/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/rohansathe/code/go_workspace"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/rohansathe/code/shoreline/github/go.mod"
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/bw/x5cgb5t5559fcg2x6d6tjml80000gn/T/go-build866183987=/tmp/go-build -gno-record-gcc-switches -fno-common"

[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] file:///Users/rohansathe/code/shoreline/github/go.mod is not a Go file
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] Request textDocument/documentSymbol failed.
  Message: no AST for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] Request textDocument/codeAction failed.
  Message: no file information for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] Request textDocument/documentLink failed.
  Message: no AST for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:15 PM] Request textDocument/codeAction failed.
  Message: no file information for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:18 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:18 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:18 PM] Request textDocument/hover failed.
  Message: no AST for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:18 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:18 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:18 PM] Request textDocument/hover failed.
  Message: no AST for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:20 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:20 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:20 PM] Request textDocument/hover failed.
  Message: no AST for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:21 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:21 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:21 PM] Request textDocument/hover failed.
  Message: no AST for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 
[Error - 4:32:31 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:31 PM] unable to check package for file:///Users/rohansathe/code/shoreline/github/handlers/model.go: no packages found for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
[Error - 4:32:31 PM] Request textDocument/hover failed.
  Message: no AST for file:///Users/rohansathe/code/shoreline/github/handlers/model.go
  Code: 0 

@gabstv
Copy link

gabstv commented Jul 3, 2019

@stamblerre

@gabstv: Can you sync to the latest version of gopls on master (go get -u golang.org/x/tools/gopls@master)? We have made some changes recently that should have solved most of those problems.

The newest version fixed this, indeed (the problem with existing go files).

@stamblerre
Copy link
Contributor

Thanks for confirming.

@rssathe, @Thomas2500, and anyone with similar issues - it seems like gopls is not working for you more generally, so please see the information under https://github.com/golang/go/wiki/gopls#troubleshooting and open new separate issues if you are still seeing these problems.

@golang golang locked and limited conversation to collaborators Jul 2, 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.
Projects
None yet
Development

No branches or pull requests

9 participants