Highlighting a point (or an offset) in a file instead of a region - eclipse

I am developing an Eclipse plug-in, and I want to highlight some points (between two consecutive characters in a file) instead of a region of text.
As an example, suppose that I want to highlight the position where foo has been deleted in a source file.
I know about the Markers(link), and I can set an annotation to a point in file, which can be shown in the side ruler areas.
Would there be any way to make it visible directly within the editor area itself?
It's obvious to highlight an area of text using something like boxes, underlines, but I couldn't find anything for a single point.
It would be nice if I could draw something like a caret, or a text cursor mark to some of the points I want to highlight.

I'm afraid annotations is the only civilized way to do it. You can apply them without markers as markers only simplify annotations management and provide persistence mechanism. All depends on how you get the information on what to highlight. Any more details on that?
If you're looking only for a way to customize annotation painting there's no way to do it via API. See in AnnotationPainter.getDecoration(), this is where the stuff happens. Looks like you can customize it only if you provide your own editor. More here - http://www.eclipse.org/forums/index.php/t/102865/.

Related

Drawing arrows and symbols in Visual Studio Code

I am writing a small tools for VS Code and the tool will need to draw arrows between symbols in the code.
Something along these lines.
Please forgive my skills with Paint.
What it is the best way to achieve this effect in VS Code?
What you want is not possible. The editor output in vscode is a list of DOM nodes (divs for the lines, spans for the syntactic elements). You cannot draw lines between DOM nodes.
If you had full control over the editor you could add an overlay over the entire text to draw the lines, but then you have to take care not to disturb the normal behavior of the editor and, after all, you don't have that kind of control.
A webview is not a good approach, as it would not only require to duplicate the work the normal editor does, it's also isolated and has no direct access to the main application, which means actions, language server support etc. don't work
yes sure use this Rainbow Brackets
its draw an arrow between the start and the end .
enter image description here

VS Code extension API for registering pointer down and up and translating coordinates to line/character position

I have developed a VS Code Box Drawing extension which works by using selection's start and end positions to work out a level rectangle between the two positions in the text and replaces the edge characters of the rectangle with Unicode box drawing characters.
This works great with a selection start and end positions provided, but it also requires at least white space to already extend all the way to the right edge of where the box is supposed to end, otherwise the selection cannot be made that far.
I would like to achieve two things:
Be able to use mouse events and figure out would-be positions from them even if they extend beyond the length of the lines, so that I can back-fill the missing line length with white-space as I go drawing the box.
Be able to draw arrows (simple enough using the Bresenham's line algorithm).
I have read the Visual Studio Code API Reference and it has only one mention of the mouse pointer in this section underneath the languages header:
The rest, like tracking the mouse, positioning the hover, keeping the hover stable etc. is taken care of by the editor.
I have also read through the Extensibility Reference finding nothing relevant to what I aim to achieve.
This extension only makes sense for monospaced fonts, so additionally, I'd like to find out if there is a way to tell if the editor font is monospaced so I can reject extension activation with an error if that's not the case.
This is something the VS Code team doesn't currently enable (not a part of the extension API) not wants to enable in the near future:
I think that exposing mouse events to the extension API is not something that we'd be likely to add
Source comment on GitHub

How do I adjust the position attributes of custom Eclipse markers when a file is edited by typing?

Does Eclipse adjust the position attributes of custom markers when a file is edited?
I have many Eclipse plugins in which I successfully create and delete markers, create quick fixes, and apply edits to the active editor programmatically. When text is inserted or deleted from the buffer all the text in the editor shifts, of course, and Eclipse's markers and my custom markers stay in synch with the text.
The problem is that when the file is edited, whether by regular typing or programmatically by changing the IBuffer, the attributes (e.g. CHAR_START) are not modified - they report the values when the marker was created and first made visible. So when one goes to do a QuickFix on the marker, for example, the reported position is incorrect. (This is an info marker, in CDT, if that matters.)
How are these marker positions supposed to be updated when edits happen?
Is there an Eclipse way to do this, but I need to implement some setting or notification or listener?
One possibility is to implement a ResourceChangeReporter - but it is not triggered for me when text edits happen, just when, for example, a save is invoked. And, if it were, I don't see information about how the file is actually altered.
I suppose I could require that a dirty file be saved before the quick fix is applied, but I still don't see where to obtain information about the file's edits. If I apply the edit programmatically, I know this information, but it does not help when the edit happens by typing.
Marker positions can be updated during editing using an updater declared using the org.eclipse.ui.editors.markerUpdaters extension point and implementing the IMarkerUpdater interface.
However there is a default updater org.eclipse.ui.texteditor.BasicMarkerUpdater which is already active for all markers which should be doing basic position updating for you.

Marking/commenting Matlab code?

Is there any way to mark Matlab code (in Matlab) via some kind of add-on? I'm looking for something similar to what Microsoft Word has with its "Review" mode where you can highlight a certain phrase/section and make a comment on the side. When I say "comment", I don't mean the regular code comments that you do with "%" in Matab.
I've googled for this, but I couldn't find anything. Anyone know if something like this exists that I may have missed? It would really help me when I'm reading someone else's code and I have to keep track of things / make comments for certain lines. Even if commenting isn't possible, it would be nice to be able to highlight certain lines via some kind of "highlighter" like the one in Word.
No. This isn't possible.
In fact, most editors and IDEs (if not ALL of them) that I know don't even support this feature as each IDE will have to be specific in the way this is implemented (à la Trojanian). The only thing that I can think of is if you print out the code in PDF, then use bubbles within the PDF viewer to tack on your comments.
However, if you want to highlight a specific line in your editor, you'll have to set this up in your settings. Go to preferences, then in the Editor / Debugger options, choose the Display option, then choose Highlight Current Line. Choose whichever colour you see fit. I'm running MATLAB R2013a on Mac OS, and this is the window I get:
You'll see the Highlight Current Line feature. Change that to whichever colour you want. I have it as gray because I do like having the current line highlighted.

Multiple cursor markers in Eclipse text editor

I am developing a plug-in for Eclipse. I have to develop a Java text editor which allows several users to write the code at the same time, the same way as in Google Docs. But I came across the following problem: the text editor has to show the cursor position of the other users who are coding in same Java document. In other words, I want to place a marker in the text editor content (see this image that shows what I'm trying to implement).
I've already looked IMarker, but IMarker is placed on the text editor's vertical ruler, which is not what I want. Can I use this class? If not, what other class should I use?
The other idea of mine was to insert a JTable in the text editor, but I couldn't find the way how to do that. Is this a right approach, or I'm wrong?
Stack Overflow Gods, please help me...
Eclipse has two different concepts for managing extra information related to files: markers and annotations. Annotations are related to a single editor instance, and their appearance can be customized with a corresponding extension point; markers are used to store extra information permanently (and additionally an annotation can be set up for that reason).
I think, you need to use annotations, as markers are too heavyweight for a real-time collaboration. For future reference, see the Annotations in the Eclipse Help; and some time ago I have written a blog post that describes an automatic translation (and customization) of markers to annotations.