Problem with content assist and scoping [message #684923] |
Thu, 16 June 2011 13:35 |
Romain Aïssat Messages: 16 Registered: June 2011 |
Junior Member |
|
|
Hi,
Here is my grammar, allowing to define integers (with '+' as the only operator, to simplify...) :
Model:
'int' declarations += IntDeclaration (',' declarations += IntDeclaration)* ';' ;
IntDeclaration :
alias = IntAlias '=' exp = IntExpression;
IntAlias :
name = ID;
IntExpression returns IntExpression :
TerminalIntExpression ({Add.left = current} '+' right = TerminalIntExpression)*;
TerminalIntExpression returns IntExpression :
Integer | IntReference | '(' IntExpression ')';
Integer :
val = INT;
IntReference :
referred = [IntAlias];
Furthermore, I defined a template named "Add" (with IntExpression as context) :
${left:CrossReference('IntReference.referred')} + ${right:CrossReference('IntReference.referred')}
I've also configured scoping to allow only IntAliases in the current resource, meaning that if my model is :
int a = 1, b = 2, c = (*);
- where (*) stands for Ctrl-Space - and I choose the "Add" template in the pop-up, proposals for both left and right terms are a, b and c.
Here is what I want to do : I'd like to remove (in this particular case) the c proposal : for example "int c = 2 + c;" has no sense in my DSL (constants are defined once and for all and can't be modified).
My problem is that i'm a bit confused with the way to achieve this. I extended the AbstractDeclarativeProvider with a method that computes the right scope (it's signature is : public IScope scope_IntDeclaration_exp(IntDeclaration d, EReference ref) ) but this alone isn't enough.
When I'm in the same situation as before (choosing the Add template), the name of the current declaration still appear in the pop-up (and if I choose it, i've got an error saying that the reference couldn't be resolved, so i guess scoping is ok...).
I looked at proposal provider to find a way to make it work with respect to scoping but in vain... Any advice would be really appreciated!
Thanks in advance,
Romain
PS : sorry for bad english, didn't practice for a while now...
|
|
|
Re: Problem with content assist and scoping [message #685108 is a reply to message #684923] |
Thu, 16 June 2011 20:40 |
|
Hi,
i am not quite sure that your scoping method makes sense.
its generally
public IScope scope_Container_refernecename(EObject context, EReference ref)
so shouldn't it be
public IScope scope_IntReference_referred(IntReference r, EReference ref)
and to cover the other possible contexts something like
public IScope scope_IntReference_referred(TerminalIntExpression r, EReference ref)
public IScope scope_IntReference_referred(IntExpression e, EReference ref)
public IScope scope_IntReference_referred(IntDeclaration r, EReference ref)
i'd juste debug the getscope method of your scope provider and see whats in the context in different situations.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.03152 seconds