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

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 17
  • Comments: 38 (16 by maintainers)

Most upvoted comments

$ 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.

@stamblerre Ok, i’ve just moved my project to another directory (it was in GOPATH/src originally) and then have updated my imports. It seems to solve the issue. My GOMOD is no longer set to NULL.

i didn’t know that module support is enabled only when the current directory is outside GOPATH/src… I suppose that was the source of the problem with GOPLS.

Reloading the window without removing the directories resolves the issue until another directory is added.

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