为什么 Atom 编辑器不能自动完成本地包的工作?

Why isn't autocomplete of local packages working in Atom editor?

Autocomplete (go-plus) 在 Atom 中用于标准库导入工作正常,但每当我尝试导入我自己的包时,它根本不起作用。

我的包结构是这样的:

.
├── bin
├── pkg
└── src
    └── Test
        ├── MyPackage
        │   └── hello.go
        └── main.go

main.go

package main

import (
    "Test/MyPackage"
)

func main() {
    hello.SayHello("World")
}

hello.go

package hello

import "fmt"

const Msg = "Hello "

func SayHello(name string) {
    fmt.Printf("%v%v!\n", Msg, name)
}

该文件编译正常,但在 main.go 中,hello 包不会在 Atom 中调用任何自动完成功能,那么可能是什么问题?

go-plus 软件包的 README.md 中解决了该问题:

First of all, make sure autocomplete-plus is present on your setup. Go-plus provides autocompletion through gocode tool, so you should ensure it's in PATH and available.

If you can't get autocompletion for the user-defined packages working, while it's there for packages from standard library, it's likely a trivial gocode-related issue. Try running gocode set. Some expected output'd be: propose-builtins false lib-path "" autobuild false force-debug-output "" package-lookup-mode "go"

What you gotta do is switching autobuild to true, by running gocode set autobuild true. Check autocompletion now, it must be working right.

另一个可能的原因是 gocode 守护程序无法正常工作(可能是由于 Go 的更新或多个 gocode 守护程序)。关闭守护进程可能会有所帮助。 gocode close