【问题标题】:IntelliJ plugin autocompletionIntelliJ 插件自动完成
【发布时间】:2015-04-17 08:07:16
【问题描述】:

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

这是我的代码:

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

我想handleInsert 可以帮助我,但找不到如何使用它

【问题讨论】:

    标签: plugins intellij-idea autocomplete intellij-plugin


    【解决方案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"/>
    

    当您的贡献者首先被调用时,您还可以使用@peter-gromov 建议的CompletionResultSet::runRemainingContributes()PrioritizedLookupElement::withPriority() 编写代码来决定如何定位以下建议或完全排除其中一些建议:

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

    【讨论】:

      【解决方案2】:

      您可以尝试通过 PrioritizedLookupElement#withPriority 为查找元素指定明确的高优先级。

      【讨论】:

      • 我只是尝试,但位置相同,它们根本不会移动 PrioritizedLookupElement.withPriority(lookup, LookupValueWithPriority.HIGHER) 或 HIGH
      • 那么需要更多信息。例如,由 DumpLookupElementWeights 操作打印的项目权重(查找列表打开时 ctrl/command+alt+shift+w)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      • 2010-10-29
      • 2011-06-06
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      相关资源
      最近更新 更多