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 {
69
69
val resolvedElement = sourceElement.parent?.reference?.resolve()
70
70
if (resolvedElement != null ) {
71
71
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
+ }
72
77
}
73
78
74
79
// 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
17
17
import com.intellij.lang.jsgraphql.psi.GraphQLInputObjectTypeDefinition
18
18
import com.intellij.lang.jsgraphql.psi.GraphQLInputValueDefinition
19
19
import com.intellij.lang.jsgraphql.psi.GraphQLOperationDefinition
20
+ import com.intellij.lang.jsgraphql.psi.GraphQLRecursiveVisitor
20
21
import com.intellij.lang.jsgraphql.psi.GraphQLSelectionSet
21
22
import com.intellij.lang.jsgraphql.psi.GraphQLTypeNameDefinition
22
23
import com.intellij.openapi.project.Project
@@ -357,3 +358,19 @@ private fun String.minusOperationTypeSuffix(): String {
357
358
else -> this
358
359
}
359
360
}
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() {
58
58
fromElement = { elementAt<PsiElement >(" computerFields" )!! },
59
59
toFile = " build/generated/source/apollo/main/com/example/generated/fragment/ComputerFields.kt" ,
60
60
toElement = { elementAt<KtClass >(" class ComputerFields" )!! },
61
+ multipleTarget = true
61
62
)
62
63
63
64
@Test
You can’t perform that action at this time.
0 commit comments