@@ -94,17 +94,29 @@ object NavigateAST {
94
94
* When choosing better fit we compare spans. If candidate span has starting or ending point inside (exclusive)
95
95
* current best fit it is selected as new best fit. This means that same spans are failing the first predicate.
96
96
*
97
- * In case when spans start and end at same offsets we prefer non synthethic one.
97
+ * In case when spans start and end at same offsets we prefer non synthethic one,
98
+ * and then one with better point (see isBetterPoint below).
98
99
*/
99
100
def isBetterFit (currentBest : List [Positioned ], candidate : List [Positioned ]): Boolean =
100
101
if currentBest.isEmpty && candidate.nonEmpty then true
101
102
else if currentBest.nonEmpty && candidate.nonEmpty then
102
103
val bestSpan = currentBest.head.span
103
104
val candidateSpan = candidate.head.span
104
105
105
- bestSpan != candidateSpan &&
106
- envelops(bestSpan, candidateSpan) ||
107
- bestSpan.contains(candidateSpan) && bestSpan.isSynthetic && ! candidateSpan.isSynthetic
106
+ def isBetterPoint =
107
+ // Given two spans with same end points,
108
+ // we compare their points in relation to the point we are looking for (span.point)
109
+ // The candidate (candidateSpan.point) is better than what we have so far (bestSpan.point), when:
110
+ // 1) candidate is closer to target from the right
111
+ span.point <= candidateSpan.point && candidateSpan.point < bestSpan.point
112
+ // 2) candidate is closer to target from the left
113
+ || bestSpan.point < candidateSpan.point && candidateSpan.point <= span.point
114
+ // 3) candidate is to on the left side of target, and best so far is on the right
115
+ || candidateSpan.point <= span.point && span.point < bestSpan.point
116
+
117
+ bestSpan != candidateSpan && envelops(bestSpan, candidateSpan)
118
+ || bestSpan.contains(candidateSpan) && bestSpan.isSynthetic && ! candidateSpan.isSynthetic
119
+ || candidateSpan.start == bestSpan.start && candidateSpan.end == bestSpan.end && isBetterPoint
108
120
else false
109
121
110
122
def isRecoveryTree (sel : untpd.Select ): Boolean =
0 commit comments