go-plus
go-plus copied to clipboard
Feature Request: Improve the `Unimported Packages` autocomplete option to cover methods
Let's say I'm working on some code and I want to use a bufio.Reader I might type something like this:
package main
func main() {
r := bufio.NewReader(os.Stdin)
}
This works great and both NewReader and Stdin are suggested for completion with the "Unimported Packages" option enabled, but if I then type r.R I do not receive any autocomplete suggestions.
package main
func main() {
r := bufio.NewReader(os.Stdin)
r.R // <--- I want to see "r.ReadString" and similar autocomplete suggestions here.
}
This occurs because the bufio package hasn't been imported yet and gocode doesn't seem to infer the type of r from the context.
One way to get around this without requesting changes to gocode is to run the file through the formatter (if it is set to goimports or goreturns) prior to passing the source to gocode. This seems fairly reasonable assuming (a) the user has the "Unimported Packages" option enabled, and (b) we use the formatter they have configured to run on save.
I'm not suggesting we alter the source in the file with the formatter results; instead what I am suggesting is that when both criteria are met we run code through a formatter and then pass that to gocode to generate autocomplete options, then discard the results from the formatter.
Does this sound reasonable?
Would it make more sense to instead offer the feature as an additional setting in go-plus?