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]);
}
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());
}
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());
}
}
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();
}
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());
}
Aggregations