Skip to content

Commit

Permalink
Restore quick assists after introduction of ScalaDocumentProvider
Browse files Browse the repository at this point in the history
It is no longer possible to retrieve compilation units from JDT classes,
we have to use the definitions in `IScalaPlugin` and `ScalaPlugin`.
  • Loading branch information
kiritsuku committed Oct 9, 2014
1 parent 92accec commit b0899a6
Showing 1 changed file with 13 additions and 14 deletions.
Expand Up @@ -3,15 +3,15 @@ package org.scalaide.core.internal.quickassist
import org.eclipse.core.commands.AbstractHandler
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation
import org.eclipse.jdt.ui.JavaUI
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.contentassist.ICompletionProposal
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext
import org.eclipse.jface.text.quickassist.IQuickAssistProcessor
import org.eclipse.jface.text.quickassist.QuickAssistAssistant
import org.eclipse.jface.text.source.Annotation
import org.eclipse.ui.IEditorInput
import org.scalaide.core.internal.jdt.model.ScalaSourceFile
import org.scalaide.core.IScalaPlugin
import org.scalaide.core.internal.ScalaPlugin
import org.scalaide.core.quickassist.AssistLocation
import org.scalaide.core.quickassist.BasicCompletionProposal
import org.scalaide.core.quickassist.InvocationContext
Expand Down Expand Up @@ -79,7 +79,7 @@ final class QuickAssistProcessor(input: IEditorInput, id: String) extends IQuick
override def computeQuickAssistProposals(ctx: IQuickAssistInvocationContext): Array[ICompletionProposal] = {
def problems = {
import collection.JavaConverters._
val model = JavaUI.getDocumentProvider.getAnnotationModel(input)
val model = ScalaPlugin().documentProvider.getAnnotationModel(input)
val iter = model.getAnnotationIterator.asScala

(iter foldLeft IndexedSeq[AssistLocation]()) {
Expand Down Expand Up @@ -107,25 +107,24 @@ final class QuickAssistProcessor(input: IEditorInput, id: String) extends IQuick
}
}

val ssf = IScalaPlugin().scalaCompilationUnit(input)
val assists =
if (id == DefaultId)
QuickAssists
else
QuickAssists.find(_.id == id).toSeq

JavaUI.getWorkingCopyManager.getWorkingCopy(input) match {
case ssf: ScalaSourceFile if assists.nonEmpty =>
val ictx = InvocationContext(ssf, ctx.getOffset, ctx.getLength, problems)
val proposals = assists flatMap (_ withInstance (_ compute ictx))
val sorted = proposals.flatten.sortBy(-_.getRelevance())
if (assists.isEmpty || ssf.isEmpty)
Array(NoProposals)
else {
val ictx = InvocationContext(ssf.get, ctx.getOffset, ctx.getLength, problems)
val proposals = assists flatMap (_ withInstance (_ compute ictx))
val sorted = proposals.flatten.sortBy(-_.getRelevance())

if (sorted.isEmpty)
Array(NoProposals)
else
sorted.toArray

case _ =>
if (sorted.isEmpty)
Array(NoProposals)
else
sorted.toArray
}
}

Expand Down

0 comments on commit b0899a6

Please sign in to comment.