Fix #94
This commit is contained in:
parent
3b8b8ced46
commit
107b499f1a
64
conf/wide.go
64
conf/wide.go
|
@ -83,7 +83,7 @@ func FixedTimeCheckEnv() {
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
gocode := Wide.GetGocode()
|
gocode := Wide.GetExecutableInGOBIN("gocode")
|
||||||
cmd := exec.Command(gocode, "close")
|
cmd := exec.Command(gocode, "close")
|
||||||
_, err := cmd.Output()
|
_, err := cmd.Output()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
@ -91,7 +91,7 @@ func FixedTimeCheckEnv() {
|
||||||
glog.Warningf("Not found gocode [%s]", gocode)
|
glog.Warningf("Not found gocode [%s]", gocode)
|
||||||
}
|
}
|
||||||
|
|
||||||
ide_stub := Wide.GetIDEStub()
|
ide_stub := Wide.GetExecutableInGOBIN("ide_stub")
|
||||||
cmd = exec.Command(ide_stub, "version")
|
cmd = exec.Command(ide_stub, "version")
|
||||||
_, err = cmd.Output()
|
_, err = cmd.Output()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
@ -149,40 +149,40 @@ func (*conf) GetUser(username string) *User {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取 gocode 路径.
|
// 获取 GOBIN 中 executable 指定的文件路径.
|
||||||
func (*conf) GetGocode() string {
|
//
|
||||||
return getGOBIN() + "gocode"
|
// 函数内部会判断操作系统,如果是 Windows 则在 executable 实参后加入 .exe 后缀.
|
||||||
}
|
func (*conf) GetExecutableInGOBIN(executable string) string {
|
||||||
|
if util.OS.IsWindows() {
|
||||||
// 获取 ide_stub 路径.
|
executable += ".exe"
|
||||||
func (*conf) GetIDEStub() string {
|
|
||||||
return getGOBIN() + "ide_stub"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取 GOBIN 路径,末尾带路径分隔符.
|
|
||||||
func getGOBIN() string {
|
|
||||||
// $GOBIN/
|
|
||||||
ret := os.Getenv("GOBIN")
|
|
||||||
if "" != ret {
|
|
||||||
return ret + PathSeparator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// $GOPATH/bin/$GOOS_$GOARCH/
|
gopaths := strings.Split(os.Getenv("GOPATH"), PathListSeparator)
|
||||||
ret = os.Getenv("GOPATH") + PathSeparator + "bin" + PathSeparator +
|
|
||||||
os.Getenv("GOOS") + "_" + os.Getenv("GOARCH")
|
for _, gopath := range gopaths {
|
||||||
if isExist(ret) {
|
// $GOPATH/bin/$GOOS_$GOARCH/executable
|
||||||
return ret + PathSeparator
|
ret := gopath + PathSeparator + "bin" + PathSeparator +
|
||||||
|
os.Getenv("GOOS") + "_" + os.Getenv("GOARCH") + PathSeparator + executable
|
||||||
|
if isExist(ret) {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// $GOPATH/bin/{runtime.GOOS}_{runtime.GOARCH}/executable
|
||||||
|
ret = gopath + PathSeparator + "bin" + PathSeparator +
|
||||||
|
runtime.GOOS + "_" + runtime.GOARCH + PathSeparator + executable
|
||||||
|
if isExist(ret) {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// $GOPATH/bin/executable
|
||||||
|
ret = gopath + PathSeparator + "bin" + PathSeparator + executable
|
||||||
|
if isExist(ret) {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// $GOPATH/bin/{runtime.GOOS}_{runtime.GOARCH}/
|
// $GOBIN/executable
|
||||||
ret = os.Getenv("GOPATH") + PathSeparator + "bin" + PathSeparator +
|
return os.Getenv("GOBIN") + PathSeparator + executable
|
||||||
runtime.GOOS + "_" + runtime.GOARCH
|
|
||||||
if isExist(ret) {
|
|
||||||
return ret + PathSeparator
|
|
||||||
}
|
|
||||||
|
|
||||||
// $GOPATH/bin/
|
|
||||||
return os.Getenv("GOPATH") + PathSeparator + "bin" + PathSeparator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存 Wide 配置.
|
// 保存 Wide 配置.
|
||||||
|
|
|
@ -56,7 +56,7 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// glog.Infof("offset: %d", offset)
|
// glog.Infof("offset: %d", offset)
|
||||||
|
|
||||||
gocode := conf.Wide.GetGocode()
|
gocode := conf.Wide.GetExecutableInGOBIN("gocode")
|
||||||
argv := []string{"-f=json", "autocomplete", strconv.Itoa(offset)}
|
argv := []string{"-f=json", "autocomplete", strconv.Itoa(offset)}
|
||||||
|
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
|
@ -135,7 +135,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
glog.V(5).Infof("gocode set lib-path %s", libPath)
|
glog.V(5).Infof("gocode set lib-path %s", libPath)
|
||||||
|
|
||||||
// FIXME: 使用 gocode set lib-path 在多工作空间环境下肯定是有问题的,需要考虑其他实现方式
|
// FIXME: 使用 gocode set lib-path 在多工作空间环境下肯定是有问题的,需要考虑其他实现方式
|
||||||
gocode := conf.Wide.GetGocode()
|
gocode := conf.Wide.GetExecutableInGOBIN("gocode")
|
||||||
argv := []string{"set", "lib-path", libPath}
|
argv := []string{"set", "lib-path", libPath}
|
||||||
exec.Command(gocode, argv...).Run()
|
exec.Command(gocode, argv...).Run()
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// glog.Infof("offset [%d]", offset)
|
// glog.Infof("offset [%d]", offset)
|
||||||
|
|
||||||
// TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现
|
// TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现
|
||||||
ide_stub := conf.Wide.GetIDEStub()
|
ide_stub := conf.Wide.GetExecutableInGOBIN("ide_stub")
|
||||||
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-info", "."}
|
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-info", "."}
|
||||||
cmd := exec.Command(ide_stub, argv...)
|
cmd := exec.Command(ide_stub, argv...)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
@ -281,7 +281,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// glog.Infof("offset [%d]", offset)
|
// glog.Infof("offset [%d]", offset)
|
||||||
|
|
||||||
// TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现
|
// TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现
|
||||||
ide_stub := conf.Wide.GetIDEStub()
|
ide_stub := conf.Wide.GetExecutableInGOBIN("ide_stub")
|
||||||
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."}
|
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."}
|
||||||
cmd := exec.Command(ide_stub, argv...)
|
cmd := exec.Command(ide_stub, argv...)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
@ -363,7 +363,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// glog.Infof("offset [%d]", offset)
|
// glog.Infof("offset [%d]", offset)
|
||||||
|
|
||||||
// TODO: 目前是调用 liteide_stub 工具来查找使用,后续需要重新实现
|
// TODO: 目前是调用 liteide_stub 工具来查找使用,后续需要重新实现
|
||||||
ide_stub := conf.Wide.GetIDEStub()
|
ide_stub := conf.Wide.GetExecutableInGOBIN("ide_stub")
|
||||||
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-use", "."}
|
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-use", "."}
|
||||||
cmd := exec.Command(ide_stub, argv...)
|
cmd := exec.Command(ide_stub, argv...)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
|
|
@ -225,7 +225,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
suffix := ""
|
suffix := ""
|
||||||
if "windows" == runtime.GOOS {
|
if util.OS.IsWindows() {
|
||||||
suffix = ".exe"
|
suffix = ".exe"
|
||||||
}
|
}
|
||||||
executable := "main" + suffix
|
executable := "main" + suffix
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
type myos struct{}
|
||||||
|
|
||||||
|
// 操作系统工具.
|
||||||
|
var OS = myos{}
|
||||||
|
|
||||||
|
// 判断是否是 Windows 操作系统.
|
||||||
|
func (*myos) IsWindows() bool {
|
||||||
|
return "windows" == runtime.GOOS
|
||||||
|
}
|
Loading…
Reference in New Issue