This commit is contained in:
parent
287fc618a0
commit
ef32199984
|
@ -74,6 +74,7 @@ func GetOutline(w http.ResponseWriter, r *http.Request) {
|
||||||
constDecls := []*element{}
|
constDecls := []*element{}
|
||||||
structDecls := []*element{}
|
structDecls := []*element{}
|
||||||
interfaceDecls := []*element{}
|
interfaceDecls := []*element{}
|
||||||
|
typeDecls := []*element{}
|
||||||
for _, decl := range f.Decls {
|
for _, decl := range f.Decls {
|
||||||
switch decl.(type) {
|
switch decl.(type) {
|
||||||
case *ast.FuncDecl:
|
case *ast.FuncDecl:
|
||||||
|
@ -98,12 +99,15 @@ func GetOutline(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
case token.TYPE:
|
case token.TYPE:
|
||||||
typeSpec := spec.(*ast.TypeSpec)
|
typeSpec := spec.(*ast.TypeSpec)
|
||||||
|
line, ch := getCursor(code, int(typeSpec.Pos()))
|
||||||
|
|
||||||
switch typeSpec.Type.(type) {
|
switch typeSpec.Type.(type) {
|
||||||
case *ast.StructType:
|
case *ast.StructType:
|
||||||
structDecls = append(structDecls, &element{Name: typeSpec.Name.Name, Line: line, Ch: ch})
|
structDecls = append(structDecls, &element{Name: typeSpec.Name.Name, Line: line, Ch: ch})
|
||||||
case *ast.InterfaceType:
|
case *ast.InterfaceType:
|
||||||
interfaceDecls = append(interfaceDecls, &element{Name: typeSpec.Name.Name, Line: line, Ch: ch})
|
interfaceDecls = append(interfaceDecls, &element{Name: typeSpec.Name.Name, Line: line, Ch: ch})
|
||||||
|
case *ast.Ident:
|
||||||
|
typeDecls = append(typeDecls, &element{Name: typeSpec.Name.Name, Line: line, Ch: ch})
|
||||||
}
|
}
|
||||||
case token.CONST:
|
case token.CONST:
|
||||||
constSpec := spec.(*ast.ValueSpec)
|
constSpec := spec.(*ast.ValueSpec)
|
||||||
|
@ -123,6 +127,7 @@ func GetOutline(w http.ResponseWriter, r *http.Request) {
|
||||||
data["constDecls"] = constDecls
|
data["constDecls"] = constDecls
|
||||||
data["structDecls"] = structDecls
|
data["structDecls"] = structDecls
|
||||||
data["interfaceDecls"] = interfaceDecls
|
data["interfaceDecls"] = interfaceDecls
|
||||||
|
data["typeDecls"] = typeDecls
|
||||||
}
|
}
|
||||||
|
|
||||||
// getCursor calculates the cursor position (line, ch) by the specified offset.
|
// getCursor calculates the cursor position (line, ch) by the specified offset.
|
||||||
|
|
Loading…
Reference in New Issue