Skip to content

x/tools/cmd/gopls: file is not part of package #33011

Closed
@jeanbza

Description

@jeanbza

Reproduces with gopls@master and gopls@latest:

golang.org/x/tools/gopls v0.1.0
    golang.org/x/tools/gopls@v0.1.2-0.20190708203411-c8855242db9c h1:qFHl9H1pFOvam5c7rRNiSVPuASu5sS/VNZUj7KNAyGI=

and

$ gopls version
golang.org/x/tools/gopls v0.1.0
    golang.org/x/tools/gopls@v0.1.1 h1:mU/O8r53RjzdZfkqmFOX4iEt8PJxTPXyLdiuQNa27OE=

Steps to reproduce:

  1. Create folder
  2. Create a.go:
    package main
    
    type whatever struct{}
    
  3. Create b.go:
    package main
    
    import "fmt"
    
    func main() {
     w := whatever{}
     fmt.Println("whatever", w)
    }
    

This compiles and runs fine, but in vscode with gopls I get a red squiggly over package with the error:

file:///usr/local/google/home/deklerk/workspace/interview-questions/foo/b.go is not part of a package LSP

Activity

added
goplsIssues related to the Go language server, gopls.
on Jul 9, 2019
stamblerre

stamblerre commented on Jul 9, 2019

@stamblerre
Contributor

Are you able to reproduce this if the package name is not main?

jeanbza

jeanbza commented on Jul 9, 2019

@jeanbza
ContributorAuthor

IIRC yes - I actually found it on a non-main package and recreated it with main.

changed the title [-]gopls: file is not part of package[/-] [+]x/tools/cmd/gopls: file is not part of package[/+] on Jul 10, 2019
added this to the Unreleased milestone on Jul 10, 2019
llbec

llbec commented on Jul 10, 2019

@llbec

I got this error too. This error has gone when I reopen vscode, but it will come out at an other new open file.

stamblerre

stamblerre commented on Jul 10, 2019

@stamblerre
Contributor

@llbox: What version of gopls are you using (gopls version)? Can you update to the latest version (go get golang.org/x/tools/gopls@latest) and confirm that you still see this issue?

mthie

mthie commented on Jul 10, 2019

@mthie
$ gopls version
version v0.1.3-cmd.gopls, built in $GOPATH mode

Even after git pull on master branch the message still occurs. Also in vim-go.

jamiebarnett

jamiebarnett commented on Jul 11, 2019

@jamiebarnett

I am also having this issue. Compiles fine but get an error that won't go away unless VS Code is restarted. from VS Code gopls log;

[Error - 10:29:21] unable to check package for file:///xxxxx/pkg/sites/sites.go: loadParseTypeCheck: no package found for /xxxxx/pkg/sites/sites.go
[Error - 10:29:21] Request textDocument/hover failed.
  Message: no AST for file:///xxxxx/pkg/sites/sites.go
  Code: 0 
version v0.1.0-cmd.gopls, built in $GOPATH mode
linguohua

linguohua commented on Jul 11, 2019

@linguohua

version v0.1.3-cmd.gopls, built in $GOPATH mode.
Has the same problem both on windows and linux

mthie

mthie commented on Jul 11, 2019

@mthie

When I check it manually, not via IDE:

/my/path $ gopls check myfile.go

2019/07/11 15:28:58 Error:unable to check package for file:///my/path/myfile.go: loadParseTypecheck: no metadata found for /my/path/myfile.go
2019/07/11 15:28:58 Error:unable to check package for file:///my/path/myfile.go: loadParseTypecheck: no metadata found for /my/path/myfile.go
/my/path/myfile.go: file:///my/path/myfile.go is not part of a package
malexdev

malexdev commented on Jul 11, 2019

@malexdev

I am also having this issue.

Sometimes restarting the language server will resolve the issue, but then it will come back seemingly at random. The only thing that seems to permanently resolve the issue for a newly created file is to reload VS Code.

This is using modules.

stamblerre

stamblerre commented on Jul 11, 2019

@stamblerre
Contributor

@mthie, @jamiebarnett, @linguohua, @malexdev - could you share a full gopls log? It would be easier for me to understand the issue to see a log that starts from the beginning. Also, if you are using VSCode, please share your VSCode settings.

mthie

mthie commented on Jul 11, 2019

@mthie

Well, I thought, I already posted the full log ;)
Here's a verbose output:

$ gopls -v check myfile.go
2019/07/11 18:48:08 Info:Build info
----------
version v0.1.3-cmd.gopls, built in $GOPATH mode

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mthie/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mthie/go"
GOPROXY=""
GORACE=""
GOROOT="/opt/go"
GOTMPDIR=""
GOTOOLDIR="/opt/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-build237434352=/tmp/go-build -gno-record-gcc-switches"
2019/07/11 18:48:08 Error:unable to check package for file:///home/mthie/go/src/github.com/mthie/mylib/myfile.go: loadParseTypecheck: no metadata found for /home/mthie/go/src/github.com/mthie/mylib/myfile.go
2019/07/11 18:48:08 Error:unable to check package for file:///home/mthie/go/src/github.com/mthie/mylib/myfile.go: loadParseTypecheck: no metadata found for /home/mthie/go/src/github.com/mthie/mylib/myfile.go
/home/mthie/go/src/github.com/mthie/mylib/myfile.go: file:///home/mthie/go/src/github.com/mthie/mylib/myfile.go is not part of a package
stamblerre

stamblerre commented on Jul 11, 2019

@stamblerre
Contributor

Thanks for sharing all of it, I didn't realize you were using gopls on the command line. What happens when you run go list -e -json -compiled -test /home/mthie/go/src/github.com/mthie/mylib?

29 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgegoplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mthie@malexdev@linguohua@jeanbza@stamblerre

        Issue actions

          x/tools/cmd/gopls: file is not part of package · Issue #33011 · golang/go