diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java index 95cf6e3abab9..1f909a5dad10 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoImplementationHandler.java @@ -19,6 +19,7 @@ package com.intellij.codeInsight.navigation; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.ContainerProvider; import com.intellij.codeInsight.TargetElementUtil; +import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction; import com.intellij.ide.util.PsiElementListCellRenderer; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.NavigationItem; @@ -29,6 +30,8 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiNamedElement; import com.intellij.psi.PsiReference; +import com.intellij.psi.search.PsiElementProcessor; +import com.intellij.util.Consumer; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,6 +51,10 @@ public class GotoImplementationHandler extends GotoTargetHandler { int offset = editor.getCaretModel().getOffset(); PsiElement source = TargetElementUtil.getInstance().findTargetElement(editor, ImplementationSearcher.getFlags(), offset); if (source == null) return null; + return createDataForSource(editor, offset, source); + } + + private GotoData createDataForSource(@NotNull Editor editor, int offset, PsiElement source) { final PsiReference reference = TargetElementUtil.findReference(editor, offset); final TargetElementUtil instance = TargetElementUtil.getInstance(); PsiElement[] targets = new ImplementationSearcher.FirstImplementationsSearcher() { @@ -76,6 +83,19 @@ public class GotoImplementationHandler extends GotoTargetHandler { return gotoData; } + @Override + protected void chooseFromAmbiguousSources(Editor editor, PsiFile file, Consumer successCallback) { + int offset = editor.getCaretModel().getOffset(); + PsiElementProcessor navigateProcessor = element -> { + GotoData data = createDataForSource(editor, offset, element); + if (data != null) { + successCallback.consume(data); + } + return true; + }; + GotoDeclarationAction + .chooseAmbiguousTarget(editor, offset, navigateProcessor, CodeInsightBundle.message("declaration.navigation.title"), null); + } private static PsiElement getContainer(PsiElement refElement) { for (ContainerProvider provider : ContainerProvider.EP_NAME.getExtensions()) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java index 115dda164673..bd3d7a776c9f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java @@ -47,6 +47,7 @@ import com.intellij.ui.popup.HintUpdateSupply; import com.intellij.usages.UsageView; import com.intellij.util.Alarm; import com.intellij.util.ArrayUtil; +import com.intellij.util.Consumer; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -76,12 +77,17 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler { if (gotoData != null) { show(project, editor, file, gotoData); } + else { + chooseFromAmbiguousSources(editor, file, data -> show(project, editor, file, data)); + } } catch (IndexNotReadyException e) { DumbService.getInstance(project).showDumbModeNotification("Navigation is not available here during index update"); } } + protected void chooseFromAmbiguousSources(Editor editor, PsiFile file, Consumer successCallback) { } + @NonNls protected abstract String getFeatureUsedKey();