|
|
Re: XText 2.0 --- Hover Documentation [message #696741 is a reply to message #696735] |
Thu, 14 July 2011 18:26 |
|
Hi,
here a short solution for the greeting example:
package org.xtext.example.mydsl.ui;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider;
import org.xtext.example.mydsl.myDsl.Greeting;
public class MyDslEObjectHoverProvider extends DefaultEObjectHoverProvider {
@Override
protected String getFirstLine(EObject o) {
if (o instanceof Greeting) {
return "Damn good greeting: " + ((Greeting)o).getName();
}
return super.getFirstLine(o);
}
}
package org.xtext.example.mydsl.ui;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.xtext.example.mydsl.myDsl.Greeting;
public class MyDslEObjectDocumentationProvider implements IEObjectDocumentationProvider {
@Override
public String getDocumentation(EObject o) {
if (o instanceof Greeting) {
return "This is a nice Greeting";
}
return null;
}
}
/*
* generated by Xtext
*/
package org.xtext.example.mydsl.ui;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider;
/**
* Use this class to register components to be used within the IDE.
*/
public class MyDslUiModule extends org.xtext.example.mydsl.ui.AbstractMyDslUiModule {
public MyDslUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
public Class<? extends IEObjectHoverProvider> bindIEObjectHoverProvider() {
return MyDslEObjectHoverProvider.class;
}
public Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProviderr() {
return MyDslEObjectDocumentationProvider.class;
}
}
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Re: XText 2.0 --- Hover Documentation [message #696770 is a reply to message #696769] |
Thu, 14 July 2011 19:40 |
|
Hi,
i guess this is cause the hovers by default are not shown for Keywords.
you may have to customize org.eclipse.xtext.resource.DefaultLocationInFileProvider too
/*
* generated by Xtext
*/
package org.xtext.example.mydsl;
import org.eclipse.xtext.resource.ILocationInFileProvider;
/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
*/
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
@Override
public Class<? extends ILocationInFileProvider> bindILocationInFileProvider() {
return MyDslLocationInFileProvider.class;
}
}
package org.xtext.example.mydsl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.resource.DefaultLocationInFileProvider;
import org.eclipse.xtext.util.ITextRegion;
public class MyDslLocationInFileProvider extends DefaultLocationInFileProvider {
@Override
public ITextRegion getSignificantTextRegion(EObject obj) {
return super.getFullTextRegion(obj);
}
}
or you customize org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int)
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Thu, 14 July 2011 19:58] Report message to a moderator
|
|
|
|
Re: XText 2.0 --- Hover Documentation [message #696977 is a reply to message #696783] |
Fri, 15 July 2011 08:46 |
Caner Messages: 98 Registered: July 2011 |
Member |
|
|
Hi Christian
as you know I have this grammar ;
Librarymodel:
(elements+=NonEmptyline)*;
NonEmptyline:
writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;
Words hidden (): ID (WS ID)* ;
I want hovering for NonEmptyLine and i just change the if loop as follows
public class MyDslEObjectDocumentationProvider implements IEObjectDocumentationProvider {
@Override
public String getDocumentation(EObject o) {
if (o instanceof NonEmpityLine) {
return "This is a NonEmpityLine";
}
return null;
}
as well as here too;
protected String getFirstLine(EObject o) {
if (o instanceof NonEmpityLine) {
return "Damn good coding: " ;
}
return super.getFirstLine(o);
}
Consequent ; When I point on the following line, Hovering doesnt show up for my NonEmptyline in somthng.mydsl;
Writer1:Book1:1233:213
Is it because ; NonEmptyline consists of other parameters which are hidden?
Second; I want to implement hovers for each field (writer,selected writer's book,selected book's isbn..etc)in my NOnEmptyLine,
which have been divided with ':'/',' for user,so user will know which type has to be typed,
while user is typing code, is there anyway to display information ?
[Updated on: Fri, 15 July 2011 08:46] Report message to a moderator
|
|
|
|
Re: XText 2.0 --- Hover Documentation [message #697071 is a reply to message #696979] |
Fri, 15 July 2011 13:10 |
Caner Messages: 98 Registered: July 2011 |
Member |
|
|
Thanks Christian
I guesss , I need an other way to define hovering for hidden or terminal roules
They are different than normal type hovers, if we consider my grammer
NonEmpityLine consists of hidden Words and some in
I tried to do some thing like this
rammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
LCModel:
(types+=Type)*;
Type:
Rule1|Rule2|Rule3|Greeting;
Rule1:
'$' name=Words
;
Rule2:
'rule2' name=Words2
;
Words2 :
ID (WS ID)*
;
Rule3:
'rule3' name=ID '!';
NonEmptyline:
writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;
Words hidden ():
ID (WS ID)*
;
and to distinguish which is called
public class MyDslEObjectHoverProvider extends DefaultEObjectHoverProvider {
LeafNode leaf;
StringBuffer result = new StringBuffer();
@Override
protected String getFirstLine(EObject o) {
}else if (o instanceof Rule1) {
return " DDD RULE1 ";
}
else if(o instanceof Rule2){
return " DDD Rule2";
}
else if (o instanceof Rule3) {
return "DDD This is Rule3 ";
} else if (o instanceof NonEmptyline) {
return "DDD This is Rule3 ";
}
return super.getFirstLine(o);
I get hover for rule1, rule 2 ,rule 3 but not for NonEmptyline
Should I override the getHoverInfo for hidden roles?
caner
[Updated on: Fri, 15 July 2011 13:13] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: XText 2.0 --- Hover Documentation [message #697475 is a reply to message #697449] |
Sat, 16 July 2011 22:43 |
Caner Messages: 98 Registered: July 2011 |
Member |
|
|
Hi
Tons of Thanks for your explanation, you are really helpful.
This is working really fine, and I guess I can use it for my dsl comment rule which is same with terminal single line comment rule,
On the other hand, if I have a keyword 'NEL' for nonemptyline as follows, when i point the NEL it works as well.
LibraryModel:
(types+=Type)*;
Type:
NonEmptyline;
NonEmptyline:
'NEL' writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;
Words hidden ():
ID (WS ID)*
;
However, my emptyline has not a keyword as follows,
NonEmptyline:
writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;
Words hidden ():
ID (WS ID)*
;
Which means, i have to point on writer or another parameter for display a hover.
I tried to define onemore qualifiedname for writer, But Xtext didnt generate interface for writer and other book, isbn and pagenumbers.
it didnt work, i need to define somethng for writer parameter which has not a key word and part of the nonemptyline and as well as for other parameters. is there anyway to do this kind with Xtext 2.0 ?
BR Caner
[Updated on: Sun, 17 July 2011 09:20] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08551 seconds