diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/CodeFoldingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/CodeFoldingPass.java index 8c8fd2c87482..0d95d24bdb8e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/CodeFoldingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/CodeFoldingPass.java @@ -18,9 +18,9 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.codeHighlighting.EditorBoundHighlightingPass; import com.intellij.codeInsight.folding.CodeFoldingManager; +import com.intellij.codeInsight.folding.impl.FoldingUpdate; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.PossiblyDumbAware; @@ -73,6 +73,6 @@ class CodeFoldingPass extends EditorBoundHighlightingPass implements PossiblyDum */ @Override public boolean isDumbAware() { - return EditorUtil.supportsDumbModeFolding(myEditor); + return FoldingUpdate.supportsDumbModeFolding(myEditor); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java index f5c692f54632..9a5bd2cbbe6b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CodeFoldingManagerImpl.java @@ -29,9 +29,9 @@ import com.intellij.openapi.editor.event.EditorMouseMotionAdapter; import com.intellij.openapi.editor.ex.DocumentBulkUpdateListener; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.FoldingModelEx; -import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.fileEditor.impl.text.CodeFoldingState; import com.intellij.openapi.project.DumbAwareRunnable; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.*; @@ -55,7 +55,7 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec private final List myDocumentsWithFoldingInfo = new WeakList(); private final Key myFoldingInfoInDocumentKey = Key.create("FOLDING_INFO_IN_DOCUMENT_KEY"); - private static final Key FOLDING_STATE_INFO_IN_DOCUMENT_KEY = Key.create("FOLDING_STATE_IN_DOCUMENT"); + private static final Key FOLDING_STATE_KEY = Key.create("FOLDING_STATE_KEY"); CodeFoldingManagerImpl(Project project) { myProject = project; @@ -205,7 +205,7 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec final Project project = editor.getProject(); if (project == null || !project.equals(myProject) || editor.isDisposed()) return; if (!((FoldingModelEx)editor.getFoldingModel()).isFoldingEnabled()) return; - if (!EditorUtil.supportsDumbModeFolding(editor)) return; + if (!FoldingUpdate.supportsDumbModeFolding(editor)) return; Document document = editor.getDocument(); PsiDocumentManager.getInstance(myProject).commitDocument(document); @@ -244,6 +244,7 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec final FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel(); if (!foldingModel.isFoldingEnabled()) return; if (isFoldingsInitializedInEditor(editor)) return; + if (DumbService.isDumb(myProject) && !FoldingUpdate.supportsDumbModeFolding(editor)) return; foldingModel.runBatchFoldingOperationDoNotCollapseCaret(new UpdateFoldRegionsOperation(myProject, editor, file, foldingMap, true, false)); initFolding(editor); @@ -266,8 +267,8 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec documentFoldingInfo.setToEditor(editor); documentFoldingInfo.clear(); - document.putUserData(FOLDING_STATE_INFO_IN_DOCUMENT_KEY, Boolean.TRUE); - editor.putUserData(FOLDING_STATE_INFO_IN_DOCUMENT_KEY, Boolean.TRUE); + document.putUserData(FOLDING_STATE_KEY, Boolean.TRUE); + editor.putUserData(FOLDING_STATE_KEY, Boolean.TRUE); } }); } @@ -408,15 +409,15 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec for(Editor editor:editors) { EditorFoldingInfo.resetInfo(editor); } - document.putUserData(FOLDING_STATE_INFO_IN_DOCUMENT_KEY, null); + document.putUserData(FOLDING_STATE_KEY, null); } } static boolean isFoldingsInitializedInDocument(@NotNull Document document) { - return Boolean.TRUE.equals(document.getUserData(FOLDING_STATE_INFO_IN_DOCUMENT_KEY)); + return Boolean.TRUE.equals(document.getUserData(FOLDING_STATE_KEY)); } static boolean isFoldingsInitializedInEditor(@NotNull Editor editor) { - return Boolean.TRUE.equals(editor.getUserData(FOLDING_STATE_INFO_IN_DOCUMENT_KEY)); + return Boolean.TRUE.equals(editor.getUserData(FOLDING_STATE_KEY)); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java index 2075fff80351..5e14a9f39179 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/DocumentFoldingInfo.java @@ -27,7 +27,6 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.editor.RangeMarker; -import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.impl.text.CodeFoldingState; import com.intellij.openapi.project.DumbService; @@ -286,7 +285,7 @@ class DocumentFoldingInfo implements JDOMExternalizable, CodeFoldingState { if (psiFile == null || !psiFile.getViewProvider().isPhysical()) return; String date = null; - boolean canRestoreElement = !DumbService.getInstance(myProject).isDumb() || EditorUtil.supportsDumbModeFolding(psiFile); + boolean canRestoreElement = !DumbService.getInstance(myProject).isDumb() || FoldingUpdate.supportsDumbModeFolding(psiFile); for (final Object o : element.getChildren()) { Element e = (Element)o; Boolean expanded = Boolean.valueOf(e.getAttributeValue(EXPANDED_ATT)); @@ -350,6 +349,7 @@ class DocumentFoldingInfo implements JDOMExternalizable, CodeFoldingState { result = 31 * result + (myFile != null ? myFile.hashCode() : 0); result = 31 * result + myPsiElements.hashCode(); result = 31 * result + myRangeMarkers.hashCode(); + result = 31 * result + mySerializedElements.hashCode(); return result; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java index 66a598bbe14d..4f7f3322a05b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java @@ -30,6 +30,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.ContentBasedFileSubstitutor; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.Key; @@ -188,6 +189,40 @@ public class FoldingUpdate { }; } + /** + * Checks the ability to initialize folding in the Dumb Mode. Due to language injections it may depend on + * edited file and active injections (not yet implemented). + * + * @param editor the editor that holds file view + * @return true if folding initialization available in the Dumb Mode + */ + public static boolean supportsDumbModeFolding(@NotNull Editor editor) { + Project project = editor.getProject(); + if (project != null) { + PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); + if (file != null) { + return supportsDumbModeFolding(file); + } + } + return true; + } + + /** + * Checks the ability to initialize folding in the Dumb Mode for file. + * + * @param file the file to test + * @return true if folding initialization available in the Dumb Mode + */ + public static boolean supportsDumbModeFolding(@NotNull PsiFile file) { + final FileViewProvider viewProvider = file.getViewProvider(); + for (final Language language : viewProvider.getLanguages()) { + final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); + if(foldingBuilder != null && !DumbService.isDumbAware(foldingBuilder)) + return false; + } + return true; + } + static FoldingMap getFoldingsFor(@NotNull Project project, @NotNull PsiFile file, @NotNull Document document, boolean quick) { FoldingMap foldingMap = new FoldingMap(); if (!isContentSubstituted(file, project)) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java index f25430648a30..8809d3d3bc99 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java @@ -17,9 +17,6 @@ package com.intellij.openapi.editor.ex.util; import com.intellij.diagnostic.Dumpable; import com.intellij.diagnostic.LogMessageEx; -import com.intellij.lang.folding.FoldingBuilder; -import com.intellij.lang.folding.LanguageFolding; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; @@ -32,18 +29,11 @@ import com.intellij.openapi.editor.impl.FontInfo; import com.intellij.openapi.editor.impl.IterationState; import com.intellij.openapi.fileEditor.impl.text.TextEditorImpl; import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.fileTypes.LanguageFileType; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; import org.intellij.lang.annotations.JdkConstants; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -882,41 +872,6 @@ public final class EditorUtil { int line = document.getLineNumber(offset); return offset == document.getLineEndOffset(line); } - - /** - * Checks the ability to initialize folding in the Dumb Mode. Due to language injections it may depend on - * edited file and active injections (not yet implemented). - * - * @param editor the editor that holds file view - * @return true if folding initialization available in the Dumb Mode - */ - public static boolean supportsDumbModeFolding(@NotNull Editor editor) { - Project project = editor.getProject(); - if (project != null) { - PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); - if (file != null) { - return supportsDumbModeFolding(file); - } - } - return true; - } - - /** - * Checks the ability to initialize folding in the Dumb Mode for file. - * - * @param file the file to test - * @return true if folding initialization available in the Dumb Mode - */ - public static boolean supportsDumbModeFolding(@NotNull PsiFile file) { - if (file.getVirtualFile() != null) { - FileType ft = FileTypeManager.getInstance().getFileTypeByFile(file.getVirtualFile()); - if (ft instanceof LanguageFileType) { - final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(((LanguageFileType)ft).getLanguage()); - return DumbService.isDumbAware(foldingBuilder) || ApplicationManager.getApplication().isUnitTestMode(); - } - } - return true; - } }