Skip to content

Commit

Permalink
Fix possible race condition in AddMethodProposal
Browse files Browse the repository at this point in the history
Creating a refactoring needs to be done on the compiler thread.
  • Loading branch information
kiritsuku committed Oct 4, 2014
1 parent a39b058 commit 8049fa6
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import tools.nsc.interactive.Global
import scala.tools.refactoring.common.TextChange
import org.scalaide.core.quickassist.BasicCompletionProposal
import org.scalaide.ui.ScalaImages
import org.scalaide.core.compiler.IScalaPresentationCompiler.Implicits._

abstract class AddValOrDefProposal extends BasicCompletionProposal(
relevance = 90,
Expand All @@ -36,7 +37,10 @@ abstract class AddValOrDefProposal extends BasicCompletionProposal(
theDocument <- EditorUtils.findOrOpen(scalaSourceFile.workspaceFile)
} {
val scu = scalaSourceFile.getCompilationUnit.asInstanceOf[ScalaCompilationUnit]
val changes = scu.withSourceFile(addRefactoring) getOrElse Nil

val changes = scu.withSourceFile { (sf, compiler) =>
compiler.asyncExec(addRefactoring(sf, compiler)).getOrElse(Nil)()
} getOrElse Nil

for (change <- changes) {
val edit = new ReplaceEdit(change.from, change.to - change.from, change.text)
Expand Down

0 comments on commit 8049fa6

Please sign in to comment.