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/go/packages: fails on ad-hoc package with bad import #33374

Open
muirrn opened this issue Jul 30, 2019 · 3 comments

Comments

@muirrn
Copy link

commented Jul 30, 2019

On master (ed3277de27998232ef7586f5f0d01384bfa52c37) when I first load a file with a non-existent import, I get a "no packages found error". For example, create a new package with this file:

package main
import (
	_ "banana"
)
func main() {
}

And then open in your editor. I see the below errors, which persist until I edit the buffer.

81.288793ms for GOROOT= GOPATH=<my GOPATH> GO111MODULE= PWD=/Users/muir/scratch/foo/ go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/muir/scratch/foo/foo.go", stderr: <<build command-line-arguments: cannot load banana: cannot find module providing package banana
>>

unable to check package: go/packages.Load: no packages found for /Users/muir/scratch/foo/foo.go
	file = file:///Users/muir/scratch/foo/foo.go

LSP :: GetAST: unable to check package for file:///Users/muir/scratch/foo/foo.go: go/packages.Load: no packages found for /Users/muir/scratch/foo/foo.go

@gopherbot gopherbot added this to the Unreleased milestone Jul 30, 2019

@gopherbot gopherbot added the gopls label Jul 30, 2019

@stamblerre stamblerre changed the title x/tools/gopls: can't load packages with bad imports x/tools/go/packages: fails on ad-hoc package with bad import Aug 6, 2019

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Aug 6, 2019

This appears to be a go/packages issue.

In this example, go/packages will not provide any output.

$ mkdir ~/tmp
$ cat > tmp.go <<EOF
package main
import _ "banana"
func main() {}

EOF
$ gopackages -json -deps -mode=imports file=~/tmp/tmp.go

In this example, go/packages will produce output for an ad-hoc package.

$ mkdir ~/tmp
$ cat > tmp.go <<EOF
package main
//import _ "banana"
func main() {}

EOF
$ gopackages -json -deps -mode=imports file=~/tmp/tmp.go
{
	"ID": "command-line-arguments",
	"Name": "main",
	"PkgPath": "command-line-arguments",
	"GoFiles": [
		"$HOME/tmp/tmp.go"
	],
	"CompiledGoFiles": [
		"$HOME/tmp/tmp.go"
	]

/cc @matloob

@gopherbot

This comment has been minimized.

Copy link

commented Aug 29, 2019

Change https://golang.org/cl/192260 mentions this issue: go/packages: add a test case for golang/go#33374

gopherbot pushed a commit to golang/tools that referenced this issue Sep 10, 2019
go/packages: add a test case for golang/go#33374
Change-Id: Iea94f3fd4ec2faa67a26176250e20f98d693f91d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192260
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
eduvim added a commit to eduvim/tools that referenced this issue Sep 11, 2019
go/packages: add a test case for golang/go#33374
Change-Id: Iea94f3fd4ec2faa67a26176250e20f98d693f91d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192260
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
myitcv added a commit to govim/govim that referenced this issue Sep 11, 2019
deps: upgrade to gopls and x/tools 16c5e0f7d110
* internal/lsp: process configuration options more thoroughly 16c5e0f7
* go/packages: add a test case for golang/go#33374 c9a5ac55
* internal/lsp: treat completion documentation errors as actual errors ec76318e
* internal/imports: fix scanning GOROOT in module mode 7f5965fd
* internal/lsp: add ID to the package cache key 3e6e7c42
* internal/imports: add all interfaces in mkstdlib d0542c01
* internal/lsp: start handling watched file deletes 5e3480f0
* internal/imports: fix mkstdlib, run for go1.13 df93a1b9
* internal/lsp: fix completion for nested *ast.BadStmt 3cd124fa
* go/analysis: copyedit doc.go c1ad8a4b
* internal/lsp: only build a view when we have its configuration 3d22a3cf
* internal/lsp: derive ASTs from type information 238129aa
myitcv added a commit to govim/govim that referenced this issue Sep 11, 2019
deps: upgrade to gopls and x/tools 16c5e0f7d110
* internal/lsp: process configuration options more thoroughly 16c5e0f7
* go/packages: add a test case for golang/go#33374 c9a5ac55
* internal/lsp: treat completion documentation errors as actual errors ec76318e
* internal/imports: fix scanning GOROOT in module mode 7f5965fd
* internal/lsp: add ID to the package cache key 3e6e7c42
* internal/imports: add all interfaces in mkstdlib d0542c01
* internal/lsp: start handling watched file deletes 5e3480f0
* internal/imports: fix mkstdlib, run for go1.13 df93a1b9
* internal/lsp: fix completion for nested *ast.BadStmt 3cd124fa
* go/analysis: copyedit doc.go c1ad8a4b
* internal/lsp: only build a view when we have its configuration 3d22a3cf
* internal/lsp: derive ASTs from type information 238129aa
myitcv added a commit to govim/govim that referenced this issue Sep 11, 2019
deps: upgrade to gopls and x/tools 16c5e0f7d110
* internal/lsp: process configuration options more thoroughly 16c5e0f7
* go/packages: add a test case for golang/go#33374 c9a5ac55
* internal/lsp: treat completion documentation errors as actual errors ec76318e
* internal/imports: fix scanning GOROOT in module mode 7f5965fd
* internal/lsp: add ID to the package cache key 3e6e7c42
* internal/imports: add all interfaces in mkstdlib d0542c01
* internal/lsp: start handling watched file deletes 5e3480f0
* internal/imports: fix mkstdlib, run for go1.13 df93a1b9
* internal/lsp: fix completion for nested *ast.BadStmt 3cd124fa
* go/analysis: copyedit doc.go c1ad8a4b
* internal/lsp: only build a view when we have its configuration 3d22a3cf
* internal/lsp: derive ASTs from type information 238129aa
myitcv added a commit to govim/govim that referenced this issue Sep 12, 2019
deps: upgrade to gopls and x/tools 6bfd74cf
* internal/lsp: update go.mod for next version 6bfd74cf
* internal/lsp: use the view options, not the session options c7d52e45
* gopls/doc: update config settings in documentation 63a3583f
* go/packages: allow types loading without NeedDeps 7dd31af5
* internal/lsp: update gopls mod file b87a5f9d
* internal/lsp: merge session and view options into one b13fa046
* internal/lsp: prepare for tagged version 4f2ddba3
* internal/lsp: process configuration options more thoroughly 16c5e0f7
* go/packages: add a test case for golang/go#33374 c9a5ac55
* internal/lsp: treat completion documentation errors as actual errors ec76318e
* internal/imports: fix scanning GOROOT in module mode 7f5965fd
* internal/lsp: add ID to the package cache key 3e6e7c42
* internal/imports: add all interfaces in mkstdlib d0542c01
* internal/lsp: start handling watched file deletes 5e3480f0
* internal/imports: fix mkstdlib, run for go1.13 df93a1b9
* internal/lsp: fix completion for nested *ast.BadStmt 3cd124fa
* go/analysis: copyedit doc.go c1ad8a4b
* internal/lsp: only build a view when we have its configuration 3d22a3cf
* internal/lsp: derive ASTs from type information 238129aa

@gopherbot gopherbot added the Tools label Sep 12, 2019

myitcv added a commit to govim/govim that referenced this issue Sep 13, 2019
deps: upgrade to gopls and x/tools 3720d1ec
* go/packages: suppress go list -e error when directory outside modules 3720d1ec
* internal/lsp: turn fuzzy matching and deep completions back on 87d9f09c
* internal/testenv: handle GOPACKAGESDRIVER=off in NeedsGopackage b0a6c2aa
* go/packages: fall back to loading from export data if sources are missing 22c3443c
* Fixed documentation for gopls installation 44811c01
* internal/lsp: update go.mod for next version 6bfd74cf
* internal/lsp: use the view options, not the session options c7d52e45
* gopls/doc: update config settings in documentation 63a3583f
* go/packages: allow types loading without NeedDeps 7dd31af5
* internal/lsp: update gopls mod file b87a5f9d
* internal/lsp: merge session and view options into one b13fa046
* internal/lsp: prepare for tagged version 4f2ddba3
* internal/lsp: process configuration options more thoroughly 16c5e0f7
* go/packages: add a test case for golang/go#33374 c9a5ac55
* internal/lsp: treat completion documentation errors as actual errors ec76318e
* internal/imports: fix scanning GOROOT in module mode 7f5965fd
* internal/lsp: add ID to the package cache key 3e6e7c42
* internal/imports: add all interfaces in mkstdlib d0542c01
* internal/lsp: start handling watched file deletes 5e3480f0
* internal/imports: fix mkstdlib, run for go1.13 df93a1b9
* internal/lsp: fix completion for nested *ast.BadStmt 3cd124fa
* go/analysis: copyedit doc.go c1ad8a4b
* internal/lsp: only build a view when we have its configuration 3d22a3cf
* internal/lsp: derive ASTs from type information 238129aa
myitcv added a commit to govim/govim that referenced this issue Sep 13, 2019
deps: upgrade to gopls and x/tools 3720d1ec
* go/packages: suppress go list -e error when directory outside modules 3720d1ec
* internal/lsp: turn fuzzy matching and deep completions back on 87d9f09c
* internal/testenv: handle GOPACKAGESDRIVER=off in NeedsGopackage b0a6c2aa
* go/packages: fall back to loading from export data if sources are missing 22c3443c
* Fixed documentation for gopls installation 44811c01
* internal/lsp: update go.mod for next version 6bfd74cf
* internal/lsp: use the view options, not the session options c7d52e45
* gopls/doc: update config settings in documentation 63a3583f
* go/packages: allow types loading without NeedDeps 7dd31af5
* internal/lsp: update gopls mod file b87a5f9d
* internal/lsp: merge session and view options into one b13fa046
* internal/lsp: prepare for tagged version 4f2ddba3
* internal/lsp: process configuration options more thoroughly 16c5e0f7
* go/packages: add a test case for golang/go#33374 c9a5ac55
* internal/lsp: treat completion documentation errors as actual errors ec76318e
* internal/imports: fix scanning GOROOT in module mode 7f5965fd
* internal/lsp: add ID to the package cache key 3e6e7c42
* internal/imports: add all interfaces in mkstdlib d0542c01
* internal/lsp: start handling watched file deletes 5e3480f0
* internal/imports: fix mkstdlib, run for go1.13 df93a1b9
* internal/lsp: fix completion for nested *ast.BadStmt 3cd124fa
* go/analysis: copyedit doc.go c1ad8a4b
* internal/lsp: only build a view when we have its configuration 3d22a3cf
* internal/lsp: derive ASTs from type information 238129aa
myitcv added a commit to govim/govim that referenced this issue Sep 13, 2019
deps: upgrade to gopls and x/tools 3720d1ec (#524)
* go/packages: suppress go list -e error when directory outside modules 3720d1ec
* internal/lsp: turn fuzzy matching and deep completions back on 87d9f09c
* internal/testenv: handle GOPACKAGESDRIVER=off in NeedsGopackage b0a6c2aa
* go/packages: fall back to loading from export data if sources are missing 22c3443c
* Fixed documentation for gopls installation 44811c01
* internal/lsp: update go.mod for next version 6bfd74cf
* internal/lsp: use the view options, not the session options c7d52e45
* gopls/doc: update config settings in documentation 63a3583f
* go/packages: allow types loading without NeedDeps 7dd31af5
* internal/lsp: update gopls mod file b87a5f9d
* internal/lsp: merge session and view options into one b13fa046
* internal/lsp: prepare for tagged version 4f2ddba3
* internal/lsp: process configuration options more thoroughly 16c5e0f7
* go/packages: add a test case for golang/go#33374 c9a5ac55
* internal/lsp: treat completion documentation errors as actual errors ec76318e
* internal/imports: fix scanning GOROOT in module mode 7f5965fd
* internal/lsp: add ID to the package cache key 3e6e7c42
* internal/imports: add all interfaces in mkstdlib d0542c01
* internal/lsp: start handling watched file deletes 5e3480f0
* internal/imports: fix mkstdlib, run for go1.13 df93a1b9
* internal/lsp: fix completion for nested *ast.BadStmt 3cd124fa
* go/analysis: copyedit doc.go c1ad8a4b
* internal/lsp: only build a view when we have its configuration 3d22a3cf
* internal/lsp: derive ASTs from type information 238129aa
@gopherbot

This comment has been minimized.

Copy link

commented Sep 13, 2019

Change https://golang.org/cl/195319 mentions this issue: go/packages: enable TestAdHocPackagesBadImport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.