public UnifiedEditorRangeHighlighter(@Nullable Project project, @NotNull Document document) { ApplicationManager.getApplication().assertReadAccessAllowed(); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, false); if (model == null) return; model.processRangeHighlightersOverlappingWith(0, document.getTextLength(), new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx marker) { int newStart = marker.getStartOffset(); int newEnd = marker.getEndOffset(); myPieces.add(new Element(marker, newStart, newEnd)); return true; } }); }
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()); } }
public static void setHighlightersToEditor(@NotNull Project project, @NotNull Document document, int startOffset, int endOffset, @NotNull Collection<HighlightInfo> highlights, @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used int group) { TextRange range = new TextRange(startOffset, endOffset); ApplicationManager.getApplication().assertIsDispatchThread(); PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); final DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project); codeAnalyzer.cleanFileLevelHighlights(project, group, psiFile); MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true); assertMarkupConsistent(markup, project); setHighlightersInRange(project, document, range, colorsScheme, new ArrayList<HighlightInfo>(highlights), (MarkupModelEx)markup, group); }
public static boolean processHighlights(@NotNull Document document, @NotNull Project project, @Nullable("null means all") final HighlightSeverity minSeverity, final int startOffset, final int endOffset, @NotNull final Processor<HighlightInfo> processor) { LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed()); final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); return model.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(@NotNull RangeHighlighterEx marker) { Object tt = marker.getErrorStripeTooltip(); if (!(tt instanceof HighlightInfo)) return true; HighlightInfo info = (HighlightInfo)tt; return minSeverity != null && severityRegistrar.compare(info.getSeverity(), minSeverity) < 0 || info.highlighter == null || processor.process(info); } }); }
static boolean processHighlightsOverlappingOutside(@NotNull Document document, @NotNull Project project, @Nullable("null means all") final HighlightSeverity minSeverity, final int startOffset, final int endOffset, @NotNull final Processor<HighlightInfo> processor) { LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed()); final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); return model.processRangeHighlightersOutside(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(@NotNull RangeHighlighterEx marker) { Object tt = marker.getErrorStripeTooltip(); if (!(tt instanceof HighlightInfo)) return true; HighlightInfo info = (HighlightInfo)tt; return minSeverity != null && severityRegistrar.compare(info.getSeverity(), minSeverity) < 0 || info.highlighter == null || processor.process(info); } }); }
@Override @NotNull public List<GutterMark> findAllGutters() { final Project project = getProject(); final SortedMap<Integer, List<GutterMark>> result = new TreeMap<Integer, List<GutterMark>>(); List<HighlightInfo> infos = doHighlighting(); for (HighlightInfo info : infos) { addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset, result); } RangeHighlighter[] highlighters = DocumentMarkupModel.forDocument(myEditor.getDocument(), project, true).getAllHighlighters(); for (final RangeHighlighter highlighter : highlighters) { if (!highlighter.isValid()) continue; addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset(), result); } return ContainerUtil.concat(result.values()); }
public static void clearHighlightingAndLineMarkers(final Editor editor, @NotNull Project project) { final MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), project, true); for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) { Object tooltip = highlighter.getErrorStripeTooltip(); if (!(tooltip instanceof HighlightInfo)) { continue; } if (((HighlightInfo)tooltip).type == TYPE) { highlighter.dispose(); } } clearLineMarkers(editor); }
@Override public void doApplyInformationToEditor() { removeHighlighters(); if (myDocument == null) { return; } final MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true); final String text = myDocument.getText(); if (text != null) { int ind = -1; while ((ind = text.indexOf(CARET, ind + 1)) >= 0) { final RangeHighlighter highlighter = model.addRangeHighlighter(ind, ind + CARET.length(), HighlighterLayer.ADDITIONAL_SYNTAX, CARET_ATTRIBUTES, HighlighterTargetArea.EXACT_RANGE); highlighter.setGutterIconRenderer(ICON_RENDERER); highlighter.putUserData(KEY, VALUE); } } }
@Nullable protected static RangeHighlighter createHighlighter(@NotNull Project project, @NotNull Document document, int lineIndex) { if (lineIndex < 0 || lineIndex >= document.getLineCount()) { return null; } EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); RangeHighlighter highlighter = ((MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true)) .addPersistentLineHighlighter(lineIndex, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes); if (!highlighter.isValid()) { return null; } highlighter.putUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY, Boolean.TRUE); highlighter.setErrorStripeTooltip(DebuggerBundle.message("breakpoint.tooltip.text", lineIndex + 1)); return highlighter; }
@Override @NotNull public Collection<GutterMark> findAllGutters(final String filePath) { final Project project = getProject(); final SortedMap<Integer, List<GutterMark>> result = new TreeMap<Integer, List<GutterMark>>(); configureByFilesInner(filePath); List<HighlightInfo> infos = doHighlighting(); for (HighlightInfo info : infos) { addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset, result); } RangeHighlighter[] highlighters = DocumentMarkupModel.forDocument(myEditor.getDocument(), project, true).getAllHighlighters(); for (final RangeHighlighter highlighter : highlighters) { if (!highlighter.isValid()) continue; addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset(), result); } return ContainerUtil.concat(result.values()); }
public void updateUI() { if (myDisposed) return; if (ApplicationManager.getApplication().isUnitTestMode()) return; Document document = getDocument(); if (document == null) return; EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); removeHighlighter(); MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, getProject(), true); RangeHighlighter highlighter = markupModel.addPersistentLineHighlighter(getLine(), DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes); if (highlighter != null) { updateIcon(); highlighter.setGutterIconRenderer(createGutterIconRenderer()); highlighter.putUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY, Boolean.TRUE); } myHighlighter = highlighter; }
public static boolean processHighlights(@NotNull Document document, @NotNull Project project, @Nullable("null means all") final HighlightSeverity minSeverity, final int startOffset, final int endOffset, @NotNull final Processor<HighlightInfo> processor) { LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed()); final SeverityRegistrar severityRegistrar = SeverityUtil.getSeverityRegistrar(project); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); return model.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(@NotNull RangeHighlighterEx marker) { Object tt = marker.getErrorStripeTooltip(); if (!(tt instanceof HighlightInfo)) return true; HighlightInfo info = (HighlightInfo)tt; return minSeverity != null && severityRegistrar.compare(info.getSeverity(), minSeverity) < 0 || info.highlighter == null || processor.process(info); } }); }
static boolean processHighlightsOverlappingOutside(@NotNull Document document, @NotNull Project project, @Nullable("null means all") final HighlightSeverity minSeverity, final int startOffset, final int endOffset, @NotNull final Processor<HighlightInfo> processor) { LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed()); final SeverityRegistrar severityRegistrar = SeverityUtil.getSeverityRegistrar(project); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); return model.processRangeHighlightersOutside(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(@NotNull RangeHighlighterEx marker) { Object tt = marker.getErrorStripeTooltip(); if (!(tt instanceof HighlightInfo)) return true; HighlightInfo info = (HighlightInfo)tt; return minSeverity != null && severityRegistrar.compare(info.getSeverity(), minSeverity) < 0 || info.highlighter == null || processor.process(info); } }); }
public static void setHighlightersToEditor(@NotNull Project project, @NotNull Document document, int startOffset, int endOffset, @NotNull Collection<HighlightInfo> highlights, @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used int group) { TextRange range = new TextRange(startOffset, endOffset); ApplicationManager.getApplication().assertIsDispatchThread(); PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); cleanFileLevelHighlights(project, group, psiFile); MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true); assertMarkupConsistent(markup, project); setHighlightersInRange(project, document, range, colorsScheme, new ArrayList<HighlightInfo>(highlights), (MarkupModelEx)markup, group); }
@Override public void doApplyInformationToEditor() { removeHighlighters(); final MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true); final String text = myDocument.getText(); if (text != null) { int ind = -1; while ((ind = text.indexOf(CARET, ind + 1)) >= 0) { final RangeHighlighter highlighter = model.addRangeHighlighter(ind, ind + CARET.length(), HighlighterLayer.ADDITIONAL_SYNTAX, CARET_ATTRIBUTES, HighlighterTargetArea.EXACT_RANGE); highlighter.setGutterIconRenderer(ICON_RENDERER); highlighter.putUserData(KEY, VALUE); } } }
public UnifiedEditorRangeHighlighter(@Nullable Project project, @Nonnull Document document) { ApplicationManager.getApplication().assertReadAccessAllowed(); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, false); if (model == null) return; model.processRangeHighlightersOverlappingWith(0, document.getTextLength(), new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx marker) { int newStart = marker.getStartOffset(); int newEnd = marker.getEndOffset(); myPieces.add(new Element(marker, newStart, newEnd)); return true; } }); }
public void apply(@Nullable Project project, @Nonnull 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()); } }
@Override @Nonnull public Collection<GutterMark> findAllGutters(final String filePath) { final Project project = getProject(); final SortedMap<Integer, List<GutterMark>> result = new TreeMap<Integer, List<GutterMark>>(); configureByFilesInner(filePath); List<HighlightInfo> infos = doHighlighting(); for (HighlightInfo info : infos) { addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset, result); } RangeHighlighter[] highlighters = DocumentMarkupModel.forDocument(myEditor.getDocument(), project, true).getAllHighlighters(); for (final RangeHighlighter highlighter : highlighters) { if (!highlighter.isValid()) continue; addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset(), result); } return ContainerUtil.concat(result.values()); }
public static void setHighlightersToEditor(@Nonnull Project project, @Nonnull Document document, int startOffset, int endOffset, @Nonnull Collection<HighlightInfo> highlights, @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used int group) { TextRange range = new TextRange(startOffset, endOffset); ApplicationManager.getApplication().assertIsDispatchThread(); PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); final DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project); codeAnalyzer.cleanFileLevelHighlights(project, group, psiFile); MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true); assertMarkupConsistent(markup, project); setHighlightersInRange(project, document, range, colorsScheme, new ArrayList<>(highlights), (MarkupModelEx)markup, group); }
public static boolean processHighlights(@Nonnull Document document, @Nonnull Project project, @Nullable final HighlightSeverity minSeverity, final int startOffset, final int endOffset, @Nonnull final Processor<HighlightInfo> processor) { LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed()); final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); return model.processRangeHighlightersOverlappingWith(startOffset, endOffset, marker -> { Object tt = marker.getErrorStripeTooltip(); if (!(tt instanceof HighlightInfo)) return true; HighlightInfo info = (HighlightInfo)tt; return minSeverity != null && severityRegistrar.compare(info.getSeverity(), minSeverity) < 0 || info.highlighter == null || processor.process(info); }); }
static boolean processHighlightsOverlappingOutside(@Nonnull Document document, @Nonnull Project project, @Nullable final HighlightSeverity minSeverity, final int startOffset, final int endOffset, @Nonnull final Processor<HighlightInfo> processor) { LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed()); final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); return model.processRangeHighlightersOutside(startOffset, endOffset, marker -> { Object tt = marker.getErrorStripeTooltip(); if (!(tt instanceof HighlightInfo)) return true; HighlightInfo info = (HighlightInfo)tt; return minSeverity != null && severityRegistrar.compare(info.getSeverity(), minSeverity) < 0 || info.highlighter == null || processor.process(info); }); }
/** * Patches attributes to be visible under debugger active line */ @SuppressWarnings("UseJBColor") public static TextAttributes patchAttributesColor(TextAttributes attributes, @Nonnull TextRange range, @Nonnull Editor editor) { if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null) return attributes; MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); if (model != null) { if (!((MarkupModelEx)model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), highlighter -> { if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { TextAttributes textAttributes = highlighter.getTextAttributes(); if (textAttributes != null) { Color color = textAttributes.getBackgroundColor(); return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128); } } return true; })) { TextAttributes clone = attributes.clone(); clone.setForegroundColor(Color.orange); clone.setEffectColor(Color.orange); return clone; } } return attributes; }
static void addLineMarkerToEditorIncrementally(@Nonnull Project project, @Nonnull Document document, @Nonnull LineMarkerInfo marker) { ApplicationManager.getApplication().assertIsDispatchThread(); MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); LineMarkerInfo[] markerInTheWay = {null}; boolean allIsClear = markupModel.processRangeHighlightersOverlappingWith(marker.startOffset, marker.endOffset, highlighter -> (markerInTheWay[0] = getLineMarkerInfo(highlighter)) == null); if (allIsClear) { createOrReuseLineMarker(marker, markupModel, null); } if (LOG.isDebugEnabled()) { LOG.debug("LineMarkersUtil.addLineMarkerToEditorIncrementally: "+marker+" "+(allIsClear ? "created" : " (was not added because "+markerInTheWay[0] +" was in the way)")); } }
public static void clearHighlightingAndLineMarkers(final Editor editor, @NotNull Project project) { final MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), project, true); for(RangeHighlighter highlighter : markupModel.getAllHighlighters()) { Object tooltip = highlighter.getErrorStripeTooltip(); if(!(tooltip instanceof HighlightInfo)) { continue; } if(((HighlightInfo) tooltip).type == TYPE) { highlighter.dispose(); } } clearLineMarkers(editor); }
public UnifiedEditorRangeHighlighter(@Nullable Project project, @NotNull Document document1, @NotNull Document document2, @NotNull List<HighlightRange> ranges) { ApplicationManager.getApplication().assertReadAccessAllowed(); MarkupModelEx model1 = (MarkupModelEx)DocumentMarkupModel.forDocument(document1, project, false); MarkupModelEx model2 = (MarkupModelEx)DocumentMarkupModel.forDocument(document2, project, false); init(model1, model2, ranges); }
static void addHighlighterToEditorIncrementally(@NotNull Project project, @NotNull Document document, @NotNull PsiFile file, int startOffset, int endOffset, @NotNull final HighlightInfo info, @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used final int group, @NotNull Map<TextRange, RangeMarker> ranges2markersCache) { ApplicationManager.getApplication().assertIsDispatchThread(); if (isFileLevelOrGutterAnnotation(info)) return; if (info.getStartOffset() < startOffset || info.getEndOffset() > endOffset) return; MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true); final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project); final boolean myInfoIsError = isSevere(info, severityRegistrar); Processor<HighlightInfo> otherHighlightInTheWayProcessor = new Processor<HighlightInfo>() { @Override public boolean process(HighlightInfo oldInfo) { if (!myInfoIsError && isCovered(info, severityRegistrar, oldInfo)) { return false; } return oldInfo.getGroup() != group || !oldInfo.equalsByActualOffset(info); } }; boolean allIsClear = DaemonCodeAnalyzerEx.processHighlights(document, project, null, info.getActualStartOffset(), info.getActualEndOffset(), otherHighlightInTheWayProcessor); if (allIsClear) { createOrReuseHighlighterFor(info, colorsScheme, document, group, file, (MarkupModelEx)markup, null, ranges2markersCache, severityRegistrar); clearWhiteSpaceOptimizationFlag(document); assertMarkupConsistent(markup, project); } }
private void addHighlighter() { adjustCounter(myEditor, 1); int line = mySourcePosition.getLine(); Document document = myEditor.getDocument(); if (line < 0 || line >= document.getLineCount()) return; //if (myNotTopFrame) { // myEditor.getSelectionModel().setSelection(document.getLineStartOffset(line), document.getLineEndOffset(line) + document.getLineSeparatorLength(line)); // return; //} if (myRangeHighlighter != null) return; EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes attributes = myNotTopFrame ? scheme.getAttributes(DebuggerColors.NOT_TOP_FRAME_ATTRIBUTES) : scheme.getAttributes(DebuggerColors.EXECUTIONPOINT_ATTRIBUTES); MarkupModel markupModel = DocumentMarkupModel.forDocument(document, myProject, true); if (mySourcePosition instanceof HighlighterProvider) { TextRange range = ((HighlighterProvider)mySourcePosition).getHighlightRange(); if (range != null) { TextRange lineRange = DocumentUtil.getLineTextRange(document, line); range = range.intersection(lineRange); if (range != null && !range.isEmpty() && !range.equals(lineRange)) { myRangeHighlighter = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes, HighlighterTargetArea.EXACT_RANGE); } } } if (myRangeHighlighter == null) { myRangeHighlighter = markupModel.addLineHighlighter(line, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes); } myRangeHighlighter.putUserData(EXECUTION_POINT_HIGHLIGHTER_KEY, true); myRangeHighlighter.setGutterIconRenderer(myGutterIconRenderer); }
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes); if (state.equals(panel.getEditorState())) { return; } panel.navigateInPreviewEditor(state); TextAttributes softerAttributes = attributes.clone(); Color backgroundColor = softerAttributes.getBackgroundColor(); if (backgroundColor != null) { softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor)); } final Editor editor = panel.getEditor(); if (editor != null) { final MarkupModel editorModel = editor.getMarkupModel(); final MarkupModel documentModel = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) { if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) { final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line; if (line1 != line) { editorModel.addLineHighlighter(line1, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes); } } } } }
/** * Patches attributes to be visible under debugger active line */ @SuppressWarnings("UseJBColor") public static TextAttributes patchAttributesColor(TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) { MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); if (model != null) { if (!((MarkupModelEx)model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx highlighter) { if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { TextAttributes textAttributes = highlighter.getTextAttributes(); if (textAttributes != null) { Color color = textAttributes.getBackgroundColor(); return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128); } } return true; } })) { TextAttributes clone = attributes.clone(); clone.setForegroundColor(Color.orange); clone.setEffectColor(Color.orange); return clone; } } return attributes; }
public static void clearMyHighlights(Document document, Project project) { MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true); for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) { Object tooltip = highlighter.getErrorStripeTooltip(); if (!(tooltip instanceof HighlightInfo)) { continue; } HighlightInfo info = (HighlightInfo)tooltip; if (info.type == HighlightInfoType.ELEMENT_UNDER_CARET_READ || info.type == HighlightInfoType.ELEMENT_UNDER_CARET_WRITE) { highlighter.dispose(); } } }
@Override public void highlightsInsideVisiblePartAreProduced(@NotNull final HighlightingSession session, @NotNull final List<HighlightInfo> infos, @NotNull TextRange priorityRange, @NotNull TextRange restrictRange, final int groupId) { final PsiFile psiFile = session.getPsiFile(); final Project project = psiFile.getProject(); final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); if (document == null) return; final long modificationStamp = document.getModificationStamp(); final TextRange priorityIntersection = priorityRange.intersection(restrictRange); final Editor editor = session.getEditor(); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (project.isDisposed() || modificationStamp != document.getModificationStamp()) return; if (priorityIntersection != null) { MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true); EditorColorsScheme scheme = session.getColorsScheme(); UpdateHighlightersUtil.setHighlightersInRange(project, document, priorityIntersection, scheme, infos, (MarkupModelEx)markupModel, groupId); } if (editor != null && !editor.isDisposed()) { // usability: show auto import popup as soon as possible new ShowAutoImportPass(project, psiFile, editor).applyInformationToEditor(); DaemonListeners.repaintErrorStripeRenderer(editor, project); } } }); }
public void release() { int line = getLine(); if (line < 0) { return; } final Document document = getDocument(); if (document == null) return; MarkupModelEx markup = (MarkupModelEx)DocumentMarkupModel.forDocument(document, myProject, true); final Document markupDocument = markup.getDocument(); if (markupDocument.getLineCount() <= line) return; final int startOffset = markupDocument.getLineStartOffset(line); final int endOffset = markupDocument.getLineEndOffset(line); final Ref<RangeHighlighterEx> found = new Ref<RangeHighlighterEx>(); markup.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() { @Override public boolean process(RangeHighlighterEx highlighter) { GutterMark renderer = highlighter.getGutterIconRenderer(); if (renderer instanceof MyGutterIconRenderer && ((MyGutterIconRenderer)renderer).myBookmark == Bookmark.this) { found.set(highlighter); return false; } return true; } }); if (!found.isNull()) found.get().dispose(); }
private void removeHighlighters() { if (myDocument == null) { return; } final MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true); for (RangeHighlighter highlighter : model.getAllHighlighters()) { if (highlighter.getUserData(KEY) == VALUE) { highlighter.dispose(); } } }
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes); if (state.equals(panel.getEditorState())) { return; } panel.navigateInPreviewEditor(state); TextAttributes softerAttributes = attributes.clone(); Color backgroundColor = softerAttributes.getBackgroundColor(); if (backgroundColor != null) { softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor)); } final Editor editor = panel.getEditor(); final MarkupModel editorModel = editor.getMarkupModel(); final MarkupModel documentModel = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) { if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) { final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line; if (line1 != line) { editorModel.addLineHighlighter(line1, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes); } } } }
@SuppressWarnings({"AutoBoxing"}) private RangeHighlighter createHighlighter(final Range range) { LOG.assertTrue(!myReleased, "Already released"); int first = range.getOffset1() >= myDocument.getLineCount() ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getOffset1()); int second = range.getOffset2() >= myDocument.getLineCount() ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getOffset2()); final RangeHighlighter highlighter = DocumentMarkupModel.forDocument(myDocument, myProject, true) .addRangeHighlighter(first, second, HighlighterLayer.FIRST - 1, null, HighlighterTargetArea.LINES_IN_RANGE); final TextAttributes attr = LineStatusTrackerDrawing.getAttributesFor(range); highlighter.setErrorStripeMarkColor(attr.getErrorStripeColor()); highlighter.setThinErrorStripeMark(true); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); highlighter.setLineMarkerRenderer(LineStatusTrackerDrawing.createRenderer(range, this)); highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter()); final int line1 = myDocument.getLineNumber(first); final int line2 = myDocument.getLineNumber(second); final String tooltip; if (line1 == line2) { tooltip = VcsBundle.message("tooltip.text.line.changed", line1); } else { tooltip = VcsBundle.message("tooltip.text.lines.changed", line1, line2); } highlighter.setErrorStripeTooltip(tooltip); return highlighter; }
public static void clearMyHighlights(Document document, Project project) { MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true); for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) { Object tooltip = highlighter.getErrorStripeTooltip(); if (!(tooltip instanceof HighlightInfo)) { continue; } HighlightInfo info = (HighlightInfo)tooltip; if (info.type == ourReadHighlightInfoType || info.type == ourWriteHighlightInfoType) { highlighter.dispose(); } } }
public GeneralHighlightingPass(@NotNull Project project, @NotNull PsiFile file, @NotNull Document document, int startOffset, int endOffset, boolean updateAll, @NotNull ProperTextRange priorityRange, @Nullable Editor editor) { super(project, document, PRESENTABLE_NAME, file, true); myStartOffset = startOffset; myEndOffset = endOffset; myUpdateAll = updateAll; myPriorityRange = priorityRange; myEditor = editor; LOG.assertTrue(file.isValid()); setId(Pass.UPDATE_ALL); myHasErrorElement = !isWholeFileHighlighting() && Boolean.TRUE.equals(myFile.getUserData(HAS_ERROR_ELEMENT)); FileStatusMap fileStatusMap = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject)).getFileStatusMap(); myErrorFound = !isWholeFileHighlighting() && fileStatusMap.wasErrorFound(myDocument); myApplyCommand = new Runnable() { @Override public void run() { ProperTextRange range = new ProperTextRange(myStartOffset, myEndOffset); MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true); UpdateHighlightersUtil.cleanFileLevelHighlights(myProject, Pass.UPDATE_ALL,myFile); final EditorColorsScheme colorsScheme = getColorsScheme(); UpdateHighlightersUtil.setHighlightersInRange(myProject, myDocument, range, colorsScheme, myHighlights, (MarkupModelEx)model, Pass.UPDATE_ALL); } }; // initial guess to show correct progress in the traffic light icon setProgressLimit(document.getTextLength()/2); // approx number of PSI elements = file length/2 myGlobalScheme = EditorColorsManager.getInstance().getGlobalScheme(); }
static void addHighlighterToEditorIncrementally(@NotNull Project project, @NotNull Document document, @NotNull PsiFile file, int startOffset, int endOffset, @NotNull final HighlightInfo info, @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used final int group, @NotNull Map<TextRange, RangeMarker> ranges2markersCache) { ApplicationManager.getApplication().assertIsDispatchThread(); if (info.isFileLevelAnnotation() || info.getGutterIconRenderer() != null) return; if (info.getStartOffset() < startOffset || info.getEndOffset() > endOffset) return; MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true); final SeverityRegistrar severityRegistrar = SeverityUtil.getSeverityRegistrar(project); final boolean myInfoIsError = isSevere(info, severityRegistrar); Processor<HighlightInfo> otherHighlightInTheWayProcessor = new Processor<HighlightInfo>() { @Override public boolean process(HighlightInfo oldInfo) { if (!myInfoIsError && isCovered(info, severityRegistrar, oldInfo)) { return false; } return oldInfo.getGroup() != group || !oldInfo.equalsByActualOffset(info); } }; boolean allIsClear = DaemonCodeAnalyzerImpl.processHighlights(document, project, null, info.getActualStartOffset(), info.getActualEndOffset(), otherHighlightInTheWayProcessor); if (!allIsClear) { return; } createOrReuseHighlighterFor(info, colorsScheme, document, group, file, (MarkupModelEx)markup, null, ranges2markersCache, severityRegistrar); clearWhiteSpaceOptimizationFlag(document); assertMarkupConsistent(markup, project); }
protected void addTextToHistory(@Nullable String text, @Nullable TextAttributes attributes) { if (text == null || text.length() == 0) return; Document history = myHistoryViewer.getDocument(); MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true); int offset = history.getTextLength(); appendToHistoryDocument(history, text); if (attributes == null) return; markupModel.addRangeHighlighter(offset, offset + text.length(), HighlighterLayer.SYNTAX, attributes, HighlighterTargetArea.EXACT_RANGE); }