This commit is contained in:
Liang Ding 2014-09-12 10:10:21 +08:00
parent ff415b35b3
commit 0f43513a57
3 changed files with 47 additions and 6 deletions

View File

@ -8,7 +8,7 @@
<body> <body>
<h1>Wide</h1> <h1>Wide</h1>
<p> <p>
Wide 是一个基于 Web 的 golang 在线 IDE。 Wide 是一个基于 Web 的 golang 开源 IDE。
</p> </p>
<h2><a href="motivation.html">动机</a></h2> <h2><a href="motivation.html">动机</a></h2>

View File

@ -187,9 +187,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
offset := getCursorOffset(code, line, ch) offset := getCursorOffset(code, line, ch)
// liteide_stub type -cursor main.go:318 -def . // TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现
glog.Info(filename, offset)
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."} argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."}
cmd := exec.Command("liteide_stub", argv...) cmd := exec.Command("liteide_stub", argv...)
cmd.Dir = curDir cmd.Dir = curDir
@ -204,8 +202,24 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
// TODO: 解析返回 found := strings.TrimSpace(string(output))
glog.Info(string(output)) if "" == found {
data["succ"] = false
return
}
part := found[:strings.LastIndex(found, ":")]
cursorSep := strings.LastIndex(part, ":")
path := found[:cursorSep]
cursorLine := found[cursorSep+1 : strings.LastIndex(found, ":")]
cursorCh := found[strings.LastIndex(found, ":")+1:]
// glog.Infof("%s\n%s\n%s\n%s", found, path, cursorLine, cursorCh)
data["path"] = path
data["cursorLine"] = cursorLine
data["cursorCh"] = cursorCh
} }
func getCursorOffset(code string, line, ch int) (offset int) { func getCursorOffset(code string, line, ch int) (offset int) {

View File

@ -142,6 +142,33 @@ var editors = {
data: JSON.stringify(request), data: JSON.stringify(request),
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
if (!data.succ) {
return;
}
// 打开一个新编辑器并定位到跳转的行列
var line = data.cursorLine;
var request = {
path: data.path
};
$.ajax({
type: 'POST',
url: '/file',
data: JSON.stringify(request),
dataType: "json",
success: function(data) {
if (!data.succ) {
alert(data.msg);
return false;
}
// FIXME: V, 这个可能不在文件树里,但是也需要打开一个编辑器
editors.newEditor(data);
}
});
} }
}); });
}; };