How to write custom autocompletion in Xtext?

半世苍凉 提交于 2019-12-22 10:33:02

问题


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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!