use of com.intellij.openapi.editor.ex.MarkupModelEx 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.MarkupModelEx 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.MarkupModelEx in project intellij-community by JetBrains.
the class Bookmark method findMyHighlighter.
private RangeHighlighterEx findMyHighlighter() {
final Document document = getDocument();
if (document == null)
return null;
RangeHighlighterEx result = SoftReference.dereference(myHighlighterRef);
if (result != null) {
return result;
}
MarkupModelEx markup = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, true);
final Document markupDocument = markup.getDocument();
final int startOffset = 0;
final int endOffset = markupDocument.getTextLength();
final Ref<RangeHighlighterEx> found = new Ref<>();
markup.processRangeHighlightersOverlappingWith(startOffset, endOffset, highlighter -> {
GutterMark renderer = highlighter.getGutterIconRenderer();
if (renderer instanceof MyGutterIconRenderer && ((MyGutterIconRenderer) renderer).myBookmark == this) {
found.set(highlighter);
return false;
}
return true;
});
result = found.get();
myHighlighterRef = result == null ? null : new WeakReference<>(result);
return result;
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class Bookmark method release.
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;
RangeHighlighterEx highlighter = findMyHighlighter();
if (highlighter != null) {
myHighlighterRef = null;
highlighter.dispose();
}
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class DocumentMarkupModel method forDocument.
/**
* Returns the markup model for the specified project. A document can have multiple markup
* models for different projects if the file to which it corresponds belongs to multiple projects
* opened in different IDEA frames at the same time.
*
* @param document the document for which the markup model is requested.
* @param project the project for which the markup model is requested, or null if the default markup
* model is requested.
* @return the markup model instance.
* @see com.intellij.openapi.editor.Editor#getMarkupModel()
*/
public static MarkupModel forDocument(@NotNull Document document, @Nullable Project project, boolean create) {
if (document instanceof DocumentWindow) {
final Document delegate = ((DocumentWindow) document).getDelegate();
final MarkupModelEx baseMarkupModel = (MarkupModelEx) forDocument(delegate, project, true);
return new MarkupModelWindow(baseMarkupModel, (DocumentWindow) document);
}
if (project == null) {
MarkupModelEx markupModel = document.getUserData(MARKUP_MODEL_KEY);
if (create && markupModel == null) {
MarkupModelEx newModel = new MarkupModelImpl((DocumentEx) document);
if ((markupModel = ((UserDataHolderEx) document).putUserDataIfAbsent(MARKUP_MODEL_KEY, newModel)) != newModel) {
newModel.dispose();
}
}
return markupModel;
}
final DocumentMarkupModelManager documentMarkupModelManager = project.isDisposed() ? null : DocumentMarkupModelManager.getInstance(project);
if (documentMarkupModelManager == null || documentMarkupModelManager.isDisposed() || project.isDisposed()) {
return new EmptyMarkupModel(document);
}
ConcurrentMap<Project, MarkupModelImpl> markupModelMap = getMarkupModelMap(document);
MarkupModelImpl model = markupModelMap.get(project);
if (create && model == null) {
MarkupModelImpl newModel = new MarkupModelImpl((DocumentEx) document);
if ((model = ConcurrencyUtil.cacheOrGet(markupModelMap, project, newModel)) == newModel) {
documentMarkupModelManager.registerDocument(document);
} else {
newModel.dispose();
}
}
return model;
}
Aggregations