[xtext] content assist for first token assignments [message #43745] |
Mon, 11 May 2009 14:46 |
Eclipse User |
|
|
|
Originally posted by: knut.wannheden.gmail.com
Hi all,
Given a grammar like this:
Model :
"model" package=[ecore::EPackage|STRING] "{"
classes+=Class ( "," classes+=Class )*
"}"
;
Class :
class=[ecore::EClass] "{"
// snip
"}"
;
And a document like this:
model "http://foo/" {
Foo {}
// <-- cursor here
}
The content assist, when invoked right before the comment token, first
tries to lookup a Class object to assign to the "classes" feature. Next
(if the first step fails, I believe) it tries to lookup an EClass object
to assign to the "class" feature. In this second step the scope provider
is given the Model object as context object (there is no Class object
yet!) and the "class" feature as the context reference.
Simple cases like this are easy to solve: The scope provider can simply
define the EClass scope at the Model level.
But how should this work when the cursor position within the containing
element is important? As in Sven's final example here
http://blog.efftinge.de/2009/01/xtext-scopes-and-emf-index.h tml. If the
Java content assist were invoked inbetween the "innerScopeVar" and
"field" declarations it obviously shouldn't (and indeed won't) propose
"field". Should the content assist in this case temporarily create and
attach the required context object?
Cheers,
--knut
|
|
|
Re: [xtext] content assist for first token assignments [message #43803 is a reply to message #43745] |
Wed, 13 May 2009 12:56 |
Sven Efftinge Messages: 1823 Registered: July 2009 |
Senior Member |
|
|
Hi Knut,
good point. I discussed this with Sebastian last week and we decided to
leave it like it is for now. But that time we havn't thought of the Java
scenario you're referring to...
Synthetically changing the model would help, but can have all kinds of
complex side-effects (we're in EMF). So although I'm sure we can make it
work and this will greatly simplify the contract of IScopeProvider, it
seems a bit magic and therefore complicated to understand for others.
We'll have to think about it. Maybe you want to open a bug for that, so
we can share our thoughts there.
Cheers,
Sven
Knut Wannheden schrieb:
> Hi all,
>
> Given a grammar like this:
>
> Model :
> "model" package=[ecore::EPackage|STRING] "{"
> classes+=Class ( "," classes+=Class )*
> "}"
> ;
>
> Class :
> class=[ecore::EClass] "{"
> // snip
> "}"
> ;
>
> And a document like this:
>
> model "http://foo/" {
> Foo {}
> // <-- cursor here
> }
>
> The content assist, when invoked right before the comment token, first
> tries to lookup a Class object to assign to the "classes" feature. Next
> (if the first step fails, I believe) it tries to lookup an EClass object
> to assign to the "class" feature. In this second step the scope provider
> is given the Model object as context object (there is no Class object
> yet!) and the "class" feature as the context reference.
>
> Simple cases like this are easy to solve: The scope provider can simply
> define the EClass scope at the Model level.
>
> But how should this work when the cursor position within the containing
> element is important? As in Sven's final example here
> http://blog.efftinge.de/2009/01/xtext-scopes-and-emf-index.h tml. If the
> Java content assist were invoked inbetween the "innerScopeVar" and
> "field" declarations it obviously shouldn't (and indeed won't) propose
> "field". Should the content assist in this case temporarily create and
> attach the required context object?
>
> Cheers,
>
> --knut
|
|
|
Powered by
FUDForum. Page generated in 0.03548 seconds