scoping function is called too late when code completion is expected [message #708065] |
Tue, 02 August 2011 08:14  |
Eclipse User |
|
|
|
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 04:11   |
Eclipse User |
|
|
|
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 04:47   |
Eclipse User |
|
|
|
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
>
|
|
|
|
Re: scoping function is called too late when code completion is expected [message #713991 is a reply to message #713913] |
Tue, 09 August 2011 09:34  |
Eclipse User |
|
|
|
Hi Mark,
you will already notice a delay when you invoke content assist directly
after a typing sequence - sometimes the parser is even too slow to
notify the infrastructure about ongoing work, but that is a nasty bug :-( .
The produced model may depended significantly on the inserted token,
e.g. an expression tree will look totally different depending on the
following input element. It is often not only a single other alternative
but actually a lot of them that have to be produced to pass them to the
proposal provider - and often they would require resolved cross
references to provide meaningful suggestions. Considering the impact on
the performance / usability and the required complexity in the
implementation it is simply not worth the effort (at least for now). It
is usually much easier to customize the proposal provider to achieve the
same results.
The model cannot be modified on the fly since there may be listeners
installed that have to be notified if something changes (e.g. the cache)
while others may be surprised if the model is changed during a read-only
operation such as computing the proposals. That's why we would have to
copy basically the complete resource set (the 'replaced' elements in the
model may be referenced by other resources which in turn are used to
compute the proposals ...).
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
On 09.08.11 13:17, Mark Christiaens wrote:
> I can understand that it would be complex but performance wise, I don't
> quite understand it. Isn't maintaining/updating the model while the user
> is typing as expensive as modifying the model on-the-fly to generate
> content assistance?
> ---
> Mark Christiaens
> Discover the Future of VHDL Design
> Go to http://www.sigasi.com
|
|
|
Powered by
FUDForum. Page generated in 0.04364 seconds