Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Some more questions on implementing task tag support
Some more questions on implementing task tag support [message #650670] Tue, 25 January 2011 18:49 Go to next message
Eclipse UserFriend
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 05:11 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Some more questions on implementing task tag support [message #1105319 is a reply to message #650734] Mon, 09 September 2013 13:31 Go to previous messageGo to next message
Eclipse UserFriend
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 Smile

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
Re: Some more questions on implementing task tag support [message #1105670 is a reply to message #1105319] Tue, 10 September 2013 02:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

thanks for the code snippet. As this could be a feature many Xtext users are interested in, you might file an enhancement request (if there isn't one already).
One issue with the builder approach could be that the markers are not updated if only task comments are modified, because this will not result in a resource delta by default. (I am not saying that the blog approach does not have issues - it was a proof of concept.)

Alex
Re: Some more questions on implementing task tag support [message #1106138 is a reply to message #1105670] Tue, 10 September 2013 15:03 Go to previous message
Eclipse UserFriend
Quote:
One issue with the builder approach could be that the markers are not updated if only task comments are modified ...


I can't verify right now, but I checked that editing only a TODO comment and saving does let the builder participant update the Tasks view. So I'm not sure if/how the problem you think of can actually occur.

Anyway, the builder integration was the smaller part, just the dot on the i to make this feature work as desired Smile

Stephan
Previous Topic:Invoke externally-defined serializer from command handler
Next Topic:Change one attribute's property from the genmodel programatically
Goto Forum:
  


Current Time: Fri Jul 04 16:41:41 EDT 2025

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

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

Back to the top