Some more questions on implementing task tag support [message #650670] |
Tue, 25 January 2011 23:49 |
No real name Messages: 101 Registered: August 2010 |
Senior Member |
|
|
Hi,
I haev some more questions on implementing task tag (//TODO, FIXME, etc) support for my Xtext-based Editor. I notice in the Java editor that if I do "// TODO: blah", it just adds a IMarker.Task to the vertical ruler in the document. Only after I hit save, does more information about the task come into display in the Task View Tab.
I have been able to figure out a mechanism to extract the comments from my Xtext Editor resource. However, to accomplish the above, I think the best way is to create a class that implements IXtextEditorCallback and register (bind) it? Then, when a document gets saved, I extract the comments in this class and then update the markers. Would that be the correct approach or is there a better (easier) way?
Thanks.
|
|
|
Re: Some more questions on implementing task tag support [message #650734 is a reply to message #650670] |
Wed, 26 January 2011 10:11 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Sounds like a task for the XtextBuilder, as this is the component that
usually triggers the creation of markers in Xtext files. I'd register an
XtextBuilderParticipant for that task. The context it takes as a
parameter also contains the model resource as it is loaded by the builder.
Am 26.01.11 00:49, schrieb pgbackup@yahoo.com:
> Hi,
>
> I haev some more questions on implementing task tag (//TODO, FIXME, etc)
> support for my Xtext-based Editor. I notice in the Java editor that if I
> do "// TODO: blah", it just adds a IMarker.Task to the vertical ruler in
> the document. Only after I hit save, does more information about the
> task come into display in the Task View Tab.
>
> I have been able to figure out a mechanism to extract the comments from
> my Xtext Editor resource. However, to accomplish the above, I think the
> best way is to create a class that implements IXtextEditorCallback and
> register (bind) it? Then, when a document gets saved, I extract the
> comments in this class and then update the markers. Would that be the
> correct approach or is there a better (easier) way?
> Thanks.
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Re: Some more questions on implementing task tag support [message #1105319 is a reply to message #650734] |
Mon, 09 September 2013 17:31 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Thanks Jan,
Although I'm late at this party, let my try to connect the bits of existing information:
- I basically followed the approach discussed here: http://blogs.itemis.de/stundzig/archives/827
- and changed that component into an IXtextBuilderParticipant.
In case s.o. else is coming down this alley, there's one significant change to be performed:
The approach discussed in the blog uses an XtextEditor to invoke editor.getDocument().readOnly(...) in order to work on the XtextResource.
Obviously, creating myriads of editors is not a good idea for a builder participant.
In the end, the implementation of my XtextTaskCalculator (see [1]) melted down to just this:
public class XtextTaskCalculator implements IXtextBuilderParticipant {
@Inject
private XtextResourceFactory xtextResourceFactory;
@Inject
private ITaskElementChecker objElementChecker;
@Override
public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
for(IResourceDescription.Delta delta: context.getDeltas()) {
URI uri = delta.getUri();
IResource resource;
if (uri.isPlatformResource()) {
IPath path = new Path(uri.toPlatformString(true));
resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
} else {
// log warning "unexpected URI"
continue;
}
if (resource.exists())
resource.deleteMarkers(MarkerCreator.getMarkerType(), true, IResource.DEPTH_INFINITE);
XtextResource xtextResource = (XtextResource) xtextResourceFactory.createResource(delta.getUri());
try {
xtextResource.load(null);
new MarkerCreator(resource, objElementChecker, monitor).exec(xtextResource);
} catch (IOException e) {
// log error
}
}
}
}
Register this builder participant via extension point org.eclipse.xtext.builder.participant (and un-bind the IXtextEditorCallback) and from there on DSL files seamlessly integrate into the Tasks view
Ah, it also seems a good idea to configure the new marker to be persistent ...
cheers,
Stephan
[1] https://github.com/joergreichert/XtextPlayground/blob/master/TODO_Example_Xtext2/plugins/org.eclipse.xtext.todo.ui/src/org/xtext/example/mydsl/ui/tasks/XtextTaskCalculator.java
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03604 seconds