** find node that fully contains given text range */
(r core.TextRange, sourceFile *ast.SourceFile)
| 18 | |
| 19 | /** find node that fully contains given text range */ |
| 20 | func findEnclosingNode(r core.TextRange, sourceFile *ast.SourceFile) *ast.Node { |
| 21 | var find func(*ast.Node) *ast.Node |
| 22 | find = func(n *ast.Node) *ast.Node { |
| 23 | var candidate *ast.Node |
| 24 | n.ForEachChild(func(c *ast.Node) bool { |
| 25 | if c.Flags&ast.NodeFlagsReparsed != 0 { |
| 26 | return false |
| 27 | } |
| 28 | if r.ContainedBy(withTokenStart(c, sourceFile)) { |
| 29 | candidate = c |
| 30 | return true |
| 31 | } |
| 32 | return false |
| 33 | }) |
| 34 | if candidate != nil { |
| 35 | result := find(candidate) |
| 36 | if result != nil { |
| 37 | return result |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return n |
| 42 | } |
| 43 | return find(sourceFile.AsNode()) |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Start of the original range might fall inside the comment - scanner will not yield appropriate results |
no test coverage detected