Home » Modeling » TMF (Xtext) » Xtext 2.4.2: how to have content assist together with validation(xtext, scope restriction, content assist, code completion, Ctrl + Space, validation, proposal provider, )
Xtext 2.4.2: how to have content assist together with validation [message #1066581] |
Wed, 03 July 2013 09:25 |
Kent To Messages: 4 Registered: July 2013 |
Junior Member |
|
|
Hi all,
I've searched and read hexas of threads about content assist using xtext. But when I want to go deeper I got stuck in advices on how to do it using earlier versions of xtext.
For a grammar I am able to do validation on any element of the AST, now I would like to give the users of my text editor a new level of friendliness: content assist, or in other words scope restriction
I) What I have learned
From [1] I learn that to have scope restriction there are two ways
- Explicit restriction
- Implicit restriction
Explicit restriction is to use a filter to discard the elements falling out of scope. To be precise you would override methods of an AbstractDeclarativeScopeProvider
Implicit restriction is to specify, by using a filter, how the parser would accept a proposal before hand, and to validate that proposal afterwards. To be precise you would override methods of an Abstract[your grammar name]ProposalProvider and an Abstract[your grammar name]JavaValidator
[1] suggests people to use the Implicit restriction, because of the ability to provide useful error messages after the user has typed something.
II) What I want to do
In the example of [1], when we want to override a method
complete[ElementName]_[FeatureName]()
there is only a possibility to call lookupCrossReference(), but in my own grammar I only see the calls to completeRuleCall(), for example
public void complete[ElementName]_[FeatureName](EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
My question is
- What do the parameters {model, assignment, context, acceptor} mean ?
- If I have a filter on an element of the model tree (AST), for example
boolean filter(EObject anElement)
How can I insert that filter into the body of
complete[ElementName]_[FeatureName]()
?
|
|
| | | | |
Re: Xtext 2.4.2: how to have content assist together with validation [message #1066745 is a reply to message #1066706] |
Thu, 04 July 2013 08:21 |
Kent To Messages: 4 Registered: July 2013 |
Junior Member |
|
|
Hi Christian,
Many thanks for your time,
Your solution works for this toy example. I'm learning xtext and start with this toy example.
I'd like to extend the scope restriction to be more complicated, this new example does not work, and I would like to receive your advice. Also if you could provide a solution using ProposalProvider, that would be great.
class DomainModelProposalProvider extends AbstractDomainModelProposalProvider {
}
Many thanks.
Scope restriction rule:
"An entity A would only extend another entity B if the first letter of A's name == the first letter of B's name"
Model source (runtime) example:
package a.new.package {
entity firstBaseEntity{}
entity secondBaseEntity{}
entity thirdBaseEntity{}
entity secondDerivedEntity extends [Ctrl+Space goes here, only secondBaseEntity should appear] {
}
}
Here is how I try in xtend
public class DomainModelScopeProvider extends AbstractDeclarativeScopeProvider {
def IScope scope_Entity_SuperType_name(Entity entity, EReference ref){
new FilteringScope(
delegateGetScope(entity, ref),
[
ieod | entity.name.startsWith(ieod.name.toString.substring(0, 1))
]
)
}
}
Why does it not work ?
- I think that ieod refers to the object whose scope is being considered by that scope_Entity_SuperType_name() function. In this example is the entity name after the "extends" keyword.
- The "entity" parameter should refer to the entity before the "extends" keyword. Therefore the scope function should have the "SuperType" in its name.
But something is still missing ?
[Updated on: Thu, 04 July 2013 08:22] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Fri Mar 29 00:55:25 GMT 2024
Powered by FUDForum. Page generated in 0.04056 seconds
|