Fix #21
This commit is contained in:
parent
a94d5c90a2
commit
c53029eabf
|
@ -161,7 +161,6 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
|
|
||||||
if err := decoder.Decode(&args); err != nil {
|
if err := decoder.Decode(&args); err != nil {
|
||||||
glog.Error(err)
|
glog.Error(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
|
@ -169,11 +168,11 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := args["file"].(string)
|
path := args["path"].(string)
|
||||||
curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))]
|
curDir := path[:strings.LastIndex(path, string(os.PathSeparator))]
|
||||||
filename := filePath[strings.LastIndex(filePath, string(os.PathSeparator))+1:]
|
filename := path[strings.LastIndex(path, string(os.PathSeparator))+1:]
|
||||||
|
|
||||||
fout, err := os.Create(filePath)
|
fout, err := os.Create(path)
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
glog.Error(err)
|
glog.Error(err)
|
||||||
|
@ -196,6 +195,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ch := int(args["cursorCh"].(float64))
|
ch := int(args["cursorCh"].(float64))
|
||||||
|
|
||||||
offset := getCursorOffset(code, line, ch)
|
offset := getCursorOffset(code, line, ch)
|
||||||
|
glog.Infof("offset [%d]", offset)
|
||||||
|
|
||||||
// TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现
|
// TODO: 目前是调用 liteide_stub 工具来查找声明,后续需要重新实现
|
||||||
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."}
|
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."}
|
||||||
|
@ -221,11 +221,11 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
part := found[:strings.LastIndex(found, ":")]
|
part := found[:strings.LastIndex(found, ":")]
|
||||||
cursorSep := strings.LastIndex(part, ":")
|
cursorSep := strings.LastIndex(part, ":")
|
||||||
path := found[:cursorSep]
|
path = found[:cursorSep]
|
||||||
cursorLine := found[cursorSep+1 : strings.LastIndex(found, ":")]
|
cursorLine := found[cursorSep+1 : strings.LastIndex(found, ":")]
|
||||||
cursorCh := found[strings.LastIndex(found, ":")+1:]
|
cursorCh := found[strings.LastIndex(found, ":")+1:]
|
||||||
|
|
||||||
// glog.Infof("%s\n%s\n%s\n%s", found, path, cursorLine, cursorCh)
|
glog.Infof("Find Decl [path: %s, cursor(%s:%s)]", path, cursorLine, cursorCh)
|
||||||
|
|
||||||
data["path"] = path
|
data["path"] = path
|
||||||
data["cursorLine"] = cursorLine
|
data["cursorLine"] = cursorLine
|
||||||
|
@ -316,21 +316,31 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
usages = append(usages, usage)
|
usages = append(usages, usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// glog.Infof("%s\n%s\n%s\n%s", found, path, cursorLine, cursorCh)
|
|
||||||
|
|
||||||
data["usages"] = usages
|
data["usages"] = usages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算光标偏移位置.
|
||||||
|
// line 指定了行号(第一行为 0),ch 指定了列号(第一列为 0).
|
||||||
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")
|
||||||
|
|
||||||
|
// 计算前几行长度
|
||||||
for i := 0; i < line; i++ {
|
for i := 0; i < line; i++ {
|
||||||
offset += len(lines[i])
|
offset += len(lines[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += line + ch
|
// 计算当前行、当前列长度
|
||||||
|
curLine := lines[line]
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
r := []rune(curLine)
|
||||||
|
for i := 0; i < ch; i++ {
|
||||||
|
buffer.WriteString(string(r[i]))
|
||||||
|
}
|
||||||
|
|
||||||
return
|
offset += line // 加换行符
|
||||||
|
offset += len(buffer.String()) // 加当前行列偏移
|
||||||
|
|
||||||
|
return offset
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCmdEnv(cmd *exec.Cmd, username string) {
|
func setCmdEnv(cmd *exec.Cmd, username string) {
|
||||||
|
|
|
@ -105,6 +105,7 @@ func GetFile(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
data["content"] = string(buf)
|
data["content"] = string(buf)
|
||||||
data["mode"] = getEditorMode(extension)
|
data["mode"] = getEditorMode(extension)
|
||||||
|
data["path"] = path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ var editors = {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wide.curEditor.focus();
|
||||||
},
|
},
|
||||||
removeAfter: function(id, nextId) {
|
removeAfter: function(id, nextId) {
|
||||||
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
||||||
|
@ -130,7 +132,7 @@ var editors = {
|
||||||
var cur = wide.curEditor.getCursor();
|
var cur = wide.curEditor.getCursor();
|
||||||
|
|
||||||
var request = {
|
var request = {
|
||||||
file: $(".edit-header .current").data("index"),
|
path: $(".edit-header .current > span:eq(0)").attr("title"),
|
||||||
code: wide.curEditor.getValue(),
|
code: wide.curEditor.getValue(),
|
||||||
cursorLine: cur.line,
|
cursorLine: cur.line,
|
||||||
cursorCh: cur.ch
|
cursorCh: cur.ch
|
||||||
|
@ -146,6 +148,9 @@ var editors = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cursorLine = data.cursorLine;
|
||||||
|
var cursorCh = data.cursorCh;
|
||||||
|
|
||||||
var request = {
|
var request = {
|
||||||
path: data.path
|
path: data.path
|
||||||
};
|
};
|
||||||
|
@ -162,10 +167,12 @@ var editors = {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: V, 这个可能不在文件树里,但是也需要打开一个编辑器
|
var tId = tree.getTIdByPath(data.path);
|
||||||
// 打开一个新编辑器并定位到跳转的行列
|
wide.curNode = tree.fileTree.getNodeByTId(tId);
|
||||||
var line = data.cursorLine;
|
tree.fileTree.selectNode(wide.curNode);
|
||||||
var ch = data.cursorCh;
|
|
||||||
|
data.cursorLine = cursorLine;
|
||||||
|
data.cursorCh = cursorCh;
|
||||||
editors.newEditor(data);
|
editors.newEditor(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -200,13 +207,24 @@ var editors = {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
// 新建一个编辑器 Tab,如果已经存在 Tab 则切换到该 Tab.
|
||||||
newEditor: function(data) {
|
newEditor: function(data) {
|
||||||
$(".ico-fullscreen").show();
|
$(".ico-fullscreen").show();
|
||||||
var id = wide.curNode.tId;
|
var id = wide.curNode.tId;
|
||||||
|
|
||||||
|
// 光标位置
|
||||||
|
var cursor = CodeMirror.Pos(0, 0);
|
||||||
|
if (data.cursorLine && data.cursorCh) {
|
||||||
|
cursor = CodeMirror.Pos(data.cursorLine - 1, data.cursorCh - 1);
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
||||||
if (editors.data[i].id === id) {
|
if (editors.data[i].id === id) {
|
||||||
editors.tabs.setCurrent(id);
|
editors.tabs.setCurrent(id);
|
||||||
wide.curEditor = editors.data[i].editor;
|
wide.curEditor = editors.data[i].editor;
|
||||||
|
wide.curEditor.setCursor(cursor);
|
||||||
|
wide.curEditor.focus();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,11 +236,12 @@ var editors = {
|
||||||
content: '<textarea id="editor' + id + '"></textarea>'
|
content: '<textarea id="editor' + id + '"></textarea>'
|
||||||
});
|
});
|
||||||
|
|
||||||
rulers = [];
|
var rulers = [];
|
||||||
rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"});
|
rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"});
|
||||||
|
|
||||||
var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), {
|
var editor = CodeMirror.fromTextArea(document.getElementById("editor" + id), {
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
|
autofocus: true,
|
||||||
autoCloseBrackets: true,
|
autoCloseBrackets: true,
|
||||||
matchBrackets: true,
|
matchBrackets: true,
|
||||||
highlightSelectionMatches: {showToken: /\w/},
|
highlightSelectionMatches: {showToken: /\w/},
|
||||||
|
@ -262,6 +281,8 @@ var editors = {
|
||||||
editor.setValue(data.content);
|
editor.setValue(data.content);
|
||||||
editor.setOption("mode", data.mode);
|
editor.setOption("mode", data.mode);
|
||||||
|
|
||||||
|
editor.setCursor(cursor);
|
||||||
|
|
||||||
editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]);
|
editor.setOption("gutters", ["CodeMirror-lint-markers", "CodeMirror-foldgutter"]);
|
||||||
|
|
||||||
if ("text/x-go" === data.mode || "application/json" === data.mode) {
|
if ("text/x-go" === data.mode || "application/json" === data.mode) {
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
var menu = {
|
var menu = {
|
||||||
init: function() {
|
init: function() {
|
||||||
this.subMenu();
|
this.subMenu();
|
||||||
|
|
||||||
|
// 点击子菜单后消失
|
||||||
|
$(".frame li").click(function() {
|
||||||
|
$(this).closest(".frame").hide();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
subMenu: function () {
|
// 焦点不在菜单上时需点击展开子菜单,否则为鼠标移动展开
|
||||||
|
subMenu: function() {
|
||||||
$(".menu > ul > li > a, .menu > ul> li > span").click(function() {
|
$(".menu > ul > li > a, .menu > ul> li > span").click(function() {
|
||||||
var $it = $(this);
|
var $it = $(this);
|
||||||
$it.next().show();
|
$it.next().show();
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
var tree = {
|
var tree = {
|
||||||
|
getTIdByPath: function (path) {
|
||||||
|
var nodes = tree.fileTree.transformToArray(tree.fileTree.getNodes());
|
||||||
|
for (var i = 0, ii = nodes.length; i < ii; i++) {
|
||||||
|
if (nodes[i].path === path) {
|
||||||
|
return nodes[i].tId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
fileTree: undefined,
|
fileTree: undefined,
|
||||||
_isParents: function(tId, parentTId) {
|
_isParents: function(tId, parentTId) {
|
||||||
var node = tree.fileTree.getNodeByTId(tId);
|
var node = tree.fileTree.getNodeByTId(tId);
|
||||||
|
|
Loading…
Reference in New Issue