如何在Xtext中编写自定义自动完成功能? [英] How to write custom autocompletion in Xtext?
问题描述
我只是找不到任何有关此的东西,只能找到编写自定义自动完成建议的资源,这不是我想要的(还是它)?
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)?
语法
我们可以使用示例语法:
We can use the example syntax for this:
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
问题
现在,当用户创建语法的新实例时,他必须
Now, when the user creates a new instance of the syntax, he has to
- 写你好"(可以完成)
- 要写一个空格
- 现在可以自动完成名称= ID"
但这不是我想要的.
我想要的
- 当用户完成"Hello"后,我希望其余部分都填充一个默认示例,例如:"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)?
推荐答案
查看文档中的模板提案"部分.或者在提案提供者
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)
}
}
这篇关于如何在Xtext中编写自定义自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!