Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Textmarker overwrites style information in the Editor
Textmarker overwrites style information in the Editor [message #1763813] Sat, 20 May 2017 11:17
tly . is currently offline tly .Friend
Messages: 8
Registered: August 2014
Junior Member
Im trying to create a lightweight C++ Editor with the help of libclang.

I use a new problemmarker type to mark the compiler warnings and errors given by clang and the token ranges to do syntax coloring.

https://i.gyazo.com/8b0538c7cf7a75f269d3719e5b01296c.png

As you can see in the picture above, the squiggly lines of the error markers overwrite the syntax coloring. Is there a PresentationReconciler that takes into account that some marked lines could still have other style information?

I added some code snippets that might be relevant to solve the problem:

my plugin.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.editors">
      <editor
            name="CXX Editor"
            extensions="cpp"
            icon="icons/sample.gif"
            contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
            class="cppeditor.editors.CppEditor"
            id="cppeditor.editors.CppEditor">
      </editor>
   </extension>
   <extension
         id="cppeditor.problemmarker"
         name="clang Error"
         point="org.eclipse.core.resources.markers">
      <super
            type="org.eclipse.core.resources.problemmarker">
      </super>
      <super
            type="org.eclipse.core.resources.textmarker">
      </super>
      <persistent
            value="true">
      </persistent>
   </extension>
</plugin>


The method to add markers to the IFile resource:

public void addMarkerToFile(IFile file, IDocument fileDocument) throws CoreException, BadLocationException{
		IMarker marker = file.createMarker("cppeditor.problemmarker");
		marker.setAttribute(IMarker.SEVERITY, this.severity);
		marker.setAttribute(IMarker.MESSAGE, this.message);
		marker.setAttribute(IMarker.LINE_NUMBER, this.line);
		int startOffset = fileDocument.getLineOffset(this.line-1);
		int endOffset = fileDocument.getNumberOfLines() > this.line ? 
		         fileDocument.getLineOffset(this.line) : fileDocument.getLength()-1;
		marker.setAttribute(IMarker.CHAR_START, startOffset);
		marker.setAttribute(IMarker.CHAR_END, endOffset);
	}


The "createPresenation" method of the PresenationRepairer

	@Override
	public void createPresentation(TextPresentation presentation, ITypedRegion region) {
		CppDocument doc = (CppDocument) this.fDocument;
		Token[] newTokens = doc.getTokens();
		if(newTokens != oldTokens){
			for(Token t : newTokens){
				addRange(
					presentation,
					t.getStart(),
					t.getEnd() - t.getStart(),
					attributeMap.get(t.getKind()));		
			}
			oldTokens = newTokens;
		}
	}


And finally my SourceViewerConfiguration:

public class CppConfiguration extends SourceViewerConfiguration {
	public CppConfiguration(ColorManager colorManager) {}

	@Override
	public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
		return new String[] { IDocument.DEFAULT_CONTENT_TYPE };
	}

	@Override
	public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
		PresentationReconciler reconciler = new PresentationReconciler();

		NonRuleBasedDamagerRepairer ndr = new NonRuleBasedDamagerRepairer();
		reconciler.setDamager(ndr, IDocument.DEFAULT_CONTENT_TYPE);
		reconciler.setRepairer(ndr, IDocument.DEFAULT_CONTENT_TYPE);
		return reconciler;
	}
	
	@Override
	public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
		return new DefaultAnnotationHover();
	}

}

Previous Topic:Eclipse editor is not becomes dirty when I change the text
Next Topic:Extension to auto-check problems of editor
Goto Forum:
  


Current Time: Thu Nov 15 08:59:02 GMT 2018

Powered by FUDForum. Page generated in 0.03628 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top