run write action in refactorings under write action (IDEA-54664)

This commit is contained in:
Anna.Kozlova
2017-02-14 13:04:35 +01:00
parent a2c8592655
commit 9c4ae0b297
2 changed files with 36 additions and 30 deletions
@@ -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();
@@ -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.