workspace
This commit is contained in:
parent
77afacc3b1
commit
ad49df807c
|
@ -3,6 +3,7 @@ package editor
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/b3log/wide/conf"
|
||||||
"github.com/b3log/wide/user"
|
"github.com/b3log/wide/user"
|
||||||
"github.com/b3log/wide/util"
|
"github.com/b3log/wide/util"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
@ -137,6 +138,9 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//session, _ := user.Session.Get(r, "wide-session")
|
||||||
|
//username := session.Values["username"].(string)
|
||||||
|
|
||||||
code := args["code"].(string)
|
code := args["code"].(string)
|
||||||
line := int(args["cursorLine"].(float64))
|
line := int(args["cursorLine"].(float64))
|
||||||
ch := int(args["cursorCh"].(float64))
|
ch := int(args["cursorCh"].(float64))
|
||||||
|
@ -150,6 +154,10 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
|
|
||||||
cmd := exec.Command("gocode", argv...)
|
cmd := exec.Command("gocode", argv...)
|
||||||
|
|
||||||
|
// 设置环境变量(设置当前用户的 GOPATH 等)
|
||||||
|
// FIXME: setCmdEnv(cmd, username)
|
||||||
|
|
||||||
cmd.Stdout = &output
|
cmd.Stdout = &output
|
||||||
|
|
||||||
stdin, _ := cmd.StdinPipe()
|
stdin, _ := cmd.StdinPipe()
|
||||||
|
@ -173,3 +181,22 @@ func getCursorOffset(code string, line, ch int) (offset int) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
GOPATH := os.Getenv("GOPATH")
|
||||||
|
glog.Infof("Env GOPATH [%s]", GOPATH)
|
||||||
|
|
||||||
|
cmd.Env = append(cmd.Env,
|
||||||
|
"GOPATH="+userWorkspace+string(os.PathListSeparator)+
|
||||||
|
masterWorkspace+string(os.PathListSeparator)+
|
||||||
|
GOPATH,
|
||||||
|
"GOROOT="+os.Getenv("GOROOT"))
|
||||||
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
session, _ := user.Session.Get(r, "wide-session")
|
session, _ := user.Session.Get(r, "wide-session")
|
||||||
sid := session.Values["id"].(string)
|
sid := session.Values["id"].(string)
|
||||||
|
username := session.Values["username"].(string)
|
||||||
|
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
|
||||||
|
@ -155,7 +156,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
|
||||||
// 设置环境变量(设置当前用户的 GOPATH 等)
|
// 设置环境变量(设置当前用户的 GOPATH 等)
|
||||||
setCmdEnv(cmd)
|
setCmdEnv(cmd, username)
|
||||||
|
|
||||||
glog.Infof("go build -o %s %s", executable, filePath)
|
glog.Infof("go build -o %s %s", executable, filePath)
|
||||||
|
|
||||||
|
@ -218,7 +219,18 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCmdEnv(cmd *exec.Cmd) {
|
func setCmdEnv(cmd *exec.Cmd, username string) {
|
||||||
// TODO: 使用用户自己的仓库路径设置 GOPATH
|
userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1)
|
||||||
cmd.Env = append(cmd.Env, "GOPATH="+conf.Wide.Repos, "GOROOT="+os.Getenv("GOROOT"))
|
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="+userWorkspace+string(os.PathListSeparator)+
|
||||||
|
masterWorkspace+string(os.PathListSeparator)+
|
||||||
|
os.Getenv("GOPATH"),
|
||||||
|
"GOROOT="+os.Getenv("GOROOT"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue