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

cmd/go: Allow go list command to accept file contents from STDIN #28809

marwan-at-work opened this Issue Nov 15, 2018 · 4 comments


None yet
4 participants

marwan-at-work commented Nov 15, 2018


Allow go list to read a file from STDIN instead of the actual file on disk so that we can get information on new imports that are not yet persisted to disk.


x/go/packages (which uses go list) is the basis for all new tooling (go-to-def, autocomplete, etc).

When a user is editing a file on their editor by importing a new package, none of these tools can work with the new import because go list cannot recognize the new import statement since it is in the editor's buffer and not yet persisted back to the file on disk.

The only workaround is persisting the file, which comes with its own drawbacks: every time you include a new import you have to use the package incorrectly, get a compile error, just so that you can get autocomplete and gotodef working again. Not a productive user experience. Even worse, GOPACKAGESDRIVER tools that implement caching of go list responses end up caching broken trees.

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

$ go version
go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?


What did you do?

Say I have this file:

package main

func main() {


Then I start editing it like so:

package main

import ""

func main() {
  errors. // <-- cursor is at the dot

Note this file is not yet persisted to disk.

What did you expect to see?

I expect to see an autocomplete list of all of pkg/errors' public API, and if I pick one, I should be able to "GoToDef"

What did you see instead?

It doesn't work unless I persist and try again.


This comment has been minimized.


mvdan commented Nov 15, 2018

How would this relate to Overlay map[string][]byte and ParseFile func(fset *token.FileSet, filename string, src []byte) (*ast.File, error), both in


This comment has been minimized.


marwan-at-work commented Nov 15, 2018

@mvdan I imagine go/packages will pass the Overlay map to go list in one form or another. Note that field's documentation is exactly what this issue is about:

// The Package.Imports map may not include packages that are imported only
// by the alternative file contents provided by Overlay. This may cause
// type-checking to fail.

@mvdan mvdan added the NeedsDecision label Nov 15, 2018


This comment has been minimized.


bcmills commented Nov 15, 2018


This comment has been minimized.


rogpeppe commented Dec 11, 2018

Given that running go list can change the contents of the current go.mod file, how would that work with transitory file contents like this?

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