From 9c4ae0b297be3f8b74b5249afe2cc7b5d40023fd Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 14 Feb 2017 13:00:29 +0100 Subject: [PATCH] run write action in refactorings under write action (IDEA-54664) --- .../refactoring/BaseRefactoringProcessor.java | 60 ++++++++++--------- .../util/resources/misc/registry.properties | 6 +- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java index 343051d96c9c..0e3b5264875f 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java @@ -23,6 +23,8 @@ import com.intellij.ide.DataManager; import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ex.ApplicationManagerEx; +import com.intellij.openapi.application.impl.ApplicationImpl; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.UndoConfirmationPolicy; import com.intellij.openapi.command.undo.BasicUndoableAction; @@ -40,6 +42,7 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.EmptyRunnable; import com.intellij.openapi.util.Factory; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.impl.status.StatusBarUtil; import com.intellij.psi.PsiDocumentManager; @@ -464,34 +467,38 @@ public abstract class BaseRefactoringProcessor implements Runnable { ProgressManager.getInstance().runProcessWithProgressSynchronously(prepareHelpersRunnable, "Prepare ...", false, myProject); - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - final String refactoringId = getRefactoringId(); + Runnable performRefactoringRunnable = () -> { + final String refactoringId = getRefactoringId(); + if (refactoringId != null) { + RefactoringEventData data = getBeforeData(); + if (data != null) { + data.addUsages(usageInfoSet); + } + myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, data); + } + + try { if (refactoringId != null) { - RefactoringEventData data = getBeforeData(); - if (data != null) { - data.addUsages(usageInfoSet); - } - myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, data); + UndoableAction action1 = new UndoRefactoringAction(myProject, refactoringId); + UndoManager.getInstance(myProject).undoableActionPerformed(action1); } - try { - if (refactoringId != null) { - UndoableAction action = new UndoRefactoringAction(myProject, refactoringId); - UndoManager.getInstance(myProject).undoableActionPerformed(action); - } - - performRefactoring(writableUsageInfos); - } - finally { - if (refactoringId != null) { - myProject.getMessageBus() - .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, getAfterData(writableUsageInfos)); - } + performRefactoring(writableUsageInfos); + } + finally { + if (refactoringId != null) { + myProject.getMessageBus() + .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, getAfterData(writableUsageInfos)); } } - }); + }; + ApplicationImpl app = (ApplicationImpl)ApplicationManagerEx.getApplicationEx(); + if (Registry.is("run.refactorings.under.progress")) { + app.runWriteActionWithProgressInDispatchThread(getCommandName(), myProject, null, null, indicator -> performRefactoringRunnable.run()); + } + else { + app.runWriteAction(performRefactoringRunnable); + } DumbService.getInstance(myProject).completeJustSubmittedTasks(); @@ -500,12 +507,7 @@ public abstract class BaseRefactoringProcessor implements Runnable { e.getKey().performOperation(myProject, e.getValue()); } myTransaction.commit(); - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - performPsiSpoilingRefactoring(); - } - }); + app.runWriteAction(() -> performPsiSpoilingRefactoring()); } finally { action.finish(); diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 28d2d6c0b748..932c07b512dc 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -466,6 +466,10 @@ core.pooled.threads=30 editor.dumb.mode.available=true editor.dumb.mode.available.description=Paint editor in buffer to avoid blinking during inplace refactorings + +run.refactorings.under.progress=true +run.refactorings.under.progress.description=Run refactorings write action under progress, not to freeze the UI during long operations + enable.animation.on.dialogs=false type.ahead.logging.enabled=false @@ -1002,7 +1006,7 @@ ide.new.editor.tabs.selection.description=New way to select an editor tab ide.new.editor.tabs.selection.color=439EB8 ide.new.editor.tabs.selection.color.description=Color to highlight selected editor tab javascript.unused.global.declarations.cached=false -javascript.unused.global.declarations.description=Allows caching of JavaScript unused property declarations; might contain threading issues, experimental +javascript.unused.global.declarations.cached.description=Allows caching of JavaScript unused property declarations; might contain threading issues, experimental php.register.class.references.in.strings=true php.register.class.references.in.strings.description=Enables extended class reference provider for php string literals.