From 922a65e59047133346ef2655eb7f3b468bcdfeaa Mon Sep 17 00:00:00 2001 From: Morgan Bartholomew Date: Mon, 16 Feb 2026 12:26:44 +1000 Subject: [PATCH] PY-56268/PY-84930 go to type declaration: support callables GitOrigin-RevId: e05dd19b681fb80f60346e1c75c34252d19d83e9 --- .../actions/GotoTypeDeclarationAction.java | 4 ++-- .../codeInsight/PyGotoTypeDeclarationTest.kt | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoTypeDeclarationAction.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoTypeDeclarationAction.java index 1c5ffa81531a..25bdb378bd73 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoTypeDeclarationAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoTypeDeclarationAction.java @@ -64,7 +64,7 @@ public final class GotoTypeDeclarationAction extends BaseCodeInsightAction imple } @VisibleForTesting - public static PsiElement @Nullable [] findSymbolTypes(@NotNull Editor editor, int offset) { + public static @Nullable PsiElement @Nullable [] findSymbolTypes(@NotNull Editor editor, int offset) { return findSymbolTypes(editor, offset, TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.LOOKUP_ITEM_ACCEPTED); @@ -75,7 +75,7 @@ public final class GotoTypeDeclarationAction extends BaseCodeInsightAction imple /// This function is the highest-level way to trigger the "Go to Type Declaration" action. /// It's composed of a couple of lower-level functions. @ApiStatus.Internal - public static PsiElement @Nullable [] findSymbolTypes(@NotNull Editor editor, + public static @Nullable PsiElement @Nullable [] findSymbolTypes(@NotNull Editor editor, int offset, @MagicConstant(flagsFromClass = TargetElementUtil.class) int flags) { PsiElement targetElement = TargetElementUtil.getInstance().findTargetElement(editor, flags, offset); diff --git a/python/testSrc/com/jetbrains/python/codeInsight/PyGotoTypeDeclarationTest.kt b/python/testSrc/com/jetbrains/python/codeInsight/PyGotoTypeDeclarationTest.kt index 95a266967b00..6fead4822977 100644 --- a/python/testSrc/com/jetbrains/python/codeInsight/PyGotoTypeDeclarationTest.kt +++ b/python/testSrc/com/jetbrains/python/codeInsight/PyGotoTypeDeclarationTest.kt @@ -2,6 +2,7 @@ package com.jetbrains.python.codeInsight import com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction +import com.intellij.idea.TestFor import com.intellij.psi.PsiElement import com.jetbrains.python.PythonFileType import com.jetbrains.python.fixtures.PyTestCase @@ -125,10 +126,24 @@ class PyGotoTypeDeclarationTest : PyTestCase() { assertEquals((myFixture.file as PyFile).findTopLevelAttribute("Movie"), type) } - private fun findSymbolType(text: String): PsiElement = findSymbolTypes(text).single() + @TestFor(issues = ["PY-84930"]) + fun `test goto type declaration for callable`() { + val type = findSymbolType( + """ + from typing import Callable + + class A: ... + a: Callable[[], A] + """ + ) - private fun findSymbolTypes(text: String): List { + assertEquals((myFixture.file as PyFile).findTopLevelClass("A"), type) + } + + private fun findSymbolType(text: String): PsiElement = findSymbolTypes(text).single()!! + + private fun findSymbolTypes(text: String): List { myFixture.configureByText(PythonFileType.INSTANCE, text) - return GotoTypeDeclarationAction.findSymbolTypes(myFixture.editor, myFixture.caretOffset)?.asList() ?: emptyList() + return GotoTypeDeclarationAction.findSymbolTypes(myFixture.editor, myFixture.caretOffset)?.asList().orEmpty() } } \ No newline at end of file