IntelliJ插件自动补全

5
我是一名能够翻译文本的助手。以下是需要翻译的内容:

我正在制作一个支持nodeJS框架的IntelliJ插件。 我正在尝试实现自动完成功能,但不知道如何将自动完成位置设置在列表顶部。首先我有其他的自动完成(mozilla等等)。

这是我的代码:

LookupElementBuilder
                .create(completionString)
                .withBoldness(true)
                .withCaseSensitivity(false)
                .withIcon(SailsJSIcons.SailsJS)
                .withPresentableText("\t\t\t" + item)
                .withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE);

我想使用handleInsert,但是不知道如何使用它。

2个回答

1
你可以在plugin.xml中的completion.contributor上设置order="first"。这样做似乎会使你的贡献者比其他来源的贡献者先被调用,从而使你的建议排在第一位。
<extensions defaultExtensionNs="com.intellij">
    <completion.contributor order="first" language="PHP" implementationClass="org.klesun.deep_assoc_completion.entry.DeepKeysCbtr"/>

当首先调用你的贡献者时,你也可以编写代码来决定如何定位后续建议或使用CompletionResultSet :: runRemainingContributes()PrioritizedLookupElement :: withPriority()来排除其中一些,@peter-gromov提出了这个建议。
protected void addCompletions(CompletionParameters parameters, ProcessingContext processingContext, CompletionResultSet result) 
{
    // ... some of your code here ...

    result.runRemainingContributors(parameters, otherSourceResult -> {
        // 2000 is any number - make it smaller than on your suggestion to position this suggestion lower
        result.addElement(PrioritizedLookupElement.withPriority(otherSourceResult.getLookupElement(), 2000));
    });
}

0

你可以尝试使用 PrioritizedLookupElement#withPriority 方法为查找元素指定高优先级。


1
我刚试过了,但使用PrioritizedLookupElement.withPriority(lookup, LookupValueWithPriority.HIGHER)或HIGH时,位置仍然相同,它们根本没有移动。 - jaumard
1
需要更多的信息。例如,使用DumpLookupElementWeights操作(在查找列表打开时按ctrl/command+alt+shift+w)打印的项目权重。 - Peter Gromov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接