@@ -61,8 +61,13 @@ object NavigateAST {
61
61
/** The reverse path from node `from` to the node that closest encloses position `pos`,
62
62
* or `Nil` if no such path exists. If a non-empty path is returned it starts with
63
63
* the node closest enclosing `pos` and ends with `from`.
64
+ *
65
+ * @param skipZeroExtent If true, skip over zero-extent nodes in the search. These nodes
66
+ * do not correspond to code the user wrote since their start and
67
+ * end point are the same, so this is useful when trying to reconcile
68
+ * nodes with source code.
64
69
*/
65
- def pathTo (pos : Position , from : Positioned )(implicit ctx : Context ): List [Positioned ] = {
70
+ def pathTo (pos : Position , from : Positioned , skipZeroExtent : Boolean = false )(implicit ctx : Context ): List [Positioned ] = {
66
71
def childPath (it : Iterator [Any ], path : List [Positioned ]): List [Positioned ] = {
67
72
while (it.hasNext) {
68
73
val path1 = it.next match {
@@ -75,7 +80,7 @@ object NavigateAST {
75
80
path
76
81
}
77
82
def singlePath (p : Positioned , path : List [Positioned ]): List [Positioned ] =
78
- if (p.pos contains pos) {
83
+ if (p.pos.exists && ! (skipZeroExtent && p. pos.isZeroExtent) && p.pos.contains(pos) ) {
79
84
// FIXME: We shouldn't be manually forcing trees here, we should replace
80
85
// our usage of `productIterator` by something in `Positioned` that takes
81
86
// care of low-level details like this for us.
0 commit comments