How to write custom autocompletion in Xtext?

2019-05-10 05:39发布

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

  1. Write "Hello" (and could complete it)
  2. Has to write a space
  3. Can now autocomplete the "Name=ID"

But this is not what I want.

What I want

  1. 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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-10 06:13

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)
    }

}
查看更多
登录 后发表回答