重新打开文件后,我的自定义 Eclipse 标记未显示

My custom Eclipse IMarkers are not being showed after I reopen the file

目前我有自己的自定义 IMarker:

<extension
    point="org.eclipse.core.resources.markers"
    id="com.test.package.custommarker"
    name="Custom Markers">
    <super type="org.eclipse.core.resources.problemmarker" />
    <persistent value="true" />
</extension>

并且 IMarkers 由以下代码创建:

IMarker marker = this.resource.createMarker("com.test.package.custommarker");
marker.setAttribute(IMarker.MESSAGE, description);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
marker.setAttribute(IMarker.LOCATION, "line: " + line + ", col: " + col);
marker.setAttribute(IMarker.LINE_NUMBER, line);     
marker.setAttribute(IMarker.CHAR_START, col);

在第一次执行时,编辑器打开并且 IMarkers 显示在编辑器和问题视图中,问题是如果我重新打开文件,IMarkers 仅显示在问题视图中而不显示在编辑器中。 当我说 IMarkers 显示在编辑器中时,我的意思是: Editor with error.

这是我重新打开文件时编辑器的样子: Editor after the reopen.

我的问题是,为什么会这样?

您需要同时设置CHAR_START和CHAR_END,或者LINE_NUMBER,为了创建相应的文本注释。此外,CHAR_START 和 CHAR_END 是文档相关的,而不是行相关的。如果您想了解其工作原理,请逐步完成 org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#createPositionFromMarker(IMarker)