scoping function is called too late when code completion is expected [message #708065] |
Tue, 02 August 2011 12:14 |
Michal S Messages: 74 Registered: July 2011 |
Member |
|
|
Hello,
I have following problem with scoping:
my grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
entities += Entity*;
Entity:
EntityA|EntityB
;
EntityA:
'A' name=ID '{'
valuesA += Value*
'}'
;
Value:
name=ID '=' value=INT
;
EntityB:
'B' name=EntityARef '{'
valuesB += ValueRef*
'}'
;
ValueRef:
name = [Value]
;
EntityARef:
name = [EntityA]
;
my model:
A aa{
a = 1
b = 2
}
A bb{
x = 1
y = 2
}
B bb {
x
}
scoping function:
IScope scope_ValueRef_name(ValueRef vr, EReference ref){
System.out.println("I am here!");
return Scopes.scopeFor(((EntityB) vr.eContainer()).getName().getName().getValuesA());
}
and in workflow I enabled
fragment = exporting.SimpleNamesFragment {}
My problem is: when I am writing in model EntityB -> valuesB, I need the editor offers me all Value-s, but only those defined in specified EntityA.
If I write in this point value "b", it undrelines it - that is perfect (my scoping function is called). Unfortunatelly, I need it called when the completion options are shown, not only after writing.
If I change in my grammar ValueRef (e.g.):
ValueRef:
'.' name = [Value]
;
then after writing "." editor calls my scoping function and it offers what I need, but I don't want the dot there. From context is clear, that the ValueRef name has to be written in that place - as you see from the grammar.
How can I make the code completion working?
Thank you.
Michal
|
|
|
|
|
|
|
Re: scoping function is called too late when code completion is expected [message #713857 is a reply to message #713614] |
Tue, 09 August 2011 08:11 |
Mark Christiaens Messages: 63 Registered: October 2010 |
Member |
|
|
Thanks Sebastian, I think I understand.
Knowing this, it's unclear to me though how to "do the right thing" to fully support good content assist based on scoping. I mean, so far when I am writing a IScopeProvider, I have been reasoning about which cross-references could need to be resolved in which contexts after a parse of the model. But now, to also make content assist happy, I have to widen the scoping net substantially. It's a big mental burden to figure out what the possible contexts are to resolve cross references.
Would it not be more appropriate to do content assist a bit differently. In your example, would it not be possible to create all the different contexts prior to presenting them to scoping? In this case it would mean creating two variants of the model:
- Resource -> Model -> Foo (with empty cross reference)
- Resource -> Model -> Bar (with empty cross reference)
and then query scoping for valid candidates for Foo.xref in the context of the Foo EObject in model (1) followed by a query for valid candidates of Bar.xref in the context the Bar EObject in model (2)?
I guess that that would require locking the model, modifying it without triggering any listeners, reverting everything and then unlocking?
---
Mark Christiaens
Discover the Future of VHDL Design
Go to www.sigasi.com
|
|
|
Re: scoping function is called too late when code completion is expected [message #713867 is a reply to message #713857] |
Tue, 09 August 2011 08:47 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Mark,
please follow the brief discussion here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=276619
It would be hardly possible to do this in a reasonable way from a
performance point of view and with regards to the complexity of the
implementation. For the rather complex grammar of Xbase and Xtend, we
customized the proposal provider to directly invoke methods on the scope
provider that take more context information into account. With a
reasonable amount of unit tests, it was possible to provide the
necessary information for helpful content assist.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
On 09.08.11 10:11, Mark Christiaens wrote:
> Thanks Sebastian, I think I understand.
> Knowing this, it's unclear to me though how to "do the right thing" to
> fully support good content assist based on scoping. I mean, so far when
> I am writing a IScopeProvider, I have been reasoning about which
> cross-references could need to be resolved in which contexts after a
> parse of the model. But now, to also make content assist happy, I have
> to widen the scoping net substantially. It's a big mental burden to
> figure out what the possible contexts are to resolve cross references.
>
> Would it not be more appropriate to do content assist a bit differently.
> In your example, would it not be possible to create all the different
> contexts prior to presenting them to scoping? In this case it would mean
> creating two variants of the model:
>
> Resource -> Model -> Foo (with empty cross reference)
> Resource -> Model -> Bar (with empty cross reference)
>
> and then query scoping for valid candidates for Foo.xref in the context
> of the Foo EObject in model (1) followed by a query for valid candidates
> of Bar.xref in the context the Bar EObject in model (2)?
>
> I guess that that would require locking the model, modifying it without
> triggering any listeners, reverting everything and then unlocking?
> ---
> Mark Christiaens
> Discover the Future of VHDL Design
> Go to http://www.sigasi.com
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03201 seconds