Search in sources :

Example 11 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testRangeMarkersDoNotGetAddedOrRemovedWhenUserIsJustTypingInsideHighlightedRegionAndEspeciallyInsideInjectedFragmentsWhichAreColoredGreenAndUsersComplainEndlesslyThatEditorFlickersThere.

public void testRangeMarkersDoNotGetAddedOrRemovedWhenUserIsJustTypingInsideHighlightedRegionAndEspeciallyInsideInjectedFragmentsWhichAreColoredGreenAndUsersComplainEndlesslyThatEditorFlickersThere() throws Throwable {
    configureByText(JavaFileType.INSTANCE, "class S { int f() {\n" + "    return <caret>hashCode();\n" + "}}");
    Collection<HighlightInfo> infos = doHighlighting(HighlightInfoType.SYMBOL_TYPE_SEVERITY);
    assertEquals(3, infos.size());
    final int[] count = { 0 };
    MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
    modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {

        @Override
        public void afterAdded(@NotNull RangeHighlighterEx highlighter) {
            count[0]++;
        }

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            count[0]++;
        }
    });
    type(' ');
    highlightErrors();
    assertEquals(0, count[0]);
}
Also used : MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx)

Example 12 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testLineMarkersReuse.

public void testLineMarkersReuse() throws Throwable {
    configureByFile(BASE_PATH + "LineMarkerChange.java");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
    assertSize(5, lineMarkers);
    type('X');
    final Collection<String> changed = new ArrayList<>();
    MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
    modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener() {

        @Override
        public void afterAdded(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("after added")));
        }

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("before removed")));
        }

        @Override
        public void attributesChanged(@NotNull RangeHighlighterEx highlighter, boolean renderersChanged, boolean fontStyleChanged) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("changed")));
        }

        private void changed(@NotNull RangeHighlighterEx highlighter, String reason) {
            // not line marker
            if (highlighter.getTargetArea() != HighlighterTargetArea.LINES_IN_RANGE)
                return;
            List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
            // not line marker
            if (ContainerUtil.find(lineMarkers, lm -> lm.highlighter == highlighter) == null)
                return;
            changed.add(highlighter + ": \n" + reason);
        }
    });
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    List<HighlightInfo> infosAfter = CodeInsightTestFixtureImpl.instantiateAndRun(myFile, myEditor, new int[] {}, false);
    assertNotEmpty(filter(infosAfter, HighlightSeverity.ERROR));
    assertEmpty(changed);
    List<LineMarkerInfo> lineMarkersAfter = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
    assertEquals(lineMarkersAfter.size(), lineMarkers.size());
}
Also used : MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Example 13 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class UnifiedEditorRangeHighlighter method apply.

public void apply(@Nullable Project project, @NotNull Document document) {
    MarkupModel model = DocumentMarkupModel.forDocument(document, project, true);
    for (Element piece : myPieces) {
        RangeHighlighterEx delegate = piece.getDelegate();
        if (!delegate.isValid())
            continue;
        RangeHighlighter highlighter = model.addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea());
        highlighter.setEditorFilter(delegate.getEditorFilter());
        highlighter.setCustomRenderer(delegate.getCustomRenderer());
        highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor());
        highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip());
        highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer());
        highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer());
        highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor());
        highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark());
        highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement());
        highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer());
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 14 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class UpdateHighlightersUtil method createOrReuseHighlighterFor.

private static void createOrReuseHighlighterFor(@NotNull final HighlightInfo info, // if null global scheme will be used
@Nullable final EditorColorsScheme colorsScheme, @NotNull final Document document, final int group, @NotNull final PsiFile psiFile, @NotNull MarkupModelEx markup, @Nullable HighlightersRecycler infosToRemove, @NotNull final Map<TextRange, RangeMarker> ranges2markersCache, @NotNull SeverityRegistrar severityRegistrar) {
    int infoStartOffset = info.startOffset;
    int infoEndOffset = info.endOffset;
    final int docLength = document.getTextLength();
    if (infoEndOffset > docLength) {
        infoEndOffset = docLength;
        infoStartOffset = Math.min(infoStartOffset, infoEndOffset);
    }
    if (infoEndOffset == infoStartOffset && !info.isAfterEndOfLine()) {
        // empty highlighter beyond file boundaries
        if (infoEndOffset == docLength)
            return;
        //show something in case of empty highlightinfo
        infoEndOffset++;
    }
    info.setGroup(group);
    int layer = getLayer(info, severityRegistrar);
    RangeHighlighterEx highlighter = infosToRemove == null ? null : (RangeHighlighterEx) infosToRemove.pickupHighlighterFromGarbageBin(info.startOffset, info.endOffset, layer);
    final TextRange finalInfoRange = new TextRange(infoStartOffset, infoEndOffset);
    final TextAttributes infoAttributes = info.getTextAttributes(psiFile, colorsScheme);
    Consumer<RangeHighlighterEx> changeAttributes = finalHighlighter -> {
        if (infoAttributes != null) {
            finalHighlighter.setTextAttributes(infoAttributes);
        }
        info.setHighlighter(finalHighlighter);
        finalHighlighter.setAfterEndOfLine(info.isAfterEndOfLine());
        Color color = info.getErrorStripeMarkColor(psiFile, colorsScheme);
        finalHighlighter.setErrorStripeMarkColor(color);
        if (info != finalHighlighter.getErrorStripeTooltip()) {
            finalHighlighter.setErrorStripeTooltip(info);
        }
        GutterMark renderer = info.getGutterIconRenderer();
        finalHighlighter.setGutterIconRenderer((GutterIconRenderer) renderer);
        ranges2markersCache.put(finalInfoRange, info.getHighlighter());
        if (info.quickFixActionRanges != null) {
            List<Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker>> list = new ArrayList<>(info.quickFixActionRanges.size());
            for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
                TextRange textRange = pair.second;
                RangeMarker marker = getOrCreate(document, ranges2markersCache, textRange);
                list.add(Pair.create(pair.first, marker));
            }
            info.quickFixActionMarkers = ContainerUtil.createLockFreeCopyOnWriteList(list);
        }
        ProperTextRange fixRange = info.getFixTextRange();
        if (finalInfoRange.equals(fixRange)) {
            info.fixMarker = null;
        } else {
            info.fixMarker = getOrCreate(document, ranges2markersCache, fixRange);
        }
    };
    if (highlighter == null) {
        highlighter = markup.addRangeHighlighterAndChangeAttributes(infoStartOffset, infoEndOffset, layer, null, HighlighterTargetArea.EXACT_RANGE, false, changeAttributes);
    } else {
        markup.changeAttributesInBatch(highlighter, changeAttributes);
    }
    boolean attributesSet = Comparing.equal(infoAttributes, highlighter.getTextAttributes());
    assert attributesSet : "Info: " + infoAttributes + "; colorsScheme: " + (colorsScheme == null ? "[global]" : colorsScheme.getName()) + "; highlighter:" + highlighter.getTextAttributes();
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) GutterMark(com.intellij.codeInsight.daemon.GutterMark) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) RangeMarker(com.intellij.openapi.editor.RangeMarker) RedBlackTree(com.intellij.openapi.editor.impl.RedBlackTree) com.intellij.openapi.editor.markup(com.intellij.openapi.editor.markup) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) RangeMarkerTree(com.intellij.openapi.editor.impl.RangeMarkerTree) RangeMarker(com.intellij.openapi.editor.RangeMarker) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Example 15 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class DocumentMarkupModelTest method testPersistentHighlighterUpdateOnPartialDocumentUpdate.

public void testPersistentHighlighterUpdateOnPartialDocumentUpdate() {
    Document document = new DocumentImpl("line0\nline1\nline2");
    MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(document, getProject(), true);
    RangeHighlighterEx highlighter = model.addPersistentLineHighlighter(2, 0, null);
    new WriteCommandAction<Void>(getProject()) {

        @Override
        protected void run(@NotNull Result<Void> result) throws Throwable {
            document.deleteString(document.getLineStartOffset(1), document.getTextLength());
        }
    }.execute();
    assertTrue(highlighter.isValid());
    assertEquals(6, highlighter.getStartOffset());
}
Also used : MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) Document(com.intellij.openapi.editor.Document)

Aggregations

RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)23 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)13 Document (com.intellij.openapi.editor.Document)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Editor (com.intellij.openapi.editor.Editor)5 MarkupModelListener (com.intellij.openapi.editor.impl.event.MarkupModelListener)5 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)5 NotNull (org.jetbrains.annotations.NotNull)5 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)4 Project (com.intellij.openapi.project.Project)4 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)3 Pair (com.intellij.openapi.util.Pair)3 java.awt (java.awt)3 Nullable (org.jetbrains.annotations.Nullable)3 GutterMark (com.intellij.codeInsight.daemon.GutterMark)2 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2