PsiReferenceBase#PsiReferenceBase(T, TextRange), has there been any change in its core logic from 2022.3 to 2024.3?

I’m working on a custom language plugin, and reference resolve exhibits different behavior in different versions of the idea

As shown below, in idea 2022.3, the references are correctly resolved and also correctly highlighted

But in the IDEA of 2024.3, although the references are also correctly resolved, all references with targets are not correctly highlighted

Only references that are resolved to null are correctly highlighted, but once it has a resolution target, it is not highlighted either

My plugin was developed based on the antlr syntax definition(But I think for this issue antlr has no impact… After all, on the 2022.3 version of the IDEA, the functionality is perfectly fine), here is the code related to reference resolve:

import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReferenceBase
import net.fallingangel.jimmerdto.psi.mixin.DTONamedElement

class DTOReference(private val element: DTONamedElement, textRange: TextRange) : PsiReferenceBase<PsiElement>(element, textRange) {
    override fun resolve() = element.resolve()

    override fun handleElementRename(newElementName: String): PsiElement {
        return element.setName(newElementName)
    }
}
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNameIdentifierOwner

interface DTONamedElement : DTOElement, PsiNameIdentifierOwner {
    fun resolve(): PsiElement?
}
import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement
import net.fallingangel.jimmerdto.psi.mixin.DTONamedElement
import net.fallingangel.jimmerdto.refenerce.DTOReference
import org.antlr.intellij.adaptor.psi.ANTLRPsiNode

abstract class DTONamedElementImpl(node: ASTNode) : ANTLRPsiNode(node), DTONamedElement {
    override fun getName() = nameIdentifier?.text

    override fun setName(name: String): DTONamedElement {
        newNameNode(name)?.let { node.treeParent.replaceChild(node, it) }
        return this
    }

    protected open fun newNameNode(name: String): ASTNode? = null

    override fun getReference() = DTOReference(this, firstChild.textRangeInParent)

    override fun resolve(): PsiElement? {
        return null
    }
}
import com.intellij.lang.ASTNode
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.search.ProjectScope
import net.fallingangel.jimmerdto.psi.element.DTODtoName
import net.fallingangel.jimmerdto.psi.element.DTOVisitor
import net.fallingangel.jimmerdto.psi.element.createDTOName
import net.fallingangel.jimmerdto.psi.mixin.impl.DTONamedElementImpl
import net.fallingangel.jimmerdto.util.file
import net.fallingangel.jimmerdto.util.findChild

class DTODtoNameImpl(node: ASTNode) : DTONamedElementImpl(node), DTODtoName {
    override val value: String
        get() = nameIdentifier.text

    override fun getNameIdentifier(): PsiElement {
        return findChild("/dtoName/Identifier")
    }

    override fun newNameNode(name: String): ASTNode {
        return project.createDTOName(name).node
    }

    override fun resolve(): PsiElement? {
        return JavaPsiFacade.getInstance(project)
                .findClass(
                    "${file.`package`}.$value",
                    ProjectScope.getAllScope(project),
                )
    }

    override fun accept(visitor: PsiElementVisitor) {
        if (visitor is DTOVisitor) {
            visitor.visitDtoName(this)
        } else {
            super.accept(visitor)
        }
    }
}

Hello. It seems that what you show is managed in

Please make sure this setting is switched on, and the resolved target of the reference is visible on screen. THen it will be highlighted when the caret is on the declaration, or on its usage.
If it still doesn’t work, please create an issue in youtrack.jetbrains.com

Oh, this is a duplicate of Is there a limit on the number of characters for its elements in PsiReference?

No duplicates, these are two different issues.

The issue you mentioned later is about highlighting (usage) not working when the quoted and defined character counts differ, whereas the current issue—I still don’t know the exact cause—I’ve only observed a bit more of the phenomenon.

Usage worked in the 2022.3 version because my DTO files and Java/Kotlin files were under src/main, while in the 2024.3 version, it was because the DTO and Java/Kotlin files were under src/test

But that can’t be right—the parsing logic doesn’t change based on file location, and the references successfully resolved to their definitions.

However, there were later cases where usage failed even under src/main, but it wasn’t reproducible afterward, making it impossible to pinpoint the exact cause