Revert "Don't perform 'sequential formatting' if dummy special text is inserted to the document"

This reverts commit b1bb2c24cac78f80f265cb4593227ff628f89b43.
Reason: choosing don't format sequentially for all actions over than 'format'
This commit is contained in:
Denis Zhdanov
2011-02-18 17:40:00 +03:00
parent 1b198a3333
commit 2366d5d403
4 changed files with 1 additions and 84 deletions
@@ -23,7 +23,6 @@ package com.intellij.codeInsight.template;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.SuggestedNameInfo;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl;
import com.intellij.psi.text.BlockSupport;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nullable;
@@ -55,7 +54,6 @@ package com.intellij.codeInsight.template;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
BlockSupport blockSupport = ServiceManager.getService(project, BlockSupport.class);
CodeStyleManagerImpl.setSequentialProcessingAllowed(false);
try{
blockSupport.reparseRange(fileCopy, offset, offset, "xxx");
}
@@ -216,20 +216,4 @@ public abstract class CodeStyleManager {
* the file is read-only).
*/
public abstract void reformatNewlyAddedElement(@NotNull final ASTNode block, @NotNull final ASTNode addedElement) throws IncorrectOperationException;
/**
* Formatting may be executed sequentially, i.e. the whole (re)formatting task is split into a number of smaller sub-tasks
* that are executed sequentially. That is done primarily for ability to show progress dialog during formatting (formatting
* is always performed from EDT, hence, the GUI freezes if we perform formatting as a single big iteration).
* <p/>
* However, there are situation when we don't want to use such an approach - for example, IntelliJ IDEA sometimes inserts dummy
* text into file in order to calculate formatting-specific data and removes it after that. We don't want to allow Swing events
* dispatching during that in order to not show that dummy text to the end-user.
* <p/>
* It's possible to configure that (implementation details are insignificant here) and current method serves as a read-only
* facade for obtaining information if 'sequential' processing is allowed at the moment.
*
* @return <code>true</code> if 'sequential' formatting is allowed now; <code>false</code> otherwise
*/
public abstract boolean isSequentialProcessingAllowed();
}
@@ -36,7 +36,6 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.formatter.DocumentBasedFormattingModel;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
@@ -189,9 +188,7 @@ public class CodeFormatterFacade {
project, mySettings, file.getFileType(), file);
FormatterEx formatter = FormatterEx.getInstanceEx();
if (CodeStyleManager.getInstance(project).isSequentialProcessingAllowed()) {
formatter.setProgressIndicator(new FormattingProgressIndicatorImpl(project, file, document));
}
formatter.setProgressIndicator(new FormattingProgressIndicatorImpl(project, file, document));
formatter.format(model, mySettings, mySettings.getIndentOptions(file.getFileType()), ranges);
for (FormatTextRanges.FormatTextRange range : textRanges) {
TextRange textRange = range.getTextRange();
@@ -48,20 +48,8 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.concurrent.TimeUnit;
public class CodeStyleManagerImpl extends CodeStyleManager {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl");
private static final ThreadLocal<ProcessingUnderProgressInfo> SEQUENTIAL_PROCESSING_ALLOWED
= new ThreadLocal<ProcessingUnderProgressInfo>()
{
@Override
protected ProcessingUnderProgressInfo initialValue() {
return new ProcessingUnderProgressInfo();
}
};
private final Project myProject;
@NonNls private static final String DUMMY_IDENTIFIER = "xxx";
@@ -490,7 +478,6 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
document.deleteString(start, end);
document.insertString(start, buffer);
setSequentialProcessingAllowed(false);
document.insertString(offset, DUMMY_IDENTIFIER);
return new TextRange(offset, offset + DUMMY_IDENTIFIER.length());
}
@@ -519,7 +506,6 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
ASTNode space1 = splitSpaceElement((TreeElement)element, offset - elementStart, charTable);
ASTNode marker = Factory.createSingleLeafElement(TokenType.NEW_LINE_INDENT, DUMMY_IDENTIFIER, charTable, file.getManager());
setSequentialProcessingAllowed(false);
parent.addChild(marker, space1.getTreeNext());
PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(marker);
return psiElement == null ? null : psiElement.getTextRange();
@@ -575,52 +561,4 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
private CodeStyleSettings getSettings() {
return CodeStyleSettingsManager.getSettings(myProject);
}
@Override
public boolean isSequentialProcessingAllowed() {
return SEQUENTIAL_PROCESSING_ALLOWED.get().isAllowed();
}
/**
* Allows to define if {@link #isSequentialProcessingAllowed() sequential processing} should be allowed.
* <p/>
* Current approach is not allow to stop sequential processing for more than predefine amount of time (couple of seconds).
* That means that call to this method with <code>'true'</code> argument is not mandatory for successful processing even
* if this method is called with <code>'false'</code> argument before.
*
* @param allowed flag that defines if {@link #isSequentialProcessingAllowed() sequential processing} should be allowed
*/
public static void setSequentialProcessingAllowed(boolean allowed) {
ProcessingUnderProgressInfo info = SEQUENTIAL_PROCESSING_ALLOWED.get();
if (allowed) {
info.decrement();
}
else {
info.increment();
}
}
private static class ProcessingUnderProgressInfo {
private static final long DURATION_TIME = TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS);
private int myCount;
private long myEndTime;
public void increment() {
myCount++;
myEndTime = System.currentTimeMillis() + DURATION_TIME;
}
public void decrement() {
if (myCount <= 0) {
return;
}
myCount--;
}
public boolean isAllowed() {
return myCount <= 0 || System.currentTimeMillis() >= myEndTime;
}
}
}