Search in sources :

Example 1 with UpdateHighlightersUtil

use of com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil in project sonarlint-intellij by SonarSource.

the class SonarLintHighlighting method highlightFlowsWithHighlightersUtil.

/**
 * Create highlighting with {@link UpdateHighlightersUtil}. It will manage internally the {@link RangeHighlighter}, and get
 * it similarly to the way {@link com.intellij.codeHighlighting.Pass} do it.
 * Tooltip will be displayed on mouse hover by {@link com.intellij.codeInsight.daemon.impl.DaemonListeners}.
 * Creating the {@link HighlightInfo} with high severity will ensure that it will override most other highlighters.
 * The alternative would be to get and manage directly {@link RangeHighlighter} with a {@link MarkupModel} from the
 * document (or editors). This would allow to use a custom renderer, but we would have to manage tooltips by ourselves, separately.
 *
 * @see com.intellij.codeInsight.hint.HintManager
 * @see com.intellij.codeInsight.hint.ShowParameterInfoHandler
 * @see HintHint
 * @see CustomHighlighterRenderer
 * @see com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
 * @see com.intellij.codeInsight.highlighting.BraceHighlightingHandler
 */
public void highlightFlowsWithHighlightersUtil(RangeMarker rangeMarker, @Nullable String message, List<LiveIssue.Flow> flows) {
    stopBlinking();
    HighlightInfo primaryInfo = createHighlight(rangeMarker, message);
    List<HighlightInfo> infos = flows.stream().flatMap(f -> f.locations().stream().filter(Objects::nonNull).map(l -> createHighlight(l.location(), l.message()))).collect(Collectors.toList());
    infos.add(primaryInfo);
    UpdateHighlightersUtil.setHighlightersToEditor(project, rangeMarker.getDocument(), 0, rangeMarker.getDocument().getTextLength(), infos, null, HIGHLIGHT_GROUP_ID);
    currentHighlightedDoc = rangeMarker.getDocument();
    Editor[] editors = EditorFactory.getInstance().getEditors(rangeMarker.getDocument(), project);
    List<Segment> segments = Stream.concat(flows.stream().flatMap(f -> f.locations().stream().map(LiveIssue.IssueLocation::location)), Stream.of(rangeMarker)).collect(Collectors.toList());
    Arrays.stream(editors).forEach(editor -> {
        blinker = new RangeBlinker(editor, new TextAttributes(null, null, JBColor.YELLOW, EffectType.BOXED, Font.PLAIN), 3);
        blinker.resetMarkers(segments);
        blinker.startBlinking();
    });
}
Also used : Arrays(java.util.Arrays) SonarLintTextAttributes(org.sonarlint.intellij.config.SonarLintTextAttributes) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) UpdateHighlightersUtil(com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil) HintHint(com.intellij.ui.HintHint) EffectType(com.intellij.openapi.editor.markup.EffectType) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Project(com.intellij.openapi.project.Project) Segment(com.intellij.openapi.util.Segment) Nullable(javax.annotation.Nullable) RangeMarker(com.intellij.openapi.editor.RangeMarker) Font(java.awt.Font) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) Editor(com.intellij.openapi.editor.Editor) Collectors(java.util.stream.Collectors) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) CustomHighlighterRenderer(com.intellij.openapi.editor.markup.CustomHighlighterRenderer) Objects(java.util.Objects) List(java.util.List) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Stream(java.util.stream.Stream) EditorFactory(com.intellij.openapi.editor.EditorFactory) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Collections(java.util.Collections) JBColor(com.intellij.ui.JBColor) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) SonarLintTextAttributes(org.sonarlint.intellij.config.SonarLintTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) Segment(com.intellij.openapi.util.Segment)

Aggregations

HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)1 UpdateHighlightersUtil (com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil)1 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 CustomHighlighterRenderer (com.intellij.openapi.editor.markup.CustomHighlighterRenderer)1 EffectType (com.intellij.openapi.editor.markup.EffectType)1 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 Project (com.intellij.openapi.project.Project)1 Segment (com.intellij.openapi.util.Segment)1 HintHint (com.intellij.ui.HintHint)1 JBColor (com.intellij.ui.JBColor)1 Font (java.awt.Font)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1