Sonntag, 15. Juni 2014

Xtext 2.6: Task Markers

With the release of Xtext 2.6 we added a cool new feature that will just work out of the box for most languages out there. By default you will get markers for TODO, FIXME and XXX in single and multiline comments. These tags will also be highlighted and tasks will appear in the tasks view, just as you are used to from JDT.

All the tasks will appear under the type Xtext task. You can add a preference page via the TaskTagPreferencePageFragment.

You can also customize how tasks are found by overwriting the Guice bindings for these interfaces:


Given a resource, finds the tasks. The default implementation will look at all leaf nodes and if they are comments (according to IHiddenTokenHelper), will pass them to the ITaskParser. It uses an ITaskTagProvider to tell which task tags to search for.


Given a String and the defined task tags, finds the tasks. The default implementation matches each line of the String against the given tags. The task description is the text following the tag until the end of the line.


Given a resource, tells which task tags should be searched. The default implementation uses a fixed list (TODO, FIXME, XXX). There is also a preference based implementation, which is activated by the TaskTagPreferencePageFragment. Writing your own should be as straightforward as writing a list in most cases. For Xtend we reuse the task tags defined in the JDT preference page.


Tasks are found, but not colored

You have bound the ISemanticHighlightingCalculator interface, which used to have no default implementation. The task highlighting is done by the new DefaultSemanticHighlightingCalculator. I strongly encourage you to inherit from that, as it also comes with a lot of convenience methods for highlighting in general.

I want tasks to have a different marker type

We have the TaskMarkerTypeProvider for this. The default implementation will return Xtext task. There is also the LanguageAwareTaskMarkerTypeProvider, which will give markers a type named after your language. But you can also write and bind your own, e.g. to give different markers different images (like a wizard hat for MAGIC tags ;)