File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
main/kotlin/com/apollographql/ijplugin/navigation
test/kotlin/com/apollographql/ijplugin/navigation Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,11 @@ class GraphQLGotoDeclarationHandler : GotoDeclarationHandler {
6969 val resolvedElement = sourceElement.parent?.reference?.resolve()
7070 if (resolvedElement != null ) {
7171 add(resolvedElement)
72+ } else {
73+ // Special case for Fragment declaration: we switch to the Fragment's usages
74+ if (gqlElement is GraphQLFragmentDefinition ) {
75+ addAll(findFragmentSpreads(gqlElement.project) { it.nameIdentifier.reference?.resolve() == gqlElement.nameIdentifier })
76+ }
7277 }
7378
7479 // Add Kotlin definition(s)
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import com.intellij.lang.jsgraphql.psi.GraphQLInlineFragment
1717import com.intellij.lang.jsgraphql.psi.GraphQLInputObjectTypeDefinition
1818import com.intellij.lang.jsgraphql.psi.GraphQLInputValueDefinition
1919import com.intellij.lang.jsgraphql.psi.GraphQLOperationDefinition
20+ import com.intellij.lang.jsgraphql.psi.GraphQLRecursiveVisitor
2021import com.intellij.lang.jsgraphql.psi.GraphQLSelectionSet
2122import com.intellij.lang.jsgraphql.psi.GraphQLTypeNameDefinition
2223import com.intellij.openapi.project.Project
@@ -357,3 +358,19 @@ private fun String.minusOperationTypeSuffix(): String {
357358 else -> this
358359 }
359360}
361+
362+ fun findFragmentSpreads (project : Project , predicate : (GraphQLFragmentSpread ) -> Boolean ): List <GraphQLFragmentSpread > {
363+ return FileTypeIndex .getFiles(GraphQLFileType .INSTANCE , GlobalSearchScope .allScope(project)).flatMap { virtualFile ->
364+ val fragmentSpreads = mutableListOf<GraphQLFragmentSpread >()
365+ val visitor = object : GraphQLRecursiveVisitor () {
366+ override fun visitFragmentSpread (o : GraphQLFragmentSpread ) {
367+ super .visitFragmentSpread(o)
368+ if (predicate(o)) {
369+ fragmentSpreads + = o
370+ }
371+ }
372+ }
373+ PsiManager .getInstance(project).findFile(virtualFile)?.accept(visitor)
374+ fragmentSpreads
375+ }
376+ }
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ class GraphQLGotoDeclarationHandlerTest : ApolloTestCase() {
5858 fromElement = { elementAt<PsiElement >(" computerFields" )!! },
5959 toFile = " build/generated/source/apollo/main/com/example/generated/fragment/ComputerFields.kt" ,
6060 toElement = { elementAt<KtClass >(" class ComputerFields" )!! },
61+ multipleTarget = true
6162 )
6263
6364 @Test
You can’t perform that action at this time.
0 commit comments