Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Javadoc-style context/hover information for rules/keywords(Display context sensitive when hovering over keywords)
Javadoc-style context/hover information for rules/keywords [message #1008201] Mon, 11 February 2013 11:52 Go to next message
Sebastian Neumann is currently offline Sebastian Neumann
Messages: 9
Registered: December 2010
Junior Member
Hi,

I am looking for a way to display the javadoc comment in the rule definition when hovering over the keyword. An example:

/**
 * My doc , this is how you use it
 */
TestClass: 'test' name=ID 


When I use hover/click on 'test' in my editor I would like to see the javadoc as a popup? Hope someone can point me in the right direction.

Best regards,
Sebastian
Re: Javadoc-style context/hover information for rules/keywords [message #1008256 is a reply to message #1008201] Mon, 11 February 2013 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6378
Registered: July 2009
Senior Member
Hi,

you may have a look at org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int)
you will see that the hover is by default only shown for the significant region, which is the name
Re: Javadoc-style context/hover information for rules/keywords [message #1008524 is a reply to message #1008201] Tue, 12 February 2013 20:30 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1156
Registered: July 2009
Senior Member
Hi,

http://blogs.itemis.de/stundzig/archives/868 may serve as a starter to get hovers for keywords to work at all.

As far as I know, there is no way to access the grammar file at runtime (in order to get at the rules' comments), so you'll have to write an IGeneratorFragment that extracts that information from the grammar file. For a first prototype it will be easier to provide the information per keyword by hand.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Javadoc-style context/hover information for rules/keywords [message #1009125 is a reply to message #1008524] Thu, 14 February 2013 13:47 Go to previous messageGo to next message
Sebastian Neumann is currently offline Sebastian Neumann
Messages: 9
Registered: December 2010
Junior Member
Thanks, both Christian and Alexander. Will give it try.

Regards
Re: Javadoc-style context/hover information for rules/keywords [message #1059056 is a reply to message #1009125] Thu, 16 May 2013 12:49 Go to previous messageGo to next message
Sebastian Neumann is currently offline Sebastian Neumann
Messages: 9
Registered: December 2010
Junior Member
Hi,

if anyone is interested I resolved the 'hover' javadoc-like feature as follows; as my whole project is built with Maven I hooked in a Test file that reads my xtext file, parses it and writes the comments to a custom xml file. That file is then evaluated by binding my custom DocumentationProvider to the module. I evaluate the object name (class name) and read it from my XML file.

Might not be the most elegant solution, but it works and I only have to maintain my xtext file (that's where I have already put my comments).

Regards,
Sebastian
Re: Javadoc-style context/hover information for rules/keywords [message #1060564 is a reply to message #1008524] Mon, 27 May 2013 03:06 Go to previous messageGo to next message
rafael lima is currently offline rafael lima
Messages: 2
Registered: July 2012
Junior Member
Hi Alex,

I did as you sad (created a MydslEObjectHover class) and added the following lines in my MyDslUiModule class. It worked fine, but I had only one problem.

@Override
	public Class<? extends IEObjectHover> bindIEObjectHover() {
		return 	MydslEObjectHover.class;
	}


The EObject first is never an instance of Keyword, so the getHoverInfo method from super is always being called. Can you give some sugestion to handle it?

@Override
	public Object getHoverInfo(EObject first, ITextViewer textViewer,
			IRegion hoverRegion) {
		if (first instanceof Keyword) {
			return getHoverInfoForKeyword((Keyword) first);
		} else {
			return super.getHoverInfo(first, textViewer, hoverRegion);
		}
	}


Best Regards,
Rafael



Re: Javadoc-style context/hover information for rules/keywords [message #1060569 is a reply to message #1060564] Mon, 27 May 2013 06:22 Go to previous message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1156
Registered: July 2009
Senior Member
Hi,

did you override the getXtextElementAt-method as described in the blog entry, as well? It is essential. Otherwise, keywords are not processed at all, as you notice.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Previous Topic:Infer from external source
Next Topic:Save Action Error
Goto Forum:
  


Current Time: Tue Oct 21 03:59:12 GMT 2014

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

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