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

Feature Request: Auto-Imports #22

Open
rjoleary opened this issue May 24, 2018 · 3 comments
Open

Feature Request: Auto-Imports #22

rjoleary opened this issue May 24, 2018 · 3 comments

Comments

@rjoleary
Copy link

It would make scripting easier if missing imports for standard libraries are automatically added. I have found the behaviour provided by this tool very helpful while scripting: https://godoc.org/golang.org/x/tools/cmd/goimports . The feature can be optional or only available for an interactive shell. Just an idea.

@cosmos72
Copy link
Owner

cosmos72 commented Jun 8, 2018

Neat idea @rjoleary

From what I understand, goimports works on whole files, while gomacro parses and evaluates code line-by-line.
So there's some impedance mismatch that would need to be solved - not too difficult, but not trivial either - it's not something that can be done with a simple call to os/exec.Command()

A contribution would be welcome :)

@cosmos72
Copy link
Owner

cosmos72 commented Jun 8, 2018

Update: since the packages in the standard library are basically fixed, goimports behavior is easy to mimic, especially now that gomacro has auto-completion.

It's a good first issue :)

@benhoyt
Copy link

benhoyt commented Nov 26, 2018

Yeah, this would be really nice. I ran into gomacro via gosnip, a little tool I made to run snippets of Go code on the command line. It uses the AST to figure out which stdlib imports to add automatically (though I might change it to use the library behind goimports, which also adds imports found in GOPATH).

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

No branches or pull requests

3 participants