This commit is contained in:
Liang Ding 2014-12-30 12:04:16 +08:00
parent edbecccec3
commit 8d0ae1d7d1
2 changed files with 107 additions and 11 deletions

View File

@ -24,6 +24,12 @@ import (
"github.com/b3log/wide/util" "github.com/b3log/wide/util"
) )
type element struct {
Name string
Pos token.Pos
End token.Pos
}
// GetOutline gets outfile of a go file. // GetOutline gets outfile of a go file.
func GetOutline(w http.ResponseWriter, r *http.Request) { func GetOutline(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} data := map[string]interface{}{"succ": true}
@ -46,5 +52,67 @@ func GetOutline(w http.ResponseWriter, r *http.Request) {
panic(err) panic(err)
} }
ast.Print(fset, f) //ast.Print(fset, f)
data["package"] = &element{Name: f.Name.Name, Pos: f.Name.Pos(), End: f.Name.End()}
imports := []*element{}
for _, astImport := range f.Imports {
impt := &element{Name: astImport.Path.Value, Pos: astImport.Path.Pos(), End: astImport.Path.End()}
imports = append(imports, impt)
}
data["imports"] = imports
funcDecls := []*element{}
varDecls := []*element{}
constDecls := []*element{}
structDecls := []*element{}
interfaceDecls := []*element{}
for _, decl := range f.Decls {
switch decl.(type) {
case *ast.FuncDecl:
funcDecl := decl.(*ast.FuncDecl)
decl := &element{Name: funcDecl.Name.Name, Pos: funcDecl.Name.Pos(), End: funcDecl.Name.End()}
funcDecls = append(funcDecls, decl)
case *ast.GenDecl:
genDecl := decl.(*ast.GenDecl)
for _, spec := range genDecl.Specs {
switch genDecl.Tok {
case token.VAR:
variableSpec := spec.(*ast.ValueSpec)
decl := &element{Name: variableSpec.Names[0].Name, Pos: variableSpec.Pos(), End: variableSpec.End()}
varDecls = append(varDecls, decl)
case token.TYPE:
typeSpec := spec.(*ast.TypeSpec)
decl := &element{Name: typeSpec.Name.Name, Pos: typeSpec.Name.Pos(), End: typeSpec.Name.End()}
switch typeSpec.Type.(type) {
case *ast.StructType:
structDecls = append(structDecls, decl)
case *ast.InterfaceType:
interfaceDecls = append(interfaceDecls, decl)
}
case token.CONST:
constSpec := spec.(*ast.ValueSpec)
decl := &element{Name: constSpec.Names[0].Name, Pos: constSpec.Pos(), End: constSpec.End()}
constDecls = append(constDecls, decl)
}
}
}
}
data["funcDecls"] = funcDecls
data["varDecls"] = varDecls
data["constDecls"] = constDecls
data["structDecls"] = structDecls
data["interfaceDecls"] = interfaceDecls
} }

View File

@ -16,7 +16,7 @@
var hotkeys = { var hotkeys = {
defaultKeyMap: { defaultKeyMap: {
// Ctrl-0 焦点切换到当前编辑器 // Ctrl-0
goEditor: { goEditor: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
@ -28,7 +28,7 @@ var hotkeys = {
} }
} }
}, },
// Ctrl-1 焦点切换到文件树 // Ctrl-1
goFileTree: { goFileTree: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
@ -51,7 +51,27 @@ var hotkeys = {
$("#files").focus(); $("#files").focus();
} }
}, },
// Ctrl-4 焦点切换到输出窗口 goOutline: {
ctrlKey: true,
altKey: false,
shiftKey: false,
which: 50,
fun: function () {
var request = newWideRequest();
request.code = wide.curEditor.getValue();
$.ajax({
type: 'POST',
url: config.context + '/outline',
data: JSON.stringify(request),
dataType: "json",
success: function (data) {
console.log(data);
}
});
}
},
// Ctrl-4
goOutput: { goOutput: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
@ -63,7 +83,7 @@ var hotkeys = {
$(".bottom-window-group .output").focus(); $(".bottom-window-group .output").focus();
} }
}, },
// Ctrl-5 焦点切换到搜索窗口 // Ctrl-5
goSearch: { goSearch: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
@ -75,7 +95,7 @@ var hotkeys = {
$(".bottom-window-group .search").focus(); $(".bottom-window-group .search").focus();
} }
}, },
// Ctrl-6 焦点切换到通知窗口 // Ctrl-6
goNotification: { goNotification: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
@ -87,7 +107,7 @@ var hotkeys = {
$(".bottom-window-group .notification").focus(); $(".bottom-window-group .notification").focus();
} }
}, },
// Ctrl-C 清空窗口内容 // Ctrl-C
clearWindow: { clearWindow: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
@ -101,21 +121,21 @@ var hotkeys = {
shiftKey: false, shiftKey: false,
which: 68 which: 68
}, },
// Ctrl-F 搜索 // Ctrl-F search
search: { search: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
shiftKey: false, shiftKey: false,
which: 70 which: 70
}, },
// Ctrl-Q 关闭当前编辑器 // Ctrl-Q close current editor
closeCurEditor: { closeCurEditor: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
shiftKey: false, shiftKey: false,
which: 81 which: 81
}, },
// Ctrl-R 重命名 // Ctrl-R
rename: { rename: {
ctrlKey: true, ctrlKey: true,
altKey: false, altKey: false,
@ -366,6 +386,14 @@ var hotkeys = {
return; return;
} }
if (event.ctrlKey === hotKeys.goOutline.ctrlKey
&& event.which === hotKeys.goOutline.which) { // Ctrl-2 焦点切换到大纲
hotKeys.goOutline.fun();
event.preventDefault();
return;
}
if (event.ctrlKey === hotKeys.goOutput.ctrlKey if (event.ctrlKey === hotKeys.goOutput.ctrlKey
&& event.which === hotKeys.goOutput.which) { // Ctrl-4 焦点切换到输出窗口 && event.which === hotKeys.goOutput.which) { // Ctrl-4 焦点切换到输出窗口
hotKeys.goOutput.fun(); hotKeys.goOutput.fun();