IntelliJ Platform Plugin SDK Help

11. Find Usages Provider

A FindUsagesProvider uses a word scanner to build an index of words in every file. A scanner breaks the text into words and defines the context for each word.

Define a Find Usages Provider

The SimpleFindUsagesProvider implements FindUsagesProvider. Using the DefaultWordsScanner ensures the scanner implementation is thread-safe. See the comments in FindUsagesProvider for more information.

final class SimpleFindUsagesProvider implements FindUsagesProvider { @Nullable @Override public WordsScanner getWordsScanner() { return new DefaultWordsScanner(new SimpleLexerAdapter(), SimpleTokenSets.IDENTIFIERS, SimpleTokenSets.COMMENTS, TokenSet.EMPTY); } @Override public boolean canFindUsagesFor(@NotNull PsiElement psiElement) { return psiElement instanceof PsiNamedElement; } @Nullable @Override public String getHelpId(@NotNull PsiElement psiElement) { return null; } @NotNull @Override public String getType(@NotNull PsiElement element) { if (element instanceof SimpleProperty) { return "simple property"; } return ""; } @NotNull @Override public String getDescriptiveName(@NotNull PsiElement element) { if (element instanceof SimpleProperty) { return ((SimpleProperty) element).getKey(); } return ""; } @NotNull @Override public String getNodeText(@NotNull PsiElement element, boolean useFullName) { if (element instanceof SimpleProperty) { return ((SimpleProperty) element).getKey() + SimpleAnnotator.SIMPLE_SEPARATOR_STR + ((SimpleProperty) element).getValue(); } return ""; } }

Register the Find Usages Provider

The SimpleFindUsagesProvider implementation is registered with the IntelliJ Platform in the plugin configuration file using the com.intellij.lang.findUsagesProvider extension point.

<extensions defaultExtensionNs="com.intellij"> <lang.findUsagesProvider language="Simple" implementationClass="org.intellij.sdk.language.SimpleFindUsagesProvider"/> </extensions>

Run the Project

Run the plugin by using the Gradle runIde task.

The IDE now supports Find Usages for any property with a reference:

Find Usages
Last modified: 27 February 2023