PsiReference () { if (getParent() instanceof RncInclude) { final TextRange range = TextRange.from(0, getNameNode().getTextLength()); return new PsiReferenceBase<RncDefine>(this, range, true) { @Override public PsiElement resolve() { return RncDefineImpl.this; } @Override public Object @NotNull [] getVariants() { final RncInclude parent = (RncInclude)getParent(); final RncFile referencedFile = parent.getReferencedFile(); if (referencedFile == null) { return EMPTY_ARRAY; } final RncGrammar grammar = referencedFile.getGrammar(); if (grammar == null) { return EMPTY_ARRAY; } final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar); if (map != null) { return map.keySet().toArray(); } return EMPTY_ARRAY; } }; } return super.getReference(); }