Skip to content

Commit 0df854d

Browse files
committed
[IJ Plugin] Improve the presentation of GraphQL elements when navigating to them (apollographql#5900)
1 parent e6e04e4 commit 0df854d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/navigation/LogNavigationPsiElement.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.intellij.navigation.NavigationItem
77
import com.intellij.platform.backend.navigation.NavigationRequest
88
import com.intellij.pom.Navigatable
99
import com.intellij.psi.PsiElement
10+
import javax.swing.Icon
1011

1112
private class LogNavigationPsiElement(
1213
private val wrapped: PsiElement,
@@ -24,8 +25,13 @@ private class LogNavigationPsiElement(
2425
return (wrapped as? NavigationItem)?.name
2526
}
2627

27-
override fun getPresentation(): ItemPresentation? {
28-
return (wrapped as? NavigationItem)?.presentation
28+
override fun getPresentation(): ItemPresentation {
29+
return (wrapped as? NavigationItem)?.presentation ?: object : ItemPresentation {
30+
// We don't want the presentation to be too wide: fallback to the first line of text, truncated to 80 characters
31+
override fun getPresentableText(): String? = wrapped.text.split('\n').firstOrNull()?.take(80)
32+
33+
override fun getIcon(unused: Boolean): Icon? = null
34+
}
2935
}
3036

3137
@Suppress("UnstableApiUsage")

0 commit comments

Comments
 (0)