Skip to content

Commit

Permalink
Add a More... link to the tooltip to show the inspection description
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Dec 5, 2023
1 parent c3a388a commit c041c7b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 "<html>$description <a href=\"#inspection/$shortName\">${ApolloBundle.message("inspection.more")}</a> ${DaemonTooltipsUtil.getShortcutText()}"
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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...

0 comments on commit c041c7b

Please sign in to comment.