IntelliJ Platform Plugin SDK Help

9. Completion Contributor

Custom languages provide code completion using one of two approaches: Contributor and Reference-based (see 10. Reference Contributor) completion.

Define a Completion Contributor

For this tutorial, the simple_language_plugin provides custom completion for values in Simple Language property files. Create SimpleCompletionContributor by subclassing CompletionContributor. This rudimentary completion contributor always adds "Hello" to the completion variants result set, regardless of context:

public class SimpleCompletionContributor extends CompletionContributor { public SimpleCompletionContributor() { extend(CompletionType.BASIC, PlatformPatterns.psiElement(SimpleTypes.VALUE), new CompletionProvider<>() { public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) { resultSet.addElement(LookupElementBuilder.create("Hello")); } } ); } }

Register the Completion Contributor

The SimpleCompletionContributor implementation is registered in the plugin configuration file using the com.intellij.completion.contributor extension point and specifying language="Simple".

<extensions defaultExtensionNs="com.intellij"> <completion.contributor language="Simple" implementationClass="org.intellij.sdk.language.SimpleCompletionContributor"/> </extensions>

Run the Project

Run the plugin by using the Gradle runIde task.

Open the test.simple file. Erase the property "English" and invoke Basic Code Completion. The choice "Hello" is shown:

Completion
Last modified: 27 February 2023