Kotlin FindUsages not working for Primary constructor for custom reference

I am writing a plugin for Handlebars support, where I am trying to connect a Handlebars file (.hbs) with a corresponding Kotlin class. The below is:

My Handlebars file:

{{#each animals}}
Working = {{animalNames}}
Not Working = {{animalName}}

My Kotlin file:

class Jungle {
var animals: List<Animal>? = null

class Animal(var animalName: String){
var animalNames: String = ""

I have established a reference between each fields. So from .hbs file, ctrl clicking on any of the fields takes me to the respective Kotlin field.

But when I try the vice versa, i.e,  when I do FindUsages for `animals` and `animalNames` it shows me the usages in the Handlebars file. But for `animalName` it doesn't show any usages.

What am I missing here? I tried multiple scenarios, and it seems that the fields in primary constructor doesn't show usages. How do is fix this, so that `animalName` behaves the same way as `animalNames` ?

1 comment
Comment actions Permalink

I found the problem. It was because I didn't resolve to the proper PsiElement.

Previously I just returned `PsiField` in my resolve() method.

But now I modified the code to return the proper PsiElement instead of `PsiField` all the time, like this:

override fun resolve(): PsiElement? {
val psiField = HbElementResolver(psiClass).resolve(element)
if (psiField is KtLightMember<*>) {
return psiElement.lightMemberOrigin?.originalElement
return psiField

Now everything is working as expected.


Please sign in to leave a comment.