From c041c7b7bb6aad8f5205f770da5d9b9b6485c6d4 Mon Sep 17 00:00:00 2001 From: BoD Date: Tue, 5 Dec 2023 13:04:03 +0100 Subject: [PATCH] Add a More... link to the tooltip to show the inspection description --- ...olloInputConstructorNamedArgsInspection.kt | 3 +- .../ijplugin/util/Inspections.kt | 51 +++++++++++++++++++ .../messages/ApolloBundle.properties | 3 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/util/Inspections.kt diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/inspection/ApolloInputConstructorNamedArgsInspection.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/inspection/ApolloInputConstructorNamedArgsInspection.kt index bdbf34d8bda..9ce2f7488b2 100644 --- a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/inspection/ApolloInputConstructorNamedArgsInspection.kt +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/inspection/ApolloInputConstructorNamedArgsInspection.kt @@ -7,6 +7,7 @@ import com.apollographql.ijplugin.telemetry.TelemetryEvent import com.apollographql.ijplugin.telemetry.telemetryService import com.apollographql.ijplugin.util.cast import com.apollographql.ijplugin.util.originalClassName +import com.apollographql.ijplugin.util.registerProblem import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils import com.intellij.codeInspection.LocalInspectionTool import com.intellij.codeInspection.LocalQuickFix @@ -41,7 +42,7 @@ class ApolloInputConstructorNamedArgsInspection : LocalInspectionTool() { add(AddArgumentNamesQuickFix) if (projectApolloVersion.isAtLeastV4) add(ChangeToBuilderQuickFix) }.toTypedArray() - holder.registerProblem(expression, ApolloBundle.message("inspection.inputConstructorNamedArgs.reportText"), *quickFixes) + holder.registerProblem(expression, ApolloBundle.message("inspection.inputConstructorNamedArgs.reportText"), withMoreLink = true, *quickFixes) } } } diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/util/Inspections.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/util/Inspections.kt new file mode 100644 index 00000000000..a9ebd5ee8c8 --- /dev/null +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/util/Inspections.kt @@ -0,0 +1,51 @@ +package com.apollographql.ijplugin.util + +import com.apollographql.ijplugin.ApolloBundle +import com.intellij.codeInsight.daemon.impl.analysis.DaemonTooltipsUtil +import com.intellij.codeInspection.LocalInspectionTool +import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.ProblemDescriptorBase +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.PsiElement + +context(LocalInspectionTool) +fun ProblemsHolder.registerProblem( + element: PsiElement, + description: String, + withMoreLink: Boolean, + vararg fixes: LocalQuickFix, +) { + registerProblem(element, description, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, withMoreLink, *fixes) +} + +context(LocalInspectionTool) +fun ProblemsHolder.registerProblem( + element: PsiElement, + description: String, + highlightType: ProblemHighlightType, + withMoreLink: Boolean, + vararg fixes: LocalQuickFix, +) { + if (!withMoreLink) { + registerProblem(element, description, highlightType, *fixes) + return + } + registerProblem( + object : ProblemDescriptorBase( + element, + element, + description, + fixes, + highlightType, + false, + null, + true, + isOnTheFly + ) { + override fun getTooltipTemplate(): String { + return "$description ${ApolloBundle.message("inspection.more")} ${DaemonTooltipsUtil.getShortcutText()}" + } + } + ) +} diff --git a/intellij-plugin/src/main/resources/messages/ApolloBundle.properties b/intellij-plugin/src/main/resources/messages/ApolloBundle.properties index e2665f25bb3..a804beae195 100644 --- a/intellij-plugin/src/main/resources/messages/ApolloBundle.properties +++ b/intellij-plugin/src/main/resources/messages/ApolloBundle.properties @@ -204,5 +204,6 @@ normalizedCacheViewer.pullFromDevice.listApolloClients.error=Error listing Apoll normalizedCacheViewer.pullFromDevice.listApolloClients.empty=No Apollo clients normalizedCacheViewer.pullFromDevice.apolloDebugNormalizedCache.records={0,choice, 0#no records|1#one record|2#{0,number} records} - tree.dynamicNode.loading=Loading... + +inspection.more=More...