Skip to content

Commit

Permalink
Filter out duplicate positions
Browse files Browse the repository at this point in the history
In order to avoid that quick fix proposals are shown multiple times, we
can either filter out duplicate positions or filter out duplicate
proposal display strings. The former is not only faster to compute
(because no proposals need to be computed multiple times) it also
doesn't filter out different proposals that have the same display string
(for whatever reason that should happen in future).

Fixes #1002286
  • Loading branch information
kiritsuku committed Oct 6, 2014
1 parent 9abe591 commit ba42c39
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,22 @@ final class QuickAssistProcessor(input: IEditorInput, id: String) extends IQuick

(iter foldLeft IndexedSeq[AssistLocation]()) {
case (ps, a: Annotation) if a.isInstanceOf[ScalaEditorAnnotation] || a.isInstanceOf[IJavaAnnotation] =>
val pos = model.getPosition(a)
if (isInside(ctx.getOffset, pos.offset, pos.offset+pos.length))
ps :+ AssistLocation(pos.offset, pos.length, a)
val (start, end) = {
val p = model.getPosition(a)
(p.offset, p.offset+p.length)
}

def isOffsetInsidePos(offset: Int): Boolean =
offset == start || offset == end || (offset > start && offset < end)

def isPosInsideRange(rStart: Int, rEnd: Int): Boolean =
start >= rStart && end <= rEnd

def posNotYetFound =
ps.forall(a => !isPosInsideRange(a.offset, a.offset+a.length))

if (isOffsetInsidePos(ctx.getOffset) && posNotYetFound)
ps :+ AssistLocation(start, end-start, a)
else
ps
case (ps, _) =>
Expand Down Expand Up @@ -118,9 +131,5 @@ final class QuickAssistProcessor(input: IEditorInput, id: String) extends IQuick

override def canAssist(ctx: IQuickAssistInvocationContext): Boolean = true
override def canFix(a: Annotation): Boolean = true

override def getErrorMessage(): String = null

private def isInside(offset: Int, start: Int, end: Int): Boolean =
offset == start || offset == end || (offset > start && offset < end)
}

0 comments on commit ba42c39

Please sign in to comment.