Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Need hover for keyword or block of elements
icon5.gif  Need hover for keyword or block of elements [message #987926] Wed, 28 November 2012 16:45 Go to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
I have a DSL where a user can define paramaters with options. Options can be inherited from option sets, they have defaults, etc.

In short, options are complex. To help users of the DSL, I'd like to show them the "effective" options, i.e. a hover with all the options plus a hint whether the option value is the default.

But I couldn't find a way to define a hover in my MSetDslEObjectHoverProvider for a keyword or a block. The DSL looks like this:

    param foo {
        options {
            name = value;
            name2 = value2;
            ...
        }
    }


I can create a hover on "name" and "value" (they are model types) but "options" is a keyword.

Is that possible somehow? Or do you have a workaround?
Re: Need hover for keyword or block of elements [message #988204 is a reply to message #987926] Wed, 28 November 2012 19:12 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
When calculating a custom hover, don't you get an IRegion? Using the offset information you can go to the node model, check the grammar element at the given position and create your hover information in case it is a keyword.

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: Need hover for keyword or block of elements [message #988218 is a reply to message #988204] Wed, 28 November 2012 21:45 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
No, the hover building code of Xtext is never called when the mouse is over a keyword.

My guess is this isn't possible by design of the current implementation but I hope there is a workaround.
Re: Need hover for keyword or block of elements [message #988235 is a reply to message #988218] Thu, 29 November 2012 02:57 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-28-11 22:45, Aaron Digulla wrote:
> No, the hover building code of Xtext is never called when the mouse is
> over a keyword.
>
> My guess is this isn't possible by design of the current implementation
> but I hope there is a workaround.
You can specify for which grammar elements the logic is triggered.

Check out

https://github.com/cloudsmith/geppetto/tree/master/org.cloudsmith.geppetto.pp.dsl.ui/src/org/cloudsmith/geppetto/pp/dsl/ui/editor/hover

Where there is are two providers; one that computes for which elements a
hover should be constructed, and one that constructs the documentation
for it.

In case you wonder - I generate HTML doc from Ruby RDoc/markdown for the
Puppet language, and almost none of the things I want doc hovers for
gets them by default.

IIRC, that was all I had to do (oh, and bind those naturally).

Hope that helps.
- henrik
Re: Need hover for keyword or block of elements [message #988345 is a reply to message #988235] Thu, 29 November 2012 13:44 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Henrik Lindberg wrote on Thu, 29 November 2012 03:57
On 2012-28-11 22:45, Aaron Digulla wrote:
> No, the hover building code of Xtext is never called when the mouse is
> over a keyword.
You can specify for which grammar elements the logic is triggered.


hasHover() is not called for elements of type org.eclipse.xtext.Keyword - they aren't part of the model. So your code sample doesn't help Sad
Re: Need hover for keyword or block of elements [message #988355 is a reply to message #988345] Thu, 29 November 2012 14:49 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Am 29.11.12 14:44, schrieb Aaron Digulla:
> Henrik Lindberg wrote on Thu, 29 November 2012 03:57
>> On 2012-28-11 22:45, Aaron Digulla wrote:
>> > No, the hover building code of Xtext is never called when the mouse is
>> > over a keyword.
>> You can specify for which grammar elements the logic is triggered.
>
>
> hasHover() is not called for elements of type org.eclipse.xtext.Keyword
> - they aren't part of the model. So your code sample doesn't help :(

Hi Aaron,

did you try to set a breakpoint on
DispatchingEObjectTextHover.getHoverInfo(EObject, ITextViewer, IRegion)

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Need hover for keyword or block of elements [message #988371 is a reply to message #988355] Thu, 29 November 2012 16:02 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Thu, 29 November 2012 15:49
did you try to set a breakpoint on
DispatchingEObjectTextHover.getHoverInfo(EObject, ITextViewer, IRegion)


Yes, it never gets there. In fact,

org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover.getHoverInfo2(ITextViewer, IRegion)

isn't called because

org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int)

returns null for keywords (they don't have a related EObject in the model).

Re: Need hover for keyword or block of elements [message #988374 is a reply to message #988371] Thu, 29 November 2012 16:17 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Okay, I found a solution but it's ugly: I have to override the methods getHoverRegion() and getHoverInfo2() of DispatchingEObjectTextHover because they return null for AST nodes that don't have a corresponding EObject in the DSL model.

In the first method, I check whether it's a keyword and the name of the keyword and return its region when it's the correct one.

The second method is the hack: I create an EObject from scratch (i.e. it's not part of my package) and return that. The code looks like this:

public class ParamOptions extends EObjectImpl {

    private Parameter param;

    public ParamOptions( Parameter param ) {
        eBasicSetContainer( (InternalEObject) param.eContainer(), -1 );
        this.param = param;
    }

    public void setParam( Parameter param ) {
        this.param = param;
    }

    public Parameter getParam() {
        return param;
    }
    
    @Override
    public EClass eClass() {
        return ParamOptionsEClass.INSTANCE;
    }
    
    public static class ParamOptionsEClass extends EClassImpl {
        public static ParamOptionsEClass INSTANCE = new ParamOptionsEClass();
    }
}


After that, I can check for this EClass and type in the rest of the label provider code.

As you can see, this is quite a hack but I don't really know to create an EClass at runtime and hook that into my model.

Suggestions?

[Updated on: Thu, 29 November 2012 16:18]

Report message to a moderator

Re: Need hover for keyword or block of elements [message #988376 is a reply to message #988371] Thu, 29 November 2012 16:25 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-29-11 17:03, Aaron Digulla wrote:
> Sebastian Zarnekow wrote on Thu, 29 November 2012 15:49
>> did you try to set a breakpoint on
>> DispatchingEObjectTextHover.getHoverInfo(EObject, ITextViewer, IRegion)
>
>
> Yes, it never gets there. In fact,
>
> org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover.getHoverInfo2(ITextViewer,
> IRegion)
>
> isn't called because
>
> org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource,
> int)
>
> returns null for keywords (they don't have a related EObject in the model).
>
>
Actually, the problem is that a check is made if the mouse pointer is in
a position that is inside the region returned by
LocationInFileProvider.getSignificantTextRegion(o). It finds the EObject
as it should.

The significantTextRegion is the region is used in several places to
figure out the "target to link to and highlight". So, solving the issue
by including the keyword in the significant region may lead to
undesirable effects elsewhere (i.e. you want to only select the "name"
or similar ID).

Seems like there is an abstraction missing for hovers.

Fix would be to override and bind your own version of
org.eclipse.xtext.ui.editor.hover.DispatchingEObjectTextHover#getXtextElementAt

And make use of the ILocationInFileProviderExtension interface and ask
for the full region instead of only the significant part.

(Which I think the AbstractEObjectHover should probably do at all times
to allow discrimination of what to show hovers for easier to customize).

- henrik
Re: Need hover for keyword or block of elements [message #988606 is a reply to message #988376] Fri, 30 November 2012 16:53 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron DigullaFriend
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Henrik, can you please open an issue on bugzilla? I'm not deep enough in Xtext to understand everything that you said. Smile

Ideally, the end result should allow me to create a hover when the mouse is anywhere over

options {


i.e. the two keywords and the space between them.

Thanks!
Re: Need hover for keyword or block of elements [message #988631 is a reply to message #988606] Fri, 30 November 2012 18:16 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-30-11 17:53, Aaron Digulla wrote:
> Henrik, can you please open an issue on bugzilla? I'm not deep enough in
> Xtext to understand everything that you said. :)
>
> Ideally, the end result should allow me to create a hover when the mouse
> is anywhere over
>
> options {
>
> i.e. the two keywords and the space between them.
>
> Thanks!
You can easily try this out.
Make a copy of/derive a class from:
org.eclipse.xtext.ui.editor.hover.DispatchingEObjectTextHover

(don't remember exactly what that class looked like).
Override #getXtextElementAt method. Instead of asking for the
"significant region" from the provider, check if this provider
implements the extended interface I mentioned, if so, you can ask for
the entire object's region instead of just the "significant" portion.

Then, you bind your specialized DispatchingEObjectTextHover as a
replacement for what is now bound.

- henrik
Re: Need hover for keyword or block of elements [message #988647 is a reply to message #988631] Fri, 30 November 2012 20:35 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
It may be worthwile to specialize #getSignificantRegion for your
language if you consider the keyword 'options' to be the significant,
identifying token of your model instance.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.11.12 19:16, schrieb Henrik Lindberg:
> On 2012-30-11 17:53, Aaron Digulla wrote:
>> Henrik, can you please open an issue on bugzilla? I'm not deep enough in
>> Xtext to understand everything that you said. :)
>>
>> Ideally, the end result should allow me to create a hover when the mouse
>> is anywhere over
>>
>> options {
>>
>> i.e. the two keywords and the space between them.
>>
>> Thanks!
> You can easily try this out.
> Make a copy of/derive a class from:
> org.eclipse.xtext.ui.editor.hover.DispatchingEObjectTextHover
>
> (don't remember exactly what that class looked like).
> Override #getXtextElementAt method. Instead of asking for the
> "significant region" from the provider, check if this provider
> implements the extended interface I mentioned, if so, you can ask for
> the entire object's region instead of just the "significant" portion.
>
> Then, you bind your specialized DispatchingEObjectTextHover as a
> replacement for what is now bound.
>
> - henrik
Re: Need hover for keyword or block of elements [message #988674 is a reply to message #988647] Sat, 01 December 2012 00:43 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-30-11 21:35, Sebastian Zarnekow wrote:
> It may be worthwile to specialize #getSignificantRegion for your
> language if you consider the keyword 'options' to be the significant,
> identifying token of your model instance.
>
> Regards,
> Sebastian

That too of course, but you may not always want to have everything be
the "significant portion" even if you want that for hovers.

A good way could be to implement your own anyway, and provide both the
significant region (the name of id or whatever), as well as the
additional regions specified by the extended interface.

(that is if I got the intent of the extended interface right :)

Regards
- henrik
Previous Topic:Check if a feature matches one among more terminals
Next Topic:Content is not allowed in prolog.
Goto Forum:
  


Current Time: Fri Apr 19 07:28:35 GMT 2024

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

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

Back to the top