Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Hover provider for terminal rules(I have implemented Hover for parser rules but not been able to provide hover for terminal rules)
Hover provider for terminal rules [message #1699970] Mon, 29 June 2015 13:45 Go to next message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
Hello,
MyGrammar is like:
Model: entities += Entity*;

Entity: 
	'entity' name = ID REGVALUE ('extends' superType=[Entity])? '{'
	attributes += Attribute*
	'}'
;
Attribute:
	'<<<<' name=ID '>>>>'
;

terminal REGVALUE:'REGNO'('0'..'9')('0'..'9')*;



using the following MydslEObjectHoverProvider, i have implemented hover for rule "Entity"

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider;
import org.xtext.example.tet.*;
 
public class MydslEObjectHoverProvider extends DefaultEObjectHoverProvider {
 
    @Override
    protected String getFirstLine(EObject o) {
        if (o instanceof Entity) {
            return "this is a test hover: " + ((Entity)o).getName();
        }
        return super.getFirstLine(o);
    }
}


but when I try to provide hover for terminal rule "REGVALUE", I am not able to do that. I cannot write like this
if (o instanceof REGVALUE) {
            return "this is a test hover: " + ((REGVALUE)o).getName();
        }


please guide me in which way should i go?

[Updated on: Mon, 29 June 2015 14:17]

Report message to a moderator

Re: Hover provider for terminal rules [message #1699971 is a reply to message #1699970] Mon, 29 June 2015 13:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
Hi,

i do not understand what you want to do but you may debug into org.eclipse.xtext.resource.ILocationInFileProvider.getSignificantTextRegion(EObject) and org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int) and org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.hasHover(EObject) and others


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1699974 is a reply to message #1699971] Mon, 29 June 2015 13:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
and org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getHoverInfo2(ITextViewer, IRegion)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1699983 is a reply to message #1699974] Mon, 29 June 2015 14:16 Go to previous messageGo to next message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
Thanks for your reply.
Please now have a look at question again. I have tried to explain a little bit in detail.
Re: Hover provider for terminal rules [message #1699984 is a reply to message #1699983] Mon, 29 June 2015 14:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
HI,

an object never is a terminal.
this is why i have you some points where to debug to understand what happens


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1699988 is a reply to message #1699984] Mon, 29 June 2015 14:23 Go to previous messageGo to next message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
Ok thanks Christian,, I got it now and debugging into these.
Re: Hover provider for terminal rules [message #1700061 is a reply to message #1699970] Mon, 29 June 2015 21:40 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Hi,

for that purpose you'd have to override
org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.getHoverInfo(EObject,
ITextViewer, IRegion) and check the viewer and the given region to
compute the hover.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: Hover provider for terminal rules [message #1720751 is a reply to message #1700061] Wed, 20 January 2016 16:34 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi,

I have a query here.
If I only put this (Mohsin's grammar above)

Model: entities += Entity*;

Entity:
'entity' name = ID REGVALUE ('extends' superType=[Entity])? '{'
attributes += Attribute*
'}'
;
Attribute:
'<<<<' name=ID '>>>>'
;

terminal REGVALUE:'REGNO'('0'..'9')('0'..'9')*;

and did not use any MydslEObjectHoverProvider...
A default hover should be generated already??

I tried with Mohsin's grammar rules...I cannot populate out any default hover here.

Any idea?

Thank guys.
Re: Hover provider for terminal rules [message #1720754 is a reply to message #1720751] Wed, 20 January 2016 16:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
only if you hover at the Name=ID place

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1720757 is a reply to message #1720754] Wed, 20 January 2016 16:56 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
oh!! I got it now...
If I am having this

Model:
greetings+=Greeting*;

Greeting:
'Hello' name=ID '!';

it will only have pop out if hover at name=ID

But I need the hover pop out at the Hello there...
Is that possible??

Thank you..
Re: Hover provider for terminal rules [message #1720760 is a reply to message #1720754] Wed, 20 January 2016 17:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
as i said: if you have a look at the impl it will use ILocationInFileProvider and EObejctAtOffsetHelper to determine

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1720796 is a reply to message #1720760] Thu, 21 January 2016 06:16 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi Christian,

where can i find the ILocationFileProvider and EObejctAtOffsetHelper??
I really do not have an idea on this.

Thank you.
Re: Hover provider for terminal rules [message #1720797 is a reply to message #1720796] Thu, 21 January 2016 06:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
have a look at the impl ?!?!?!?!?!?!?!?!?

org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.hasHover(EObject)
org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1720888 is a reply to message #1720797] Thu, 21 January 2016 16:47 Go to previous messageGo to next message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
Hi Jia,
I think you need hover support on Keywords.
'Hello' is a keyword, By default hover is not available on keywords.
Just follow the tutorial (it extents Christian's this tutorial)
https://borisdevnotes.wordpress.com/2014/02/28/xtext-usability-hovers-on-keywords/
Re: Hover provider for terminal rules [message #1720889 is a reply to message #1720797] Thu, 21 January 2016 16:52 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi Christian,

sorry to ask this >< I am not familiar with eclipse yet...
is impl means ctrl + click at
org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider
or
org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover

then looked for the word ILocationInFileProvider and EObejctAtOffsetHelper ??
If that the way, I could not find that...

Thank you..
Re: Hover provider for terminal rules [message #1720890 is a reply to message #1720889] Thu, 21 January 2016 16:57 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi Mohsin,

yaya, I found this too...but seems like my project cannot extend the XbaseHoverProvider
and error unable to resolve for the import...

import org.xtext.example.mydsl.ui.hover.XbaseHoverProvider;

Do you have the same problem?
Or I miss out something??

Thank you
Re: Hover provider for terminal rules [message #1720894 is a reply to message #1720890] Thu, 21 January 2016 17:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
If you don't use xbase you should not extend xbasehoverprovider. You can use open type dialog to directly open classes (Crtl shift t on Windows) set a breakpoint in the methods and use the debugger to find out what happens (in the getxtextelementat method)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1720896 is a reply to message #1720894] Thu, 21 January 2016 17:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
Extend defaulteobjecthoverprovider instead.
Since I don't know your grammar and requirements that's all I can recommend


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1720967 is a reply to message #1720896] Fri, 22 January 2016 09:10 Go to previous messageGo to next message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
As Christian said If you don't use xbase you should not extend xbasehoverprovider,
I did not use xbase in my project so I did not extend xbasehoverprovider.
Instead I wanted documentation on keywords in my project, so I @Override IEObjectDocumentationProvider.getDocumentation(EObject).
Re: Hover provider for terminal rules [message #1721008 is a reply to message #1720967] Fri, 22 January 2016 13:58 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
okok...
Thank you Christian!!
Thank you Mohsin!!
Re: Hover provider for terminal rules [message #1721085 is a reply to message #1721008] Sat, 23 January 2016 14:15 Go to previous messageGo to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi,

Given is my grammar, the PUSH_POP_OP can be formed by different combination with condition suffix.
It is not a keyword in this case, I noticed that it is RuleCall in org.xtext.example.mydsl.services.MyDslGrammarAccess
can I still give hover for it??

terminal PUSH_POP_OP:
	('push' | 'pop' )CONDITION_SUFFIX?
; 

terminal CONDITION_SUFFIX:
	  'eq' | 'ne' | 'cs' | 'hs' | 'cc'
 ;

REGISTER:
	  r0?='r0'  | r1?='r1'
;
push_pop_instr:
	PUSH_POP_OP '{'register+=REGISTER(','register+=REGISTER)* '}' 
;
Re: Hover provider for terminal rules [message #1721086 is a reply to message #1721085] Sat, 23 January 2016 15:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
Hi,

i dont understand your point. you can hover at everything!!!!!!
but if you want to do strange things you have to care yourself
(debugging is your friend)

the starting point is as a said before org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getHoverRegion(ITextViewer, int)
which calls
org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int)

this is the place where boris' implementation gives back the keyword.

keywords from grammar access are eobjects like rules and all other stuff in your grammar.
in your case it may be a org.eclipse.xtext.RuleCall which rules is the terminal rule PUSH_POP_OP
(once more a debugger will help)
from the node model you can not only get the grammar stuff you are at,
but you can get the text as well (INode.getText)

of course you would it make 1000000000 times easier when using a datatype rule
instead of a terminal

PUSH_POP_OP:
('push' | 'pop' )CONDITION_SUFFIX?
;

(no terminal keyword)





Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Hover provider for terminal rules [message #1722306 is a reply to message #1721086] Thu, 04 February 2016 02:11 Go to previous message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi Christian,

I got it!!
Many thanks for your quick support =)
Previous Topic:Accessing properties... the right way!
Next Topic:Using XBlockExpressions and XExpressios without JvmModelInferrer
Goto Forum:
  


Current Time: Thu Oct 21 00:26:33 GMT 2021

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

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

Back to the top