From fe2df3beb6a15614accaf183ea4c91edf2c8c42e Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 13 Feb 2012 17:29:19 +0400 Subject: [PATCH] IDEA-63712 --- .../daemon/impl/GeneralHighlightingPass.java | 5 ++++- .../daemon/impl/HighlightInfoType.java | 2 ++ .../daemon/impl/UpdateHighlightersUtil.java | 3 +++ .../analysis/HighlightingSettingsPerFile.java | 15 +++++++-------- .../injected/InjectedLanguageManagerImpl.java | 8 ++++++-- .../openapi/editor/impl/IterationState.java | 4 ++-- .../ExpectedHighlightingData.java | 19 ++++++++----------- 7 files changed, 32 insertions(+), 24 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index 4148e31ff6b6..43818a9ab534 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -345,7 +345,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP TextRange textRange = place.getRangeInsideHost().shiftRight(place.host.getTextRange().getStartOffset()); if (textRange.isEmpty()) continue; String desc = injectedPsi.getLanguage().getDisplayName() + ": " + injectedPsi.getText(); - HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT, textRange, null, desc, injectedAttributes); + HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_BACKGROUND, textRange, null, desc, injectedAttributes); info.fromInjection = true; outInfos.add(info); } @@ -521,6 +521,9 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP forcedAttributes = TextAttributes.ERASE_MARKER; } else { + HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT, annRange, null,null,TextAttributes.ERASE_MARKER); + holder.add(info); + Color back = attributes.getBackgroundColor() == null ? myGlobalScheme.getDefaultBackground() : attributes.getBackgroundColor(); Color fore = attributes.getForegroundColor() == null ? myGlobalScheme.getDefaultForeground() : attributes.getForegroundColor(); forcedAttributes = new TextAttributes(fore, back, attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java index 4130215eacd4..336eb99cc344 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java @@ -90,7 +90,9 @@ public interface HighlightInfoType { HighlightInfoType TODO = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, null); // t.o.d.o attributes depend on the t.o.d.o text HighlightInfoType UNHANDLED_EXCEPTION = new HighlightInfoTypeImpl(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES); + HighlightSeverity INJECTED_FRAGMENT_SEVERITY = new HighlightSeverity("INJECTED_FRAGMENT", SYMBOL_TYPE_SEVERITY.myVal - 1); HighlightInfoType INJECTED_LANGUAGE_FRAGMENT = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INFORMATION_ATTRIBUTES); + HighlightInfoType INJECTED_LANGUAGE_BACKGROUND = new HighlightInfoTypeImpl(INJECTED_FRAGMENT_SEVERITY, CodeInsightColors.INFORMATION_ATTRIBUTES); @NotNull HighlightSeverity getSeverity(@Nullable PsiElement psiElement); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java index 8f5a44c6962a..ac3faa058657 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java @@ -489,6 +489,9 @@ public class UpdateHighlightersUtil { else if (severityRegistrar.compare(severity, HighlightSeverity.ERROR) >= 0) { layer = HighlighterLayer.ERROR; } + else if (severity == HighlightInfoType.INJECTED_FRAGMENT_SEVERITY) { + layer = HighlighterLayer.CARET_ROW-1; + } else { layer = HighlighterLayer.ADDITIONAL_SYNTAX; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightingSettingsPerFile.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightingSettingsPerFile.java index 38d6f7eafca0..f31d8a7b96bc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightingSettingsPerFile.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightingSettingsPerFile.java @@ -30,6 +30,7 @@ import com.intellij.psi.util.PsiUtilBase; import com.intellij.util.containers.WeakHashMap; import org.jdom.Element; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashMap; @@ -42,15 +43,14 @@ public class HighlightingSettingsPerFile implements PersistentStateComponent myHighlightSettings = new HashMap(); - private final Map myProfileSettings = new WeakHashMap(); - public FileHighlighingSetting getHighlightingSettingForRoot(PsiElement root){ + public FileHighlighingSetting getHighlightingSettingForRoot(@NotNull PsiElement root){ final PsiFile containingFile = root.getContainingFile(); final VirtualFile virtualFile = containingFile.getVirtualFile(); FileHighlighingSetting[] fileHighlighingSettings = myHighlightSettings.get(virtualFile); @@ -62,7 +62,7 @@ public class HighlightingSettingsPerFile implements PersistentStateComponent commitProcessor = new Processor() { @Override public boolean process(DocumentWindow documentWindow) { - ProgressManager.checkCanceled(); - if (documentManager.isUncommited(hostDocument)) return false; // will be committed later + if (myProject.isDisposed()) return false; + ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); + if (indicator != null && indicator.isCanceled()) return false; + if (documentManager.isUncommited(hostDocument) || !hostPsiFile.isValid()) return false; // will be committed later RangeMarker rangeMarker = documentWindow.getHostRanges()[0]; PsiElement element = rangeMarker.isValid() ? hostPsiFile.findElementAt(rangeMarker.getStartOffset()) : null; @@ -173,6 +176,7 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme final Runnable commitInjectionsRunnable = new Runnable() { @Override public void run() { + if (myProgress.isCanceled()) return; JobUtil.invokeConcurrentlyUnderProgress(new ArrayList(injected), myProgress, !synchronously, commitProcessor); } }; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java index 0aa4b4666b5b..b7ce758466e9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java @@ -385,7 +385,7 @@ public final class IterationState { } TextAttributes textAttributes = highlighter.getTextAttributes(); - if (textAttributes != null) { + if (textAttributes != null && textAttributes != TextAttributes.ERASE_MARKER) { cachedAttributes.add(textAttributes); } } @@ -393,8 +393,8 @@ public final class IterationState { if (selection != null) cachedAttributes.add(selection); if (fold != null) cachedAttributes.add(fold); if (guard != null) cachedAttributes.add(guard); - if (syntax != null) cachedAttributes.add(syntax); if (caret != null) cachedAttributes.add(caret); + if (syntax != null) cachedAttributes.add(syntax); Color fore = null; Color back = isInGuardedBlock ? myReadOnlyColor : null; diff --git a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java index 74f003d21c59..d69dec3cefdc 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java +++ b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java @@ -120,12 +120,10 @@ public class ExpectedHighlightingData { boolean checkWeakWarnings = false; boolean checkInfos = false; - - highlightingTypes.put(ERROR_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, false, true)); highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, checkWarnings)); highlightingTypes.put(WEAK_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, checkWeakWarnings)); - //highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos)); + highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos)); highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, checkInfos)); highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, false)); for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) { @@ -162,8 +160,7 @@ public class ExpectedHighlightingData { } public void checkInfos() { highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, true)); - //highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true)); - + highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true)); } public void checkSymbolNames() { highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, true)); @@ -357,7 +354,7 @@ public class ExpectedHighlightingData { int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0); int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0); - if (failMessage.length() != 0) failMessage += '\n'; + if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Extra line marker highlighted " + "(" + (x1 + 1) + ", " + (y1 + 1) + ")" + "-" + "(" + (x2 + 1) + ", " + (y2 + 1) + ")" @@ -377,7 +374,7 @@ public class ExpectedHighlightingData { int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0); int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0); - if (failMessage.length() != 0) failMessage += '\n'; + if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Line marker was not highlighted " + "(" + (x1 + 1) + ", " + (y1 + 1) + ")" + "-" + "(" + (x2 + 1) + ", " + (y2 + 1) + ")" @@ -386,7 +383,7 @@ public class ExpectedHighlightingData { } } - if (failMessage.length() > 0) Assert.fail(failMessage); + if (!failMessage.isEmpty()) Assert.fail(failMessage); } private static boolean containsLineMarker(LineMarkerInfo info, Collection where) { @@ -427,7 +424,7 @@ public class ExpectedHighlightingData { int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0); int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0); - if (failMessage.length() != 0) failMessage += '\n'; + if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Extra text fragment highlighted " + "(" + (x1 + 1) + ", " + (y1 + 1) + ")" + "-" + "(" + (x2 + 1) + ", " + (y2 + 1) + ")" + @@ -453,7 +450,7 @@ public class ExpectedHighlightingData { int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0); int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0); - if (failMessage.length() != 0) failMessage += '\n'; + if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Text fragment was not highlighted " + "(" + (x1 + 1) + ", " + (y1 + 1) + ")" + "-" + "(" + (x2 + 1) + ", " + (y2 + 1) + ")" + @@ -464,7 +461,7 @@ public class ExpectedHighlightingData { } } - if (failMessage.length() > 0) { + if (!failMessage.isEmpty()) { compareTexts(infos, text, failMessage, filePath); } }