gomacro icon indicating copy to clipboard operation
gomacro copied to clipboard

Feature Request: Auto-Imports

Open rjoleary opened this issue 7 years ago • 3 comments

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.

rjoleary avatar May 24 '18 13:05 rjoleary

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 avatar Jun 08 '18 17:06 cosmos72

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 :)

cosmos72 avatar Jun 08 '18 23:06 cosmos72

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

benhoyt avatar Nov 26 '18 14:11 benhoyt