diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtd.kt b/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtd.kt index b247a3f326a7..8850221e2139 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtd.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtd.kt @@ -71,7 +71,7 @@ private fun gotoDeclarationInner(file: PsiFile, offset: Int): GTDActionData? { } private fun fromTargetData(file: PsiFile, offset: Int): GTDActionData? { - val (declaredData, referencedData) = declaredReferencedData(file, offset) + val (declaredData, referencedData) = declaredReferencedData(file, offset) ?: return null val targetData = referencedData // prefer referenced because GTD follows references first ?: declaredData // offer navigation between declarations of the declared symbol ?: return null diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtdu.kt b/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtdu.kt index 688897220f46..3b5d30cb1a45 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtdu.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/impl/gtdu.kt @@ -55,7 +55,7 @@ private fun gotoDeclarationOrUsagesInner(file: PsiFile, offset: Int): GTDUAction } private fun fromTargetData(file: PsiFile, offset: Int): GTDUActionData? { - val (declaredData, referencedData) = declaredReferencedData(file, offset) + val (declaredData, referencedData) = declaredReferencedData(file, offset) ?: return null return referencedData?.toGTDActionData(file.project)?.toGTDUActionData() // GTD of referenced symbols ?: (referencedData)?.let { ShowUsagesGTDUActionData(file.project, it) } // SU of referenced symbols if nowhere to navigate ?: declaredData?.let { ShowUsagesGTDUActionData(file.project, it) } // SU of declared symbols diff --git a/platform/lang-impl/src/com/intellij/model/psi/impl/targets.kt b/platform/lang-impl/src/com/intellij/model/psi/impl/targets.kt index f73b14efaf6a..4d3348c5dd99 100644 --- a/platform/lang-impl/src/com/intellij/model/psi/impl/targets.kt +++ b/platform/lang-impl/src/com/intellij/model/psi/impl/targets.kt @@ -22,6 +22,7 @@ import org.jetbrains.annotations.ApiStatus.Experimental @Experimental fun targetSymbols(file: PsiFile, offset: Int): Collection { val (declaredData, referencedData) = declaredReferencedData(file, offset) + ?: return emptyList() val data = referencedData ?: declaredData ?: return emptyList() @@ -33,16 +34,14 @@ fun targetSymbols(file: PsiFile, offset: Int): Collection { */ @Experimental fun targetDeclarationAndReferenceSymbols(file: PsiFile, offset: Int): Pair, Collection> { - val (declaredData, referencedData) = declaredReferencedData(file, offset) + val (declaredData, referencedData) = declaredReferencedData(file, offset) ?: return Pair(emptyList(), emptyList()) return (declaredData?.targets?.map { it.symbol } ?: emptyList()) to (referencedData?.targets?.map { it.symbol } ?: emptyList()) } -private val emptyData = DeclaredReferencedData(null, null) - -internal fun declaredReferencedData(file: PsiFile, offset: Int): DeclaredReferencedData { +internal fun declaredReferencedData(file: PsiFile, offset: Int): DeclaredReferencedData? { val allDeclarationsOrReferences: List = declarationsOrReferences(file, offset) if (allDeclarationsOrReferences.isEmpty()) { - return emptyData + return null } val withMinimalRanges: Collection = chooseByRange(