How can I indicate syntax errors (e.g. an illegal sequence of tokens) in an eclipse editor plugin just like in the eclipse Java editor, i.e. by red wriggly underlines, a red marker on the scrollbar that you can jump to, and an explanatory message when you hover over either one?
I'm writing an eclipse editor plugin for a custom file format (specifically, the "snake file format" of the Shark3D game engine). I have implemented a scanner to get syntax highlighting, and an outline.
For the underlines, do I simply have the scanner return an IToken with a "wriggly underline" TextAttribute instead of the normal one, or is there a specific mechanism for marking syntax errors?
How do I implement the scrollbar markers? Is IAnnotationModel the relevant interface here? If so, where do I register the implementation so that the markers appear?
I've only found SourceViewerConfiguration.getAnnotationHover(), which would allow me to implement the hover behaviour, but only for the "annotation", which I suppose means the scrollbar markers - how do I implement the hover behaviour for the text itself?
I'd be happy specific advice as well as an URL of a tutorial that covers this - the eclipse help documents and examples don't seem to.
Edit:
Markers are the best solutions to this. A working example of how to use them can be found in the plugin example code in org.eclipse.ui.examples.readmetool.AddReadmeMarkerAction
You should be using Markers.
An example derived from "The Java Developer's Guide to Eclipse" follows:
<extension point="org.eclipse.core.resources.markers"
id="snakesyntax"
name="Snake syntax error">
<super type="org.eclipse.core.resources.problemmarker" />
<super type="org.eclipse.core.resources.textmarker" />
<persistent value="true" />
<extension>
IMarker marker = res.createMarker("com.ibm.tool.resources.snakesyntax");
marker.setAttribute(IMarker.SEVERITY, 0);
marker.setAttribute(IMarker.CHAR_START, startOfSyntaxError);
marker.setAttribute(IMarker.CHAR_END, endOfSyntaxError);
marker.setAttribute(IMarker.LOCATION, "Snake file");
marker.setAttribute(IMarker.MESSAGE, "Syntax error");
The correct way is using the marker interface.
Markers are essentially a model that maps marker objects to locations in your source code, so this makes sense in situations where you can have errors in multiple files. (see the IMarker interface)
A cheaper option if you want to add markup to your current editor but not to all the project is using Annotations, which you can add an remove yourself.
Markers are represented in the UI as annotations but Eclipse adds and removes the annotations itself. With direct annotations, you're in control.
Related
Is there a way to just see one method of a class in the IntelliJ IDEA editor and hide everything else, and/or toggle between this and the regular view.
Please note, I'm not looking to fold/collapse other methods, which is certainly a way to minimize getting lost in a large file.
I am looking for a way to only view a specific method I'm working on within a class.
e.g. If there is a legacy code where an existing class has 10 long
methods (each ~50 lines long), and I'm working on one of them and don't wish to be lost in
the 500 lines of code and need to focus on a single method thereby narrowing my view to 50
lines of code.
I do remember a few versions back that this was possible, but am not able to find that setting now.
Further clarifying my question. Consider the method selected in the image below
I am interested in a view that'll show just the method like below (with all the java capabilities like code highlighting, refactoring etc., enabled of course):
In IntelliJ IDEA 2019.3.3 (Community Edition) there's a fold option 'Fold Selection' that hides even the signature.
Select / highlight the code above the method you want to focus on
Right click > Folding > Fold Selection. Shortcut = cmd + .
It might be in earlier versions but I haven't checked.
Fold selection menu option
I have searched in google but unfortunately couldn't find any answers, so the question is:
What this symbol means in eclipse? (eclipse version : neon.1 for EE developers)
(It is known that the green dot indicates a method but what about the yellow star?)
Update: In this image you can see 8 methods that have the star symbol.
Completion proposals with that icon are contributed by Code Recommenders. That plugin leverages external information to recommend more relevant proposals, as you can also see by the percentage shown beside each entry: it indicates s.t. like the probability that the given proposal is what you need in your context.
You will also find mention of Code Recommenders and how it intergrates with JDT in the preferences under Java > Editor > Content Assist > Advanced.
Doesn't it have a tooltip? Just hover over it and see what it says.
That might be a custom icon that was introduced by a certain Eclipse plugin that you installed. To figure out what plugin it relates to, go to Window -> Customize Perspective. There, under Tool Bar Visibility tab, you will see the tool bar structure. You can expand each section to see the list of functions and the related icons. Your icon should be there somewhere.
Eclipse generally sorts methods alphabetically.
To ease users, top used methods are listed before the alphabetical sorting; think of System.out where println will be on top.
Another case is when a certain return type is expected, say for any arbitrary object:
String str = obj.
toString() will be on the top.
Methods like these are starred.
Please do not confuse this with 'selecting code' like selecting code with a mouse.
When my debug device hits a break point I want to highlight the specific line of code.
I am using the CDT Plugin.
I already got the lineNumber and all I want to do now is to tell
editor.highlightLine(lineNumber);
to get something like this:
I already tried this:
marker = resource.createMarker(IMarker.TEXT);
marker.setAttribute(IMarker.LINE_NUMBER, 10);
marker.setAttribute(IMarker.CHAR_START, 0);
marker.setAttribute(IMarker.CHAR_END, 10);
but it didn't work.
Since there are already predefined annotations provided by Eclipse and/or the CDT Plugin I'd like to reuse them. But how to access and use them inside sourcecode?
You can create your own marker using an extension point "org.eclipse.core.resources.markers" and adding super attribute of type "org.eclipse.core.resources.textmarker". After setting up your marker, you still need to describe its look and feel by adding the annotation extension point "org.eclipse.ui.editors.annotationTypes"
I am not exactly sure of your intentions but this link might help http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-plugin-guide/section3.html
Marker is the thing on your ruler. You need to look at the editor background painting. Take a look at InstructionPointerManager.java
I had the same problem. And I solve it by creating my own marker. I follow the step of this blog http://cubussapiens.hu/2011/05/custom-markers-and-annotations-the-bright-side-of-eclipse/ and create a marker when the lineNumber changed. It will highlight this line.
I've written an eclipse editor for my own DSL. When an editor is opened or saved I check the contents and create problem markers for any syntax errors. The markers show up in my editor as expected, and also in the Problems view.
I've got an extension point org.eclipse.ui.ide.markerResolution and provide an implementation of IMarkerResolutionGenerator which creates resolutions for problem markers. This works fine; when I right click a problem in the Problems view the Quick Fix option shows in the context menu and works fine.
My editor extends SourceViewerConfiguration and I override getQuickAssistAssistant(), returning an extension of QuickAssistAssistant. This allows me to right click a problem in the editor and see the Quick Fix option in the menu.
I'd really like to get the quick fix resolutions to appear when I hover over the problem in the editor, just like in the java editor. Currently just the problem text appears in the tooltip. Is there a seperate hook into this or should it be covered in two quick fix hooks I've already implemented?
I had the same problem and found a solution for myself: How to implement Quick Fix / Quick Assist for custom eclipse editor?
From what I've understood, Markers show up in the Problems View and Annotations show up in the editor (on the ruler and on mouse hover).
I use the org.eclipse.ui.editors.annotationTypes extension point to register my own annotation type and the org.eclipse.ui.editors.markerAnnotationSpecification extension point to specify the look and feel. In my custom SourceViewerConfiguration class I override getAnnotationHover(...) to return a DefaultAnnotationHover object and getTextHover(...) to return a DefaultTextHover object, so the annotations are shown in my source viewer.
To create annotations, you could use org.eclipse.ui.texteditor.SimpleMarkerAnnotation, you can construct a SimpleMarkerAnnotation passing a marker object to the constructor.
Then you need to add the annotation to the annotation model. You can use getAnnotationModel() on your SourceViewer and then addAnnotation(Annotation annotation, Position position) on the AnnotationModel. All annotations in the model will be shown in the editor.
You could also use org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel as your annotation model. Then you won't need to create annotation objects first, since AbstractMarkerAnnotationModel provides a method addMarkerAnnotation(IMarker marker).
Have a look at the IAnnotationModel interface.
i am having trouble with custom quick-fixes, which i want to provide in my Eclipse plug-in, and i'm hoping for someone more experienced than me in Eclipse PDE to have some hints for me on this issue.
As i have understood, i can provide custom so-called "quick fixes" (or "resolutions", in Eclipse inside terminology), by extending the extension point org.eclipse.ui.ide.markerResolution for a specific marker id, such as for example some default Eclipse marker, org.eclipse.core.resources.problemmarker.
This works for me for the default marker types and for custom marker types, BUT:
The QuickFixes, which my IMarkerResolutionGenerator provides, are only accessible from the "Problems"-View, not from the Editor, in which my markers show up.
What i have: I create markers in the default text editor, which causes (1) an icon with the markers tooltip message to show up on the left editor ruler at the line, which the marker is assigned to, (2) a marker on the right side of the editor, (3) some underlined characters in the editor, and (4) an entry in the "Problems"-view.
What i want: Just like in Java IDE support, i want to press Strg+1, or Context-Menu->Quick Fix, or to click at the error icon on the left-side-ruler, to see the available quick-fixes and to select one.
However: Only in the Problems-View am i able to get the Quick-Fixes, by pressing Strg+1 or from the context menu.
Is this the normal behaviour, and do i have to access another extension point, or the specific editors features, to hook my quick fixes into them? I haven't found anything much detailed about it, except that everybody seems to be pretty happy with this only extension point that i have mentioned above. What am i missing?
For completion, here is my extension point definition:
<extension point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
class="com.markers.test.MarkerResolutionGenerator"
markerType="org.eclipse.core.resources.problemmarker">
</markerResolutionGenerator>
</extension>
I have the same problem and I'm not sure, if this is the right way, but at least it works:
If you want to see your quick fixes in the source viewer you have to set an QuickAssistAssistant for it. In your class implementing SourceViewerConfiguration override getQuickAssistAssistant. You can instantiate org.eclipse.jface.text.quickassist.QuickAssistAssistant, but you have to set a QuickAssistProcessor, so implement the org.eclipse.jface.text.quickassist.IQuickAssistProcessor interface, especially computeQuickAssistProposals to return your quick fix proposals.
public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) {
IQuickAssistAssistant quickAssist = new QuickAssistAssistant();
quickAssist.setQuickAssistProcessor(new MyQuickAssistProcessor());
quickAssist.setInformationControlCreator(getInformationControlCreator(sourceViewer));
return quickAssist;
}
Also have a look at the code in the last post here, it is a bit messy, but you will get it. And look at this code here for an example implementation of ICompletionProposal, which you will have to return in your QuickAssistProcessor.
If you simply add one line to the marker extension point:
<super type="org.eclipse.core.resources.textmarker"/>
and add attributes to the marker
marker.setAttribute(IMarker.CHAR_START, ...);
marker.setAttribute(IMarker.CHAR_END, ...);
You will be able get this:
But I still can't found how to change marker icon (to variant with bulb) a show possible quick fix also after click on the annotation icon.