问题
I just can't find anything about this, only sources about writing a custom autocompletion proposal, which is not what I want (or is it)?
Syntax
We can use the example syntax for this:
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
Problem
Now, when the user creates a new instance of the syntax, he has to
- Write "Hello" (and could complete it)
- Has to write a space
- Can now autocomplete the "Name=ID"
But this is not what I want.
What I want
- When the user completes "Hello", I want the rest to be filled with a default example, like: "Hello World"
Is this possible? Are there some source for this? Where is an entry point for looking into this? Can I archive this with just printing some text after the completion or do I need to fill the modell with an example (and where can I do this)?
回答1:
have a look at the section "templates proposals" in the docs. alternatively override complete_Greeting
in the proposal provider
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
override complete_Greeting(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
acceptor.accept(createCompletionProposal("Hello World!",context))
super.complete_Greeting(model, ruleCall, context, acceptor)
}
}
来源:https://stackoverflow.com/questions/31423535/how-to-write-custom-autocompletion-in-xtext