Marco Naddeo Messages: 47 Registered: November 2012
Member
Hi
I have defined MyDSLScopeProvider to suitably restrict the scope of cross-references in my language. Now I correctly obtain an error if I try to cross-reference an element of the right type, but outside of the defined scope.
On the other hand, using the content assist functionality by pressing CTRL+SPACE in my Xtext editor, I still obtain a list of all elements of the type specified in the cross-reference definition in the grammar, that is a list which is still unfiltered by scoping.
Scoping and content assist are independent from each other?
As far as I understand, I have to override in MyDSLProposalProvider the appropriate methods from AbstractMyDSLProposalProvider, but how? Is there an example of that?
Ian McDevitt Messages: 27 Registered: December 2012
Junior Member
I've been looking at this too recently and have found myself spending a lot of time between my overridden ScopeProvider and ProposalProvider classes.
I inherited from the XbaseProposalProvider and implemented a few completeXYZ() methods where XYZ is one of my ParserRules that I want completion proposals for.
I had found a few mentions about it to let me know it should be achievable but not enough in the way of examples to let me undestand it and get it working without a lot of trial, error and debugging.
Some attempts give nothing while others include eveything on the planet.
Basically for the Xbase option you choose the completeXYZ method you need and write your custom proposal provider to query your custom scope for the prefix, if any, supplied in the context assist parameter. I expect in your case the default proposal provider would be using the default scope provider and not yours. Even though I had specified my classes in the runtime module, there were still code in the super class that was calling other super class methods and so I had to start overriding more methods to get them to work.
I'd be interested in any other responses with worked examples too.
Ian McDevitt Messages: 27 Registered: December 2012
Junior Member
Proposals have a dependency on scoping. It may be the proposer isn't calling your scoping function, I found it calling its other member functions which I also had to overide - some debugging or logging may tell.
Or does your custom scope have an outer parent scope which is being included by default. Your scope may need to be an isolated list of items with no outer scope.
I think the reason it includes outer scopes by default is to allow you to show what may be possible under other situations (a bit like showing a greyed out button rather than no button at all). So you may see all methods even private ones which you can't call. If you don't like that then you supply filtering of your choice, but I know what you mean - it seems odd to have only 3 items in your scope and get 30 poposed to you from the outer scope.
I'm planning to rework mine to get the proposals and scoping more closely aligned (i.e. get it to work). Scoping first, then proposals.
Thanks for that link to the other example it looks straight forward.
P.S: i think the problem is often xtexts lazy object creation
(affects you if the cross reference i the first "real" thing (first assignment) in the rule for the object
XXX: "keyword" yyy=[KKK]
then you have 2 possibilities to workaround this
(1) use scope_XXX_yyy(ParentObject ctx, Ereference ref) instead of scope_XXX_yyy(XXX ctx, Ereference ref)
(2) try to use a unassigned action to force xtext to create the object eager
XXX: {XXX}"keyword" yyy=[KKK]
Marco Naddeo Messages: 47 Registered: November 2012
Member
Another question: now I obtain my content proposal correctly scoped and triggered on dot typing, but between the various proposals I also get the dot itself, and I don't understand why: the grammar is not expected that there may be two points below each other, and in fact if I select the dot from the drop-down menu, anything is added to the code, so that I do not understand the usefulness of this proposal.
generally speaking, content assist shows all alternatives possible at the current position, taking into account a potential prefix. The proposal may be identical to the prefix. This will the case for your dot-question.