This commit is contained in:
parent
d7079781dd
commit
dc65f78c2e
|
@ -8,6 +8,7 @@
|
||||||
<body>
|
<body>
|
||||||
<h1>键盘快捷键</h1>
|
<h1>键盘快捷键</h1>
|
||||||
|
|
||||||
|
Done:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Ctrl+G: 跳转到行</li>
|
<li>Ctrl+G: 跳转到行</li>
|
||||||
<li>Ctrl+\\: 自动补全</li>
|
<li>Ctrl+\\: 自动补全</li>
|
||||||
|
@ -17,5 +18,17 @@
|
||||||
<li>Ctrl+]: 缩进</li>
|
<li>Ctrl+]: 缩进</li>
|
||||||
<li>Ctrl+[: 反缩进</li>
|
<li>Ctrl+[: 反缩进</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
In Process:
|
||||||
|
<ul>
|
||||||
|
<li>Ctrl+B:跳转到声明</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
<ul>
|
||||||
|
<li>Ctrl+1:焦点切换到文件树</li>
|
||||||
|
<li>Ctrl+0:焦点切换到编辑器</li>
|
||||||
|
<li>Ctrl+4:焦点切换到 Output</li>
|
||||||
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/b3log/wide/conf"
|
"github.com/b3log/wide/conf"
|
||||||
"github.com/b3log/wide/user"
|
"github.com/b3log/wide/user"
|
||||||
|
"github.com/b3log/wide/util"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
@ -97,7 +98,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// glog.Infof("offset: %d", offset)
|
// glog.Infof("offset: %d", offset)
|
||||||
|
|
||||||
userWorkspace := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username
|
userWorkspace := conf.Wide.GetUserWorkspace(username)
|
||||||
|
|
||||||
//glog.Infof("User [%s] workspace [%s]", username, userWorkspace)
|
//glog.Infof("User [%s] workspace [%s]", username, userWorkspace)
|
||||||
userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) +
|
userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) +
|
||||||
|
@ -116,6 +117,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
cmd := exec.Command("gocode", argv...)
|
cmd := exec.Command("gocode", argv...)
|
||||||
cmd.Start()
|
cmd.Start()
|
||||||
|
|
||||||
|
//gocode 试验性质特性:自动构建
|
||||||
//argv = []string{"set", "autobuild", "true"}
|
//argv = []string{"set", "autobuild", "true"}
|
||||||
//cmd := exec.Command("gocode", argv...)
|
//cmd := exec.Command("gocode", argv...)
|
||||||
//cmd.Start()
|
//cmd.Start()
|
||||||
|
@ -139,6 +141,73 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(output)
|
w.Write(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data := map[string]interface{}{"succ": true}
|
||||||
|
defer util.RetJSON(w, r, data)
|
||||||
|
|
||||||
|
session, _ := user.Session.Get(r, "wide-session")
|
||||||
|
username := session.Values["username"].(string)
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
|
||||||
|
var args map[string]interface{}
|
||||||
|
|
||||||
|
if err := decoder.Decode(&args); err != nil {
|
||||||
|
glog.Error(err)
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath := args["file"].(string)
|
||||||
|
curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))]
|
||||||
|
filename := filePath[strings.LastIndex(filePath, string(os.PathSeparator))+1:]
|
||||||
|
|
||||||
|
fout, err := os.Create(filePath)
|
||||||
|
|
||||||
|
if nil != err {
|
||||||
|
glog.Error(err)
|
||||||
|
data["succ"] = false
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
code := args["code"].(string)
|
||||||
|
fout.WriteString(code)
|
||||||
|
|
||||||
|
if err := fout.Close(); nil != err {
|
||||||
|
glog.Error(err)
|
||||||
|
data["succ"] = false
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
line := int(args["cursorLine"].(float64))
|
||||||
|
ch := int(args["cursorCh"].(float64))
|
||||||
|
|
||||||
|
offset := getCursorOffset(code, line, ch)
|
||||||
|
|
||||||
|
// liteide_stub type -cursor main.go:318 -def .
|
||||||
|
glog.Info(filename, offset)
|
||||||
|
|
||||||
|
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."}
|
||||||
|
cmd := exec.Command("liteide_stub", argv...)
|
||||||
|
cmd.Dir = curDir
|
||||||
|
|
||||||
|
setCmdEnv(cmd, username)
|
||||||
|
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if nil != err {
|
||||||
|
glog.Error(err)
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: 解析返回
|
||||||
|
glog.Info(string(output))
|
||||||
|
}
|
||||||
|
|
||||||
func getCursorOffset(code string, line, ch int) (offset int) {
|
func getCursorOffset(code string, line, ch int) (offset int) {
|
||||||
lines := strings.Split(code, "\n")
|
lines := strings.Split(code, "\n")
|
||||||
|
|
||||||
|
@ -150,3 +219,14 @@ func getCursorOffset(code string, line, ch int) (offset int) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setCmdEnv(cmd *exec.Cmd, username string) {
|
||||||
|
userWorkspace := conf.Wide.GetUserWorkspace(username)
|
||||||
|
|
||||||
|
cmd.Env = append(cmd.Env,
|
||||||
|
"GOPATH="+userWorkspace,
|
||||||
|
"GOOS="+runtime.GOOS,
|
||||||
|
"GOARCH="+runtime.GOARCH,
|
||||||
|
"GOROOT="+runtime.GOROOT(),
|
||||||
|
"PATH="+os.Getenv("PATH"))
|
||||||
|
}
|
||||||
|
|
1
main.go
1
main.go
|
@ -93,6 +93,7 @@ func main() {
|
||||||
http.HandleFunc("/editor/ws", editor.WSHandler)
|
http.HandleFunc("/editor/ws", editor.WSHandler)
|
||||||
http.HandleFunc("/go/fmt", editor.GoFmtHandler)
|
http.HandleFunc("/go/fmt", editor.GoFmtHandler)
|
||||||
http.HandleFunc("/autocomplete", editor.AutocompleteHandler)
|
http.HandleFunc("/autocomplete", editor.AutocompleteHandler)
|
||||||
|
http.HandleFunc("/finddecl", editor.FindDeclarationHandler)
|
||||||
http.HandleFunc("/html/fmt", editor.HTMLFmtHandler)
|
http.HandleFunc("/html/fmt", editor.HTMLFmtHandler)
|
||||||
http.HandleFunc("/json/fmt", editor.JSONFmtHandler)
|
http.HandleFunc("/json/fmt", editor.JSONFmtHandler)
|
||||||
|
|
||||||
|
|
|
@ -462,7 +462,4 @@ func setCmdEnv(cmd *exec.Cmd, username string) {
|
||||||
"GOARCH="+runtime.GOARCH,
|
"GOARCH="+runtime.GOARCH,
|
||||||
"GOROOT="+runtime.GOROOT(),
|
"GOROOT="+runtime.GOROOT(),
|
||||||
"PATH="+os.Getenv("PATH"))
|
"PATH="+os.Getenv("PATH"))
|
||||||
|
|
||||||
//"TERM="+os.Getenv("COMSPEC"),
|
|
||||||
//"ComSpec="+os.Getenv("ComSpec")
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,26 @@ var editors = {
|
||||||
|
|
||||||
CodeMirror.commands.doNothing = function(cm) {
|
CodeMirror.commands.doNothing = function(cm) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CodeMirror.commands.jumpToDecl = function(cm) {
|
||||||
|
var cur = wide.curEditor.getCursor();
|
||||||
|
|
||||||
|
var request = {
|
||||||
|
file: wide.curNode.path,
|
||||||
|
code: wide.curEditor.getValue(),
|
||||||
|
cursorLine: cur.line,
|
||||||
|
cursorCh: cur.ch
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '/finddecl',
|
||||||
|
data: JSON.stringify(request),
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
},
|
},
|
||||||
newEditor: function(data) {
|
newEditor: function(data) {
|
||||||
$(".ico-fullscreen").show();
|
$(".ico-fullscreen").show();
|
||||||
|
@ -169,7 +189,8 @@ var editors = {
|
||||||
},
|
},
|
||||||
"Ctrl-G": "gotoLine",
|
"Ctrl-G": "gotoLine",
|
||||||
"Ctrl-E": "deleteLine",
|
"Ctrl-E": "deleteLine",
|
||||||
"Ctrl-D": "doNothing" // 取消默认的 deleteLine
|
"Ctrl-D": "doNothing", // 取消默认的 deleteLine
|
||||||
|
"Ctrl-B": "jumpToDecl"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue