mirror of
https://github.com/go-delve/delve.git
synced 2025-10-30 02:07:58 +08:00
Handle defer blocks when next'ing
This commit is contained in:
@ -63,3 +63,10 @@ func decltest() {
|
|||||||
var baz = 9
|
var baz = 9
|
||||||
fmt.Println(foo, baz)
|
fmt.Println(foo, baz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func defertest() {
|
||||||
|
defer func() {
|
||||||
|
fmt.Println("this is a useless defer")
|
||||||
|
}()
|
||||||
|
fmt.Println("I should get here")
|
||||||
|
}
|
||||||
|
|||||||
@ -162,6 +162,7 @@ func (s *Searcher) NextLines(fname string, line int) (lines []int, err error) {
|
|||||||
var (
|
var (
|
||||||
parents []*ast.BlockStmt
|
parents []*ast.BlockStmt
|
||||||
parentBlockBeginLine int
|
parentBlockBeginLine int
|
||||||
|
deferEndLine int
|
||||||
)
|
)
|
||||||
f, err := s.parse(fname)
|
f, err := s.parse(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -174,6 +175,17 @@ func (s *Searcher) NextLines(fname string, line int) (lines []int, err error) {
|
|||||||
if n == nil {
|
if n == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pos := s.fileset.Position(n.Pos())
|
||||||
|
if line < pos.Line && deferEndLine != 0 {
|
||||||
|
p := s.fileset.Position(n.Pos())
|
||||||
|
if deferEndLine < p.Line {
|
||||||
|
found = true
|
||||||
|
lines = append(lines, p.Line)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if stmt, ok := n.(*ast.ForStmt); ok {
|
if stmt, ok := n.(*ast.ForStmt); ok {
|
||||||
parents = append(parents, stmt.Body)
|
parents = append(parents, stmt.Body)
|
||||||
pos := s.fileset.Position(stmt.Pos())
|
pos := s.fileset.Position(stmt.Pos())
|
||||||
@ -184,6 +196,13 @@ func (s *Searcher) NextLines(fname string, line int) (lines []int, err error) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dn, ok := n.(*ast.DeferStmt); ok {
|
||||||
|
fmt.Println("defer")
|
||||||
|
endpos := s.fileset.Position(dn.End())
|
||||||
|
deferEndLine = endpos.Line
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if st, ok := n.(*ast.DeclStmt); ok {
|
if st, ok := n.(*ast.DeclStmt); ok {
|
||||||
beginpos := s.fileset.Position(st.Pos())
|
beginpos := s.fileset.Position(st.Pos())
|
||||||
endpos := s.fileset.Position(st.End())
|
endpos := s.fileset.Position(st.End())
|
||||||
@ -193,7 +212,6 @@ func (s *Searcher) NextLines(fname string, line int) (lines []int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if we've found the "next" line.
|
// Check to see if we've found the "next" line.
|
||||||
pos := s.fileset.Position(n.Pos())
|
|
||||||
if line < pos.Line {
|
if line < pos.Line {
|
||||||
if _, ok := n.(*ast.BlockStmt); ok {
|
if _, ok := n.(*ast.BlockStmt); ok {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@ -40,6 +40,7 @@ func TestNextLines(t *testing.T) {
|
|||||||
{57, []int{55}},
|
{57, []int{55}},
|
||||||
{30, []int{32}},
|
{30, []int{32}},
|
||||||
{62, []int{63}},
|
{62, []int{63}},
|
||||||
|
{67, []int{71}},
|
||||||
}
|
}
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
lines, err := v.NextLines(tf, c.line)
|
lines, err := v.NextLines(tf, c.line)
|
||||||
|
|||||||
Reference in New Issue
Block a user