A Go to Symbol Contributor helps the user to navigate to any PSI element by its name.
Define a Helper Method for Generated PSI Elements
To specify what a PSI element looks like in the Navigate | Symbol popup window, Structure tool window, or other components, it should implement getPresentation(). This method gets defined in the utility class SimplePsiImplUtil, and the parser and PSI classes must be regenerated. Add the following method to SimplePsiImplUtil:
public static ItemPresentation getPresentation(final SimpleProperty element) {
return new ItemPresentation() {
@Nullable
@Override
public String getPresentableText() {
return element.getKey();
}
@Nullable
@Override
public String getLocationString() {
PsiFile containingFile = element.getContainingFile();
return containingFile == null ? null : containingFile.getName();
}
@Override
public Icon getIcon(boolean unused) {
return element.getIcon(0);
}
};
}
In addition, to provide an icon for the displayed items, extend IconProvider and register it in com.intellij.iconProvider extension point. See SimplePropertyIconProvider:
final class SimplePropertyIconProvider extends IconProvider {
@Override
public @Nullable Icon getIcon(@NotNull PsiElement element, int flags) {
return element instanceof SimpleProperty ? SimpleIcons.FILE : null;
}
}
Update Grammar and Regenerate the Parser
Now add the SimplePsiImplUtil.getPresentation() to the property methods definition in the Simple.bnf grammar file by replacing the property definition with the lines below. Don't forget to regenerate the parser after updating the file! Right-click on the Simple.bnf file and select Generate Parser Code.
The SimpleChooseByNameContributor implementation is registered with the IntelliJ Platform in the plugin configuration file using the com.intellij.gotoSymbolContributor extension point.