diff --git a/doc/zh_CN/index.html b/doc/zh_CN/index.html index f45b326..fd377e3 100644 --- a/doc/zh_CN/index.html +++ b/doc/zh_CN/index.html @@ -8,7 +8,7 @@

Wide

- Wide 是一个基于 Web 的 golang 在线 IDE。 + Wide 是一个基于 Web 的 golang 开源 IDE。

动机

diff --git a/editor/editors.go b/editor/editors.go index 61f9725..5213103 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -187,9 +187,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { offset := getCursorOffset(code, line, ch) - // liteide_stub type -cursor main.go:318 -def . - glog.Info(filename, offset) - + // TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现 argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."} cmd := exec.Command("liteide_stub", argv...) cmd.Dir = curDir @@ -204,8 +202,24 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { return } - // TODO: 解析返回 - glog.Info(string(output)) + found := strings.TrimSpace(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) { diff --git a/static/js/editor.js b/static/js/editor.js index 6dc20e9..9a9cbee 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -142,6 +142,33 @@ var editors = { data: JSON.stringify(request), dataType: "json", 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); + } + }); } }); };