Home » Modeling » TMF (Xtext) » Need hover for keyword or block of elements
| | | | |
Re: Need hover for keyword or block of elements [message #988355 is a reply to message #988345] |
Thu, 29 November 2012 14:49 |
Sebastian Zarnekow 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 #988374 is a reply to message #988371] |
Thu, 29 November 2012 16:17 |
Aaron Digulla 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 |
Henrik Lindberg 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 #988647 is a reply to message #988631] |
Fri, 30 November 2012 20:35 |
Sebastian Zarnekow 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
|
|
| |
Goto Forum:
Current Time: Tue Apr 23 10:39:25 GMT 2024
Powered by FUDForum. Page generated in 0.05096 seconds
|