用户工作空间自动完成

This commit is contained in:
Liang Ding 2014-09-04 23:48:49 +08:00
parent 4ff11fb733
commit fcfe3eb221
2 changed files with 17 additions and 10 deletions

View File

@ -169,7 +169,8 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
// FIXME: 使用 gocode set lib-path 在多工作空间环境下肯定是有问题的,需要考虑其他实现方式
argv := []string{"set", "lib-path", libPath}
exec.Command("gocode", argv...).Start()
cmd := exec.Command("gocode", argv...)
cmd.Start()
//argv = []string{"set", "autobuild", "true"}
//cmd := exec.Command("gocode", argv...)

View File

@ -199,6 +199,17 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
buf := make([]byte, 1024*8)
count, _ := reader.Read(buf)
if 0 == count { // 说明构建成功,没有错误信息输出
go func() { // 运行 go install生成的库用于 gocode lib-path
cmd := exec.Command("go", "install")
cmd.Dir = curDir
setCmdEnv(cmd, username)
cmd.Start()
}()
}
channelRet := map[string]interface{}{}
channelRet["output"] = string(buf[:count])
@ -223,14 +234,9 @@ func setCmdEnv(cmd *exec.Cmd, username string) {
userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1)
userWorkspace := userRepos[:strings.LastIndex(userRepos, "/src")]
// glog.Infof("User [%s] workspace [%s]", username, userWorkspace)
masterWorkspace := conf.Wide.Repos[:strings.LastIndex(conf.Wide.Repos, "/src")]
// glog.Infof("Master workspace [%s]", masterWorkspace)
cmd.Env = append(cmd.Env,
"GOPATH="+os.Getenv("GOPATH")+string(os.PathListSeparator)+
userWorkspace+string(os.PathListSeparator)+
masterWorkspace,
"GOROOT="+os.Getenv("GOROOT"))
"GOPATH="+userWorkspace,
"GOOS="+runtime.GOOS,
"GOARCH="+runtime.GOARCH,
"GOROOT="+runtime.GOROOT())
}