Skip to content

Commit

Permalink
Only highlight the name of unused operations, rather than the whole o…
Browse files Browse the repository at this point in the history
…peration
  • Loading branch information
BoD committed Oct 28, 2024
1 parent 2b5d778 commit 5a37e0c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import com.apollographql.ijplugin.telemetry.TelemetryEvent
import com.apollographql.ijplugin.util.isProcessCanceled
import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.lang.jsgraphql.psi.GraphQLIdentifier
import com.intellij.lang.jsgraphql.psi.GraphQLTypedOperationDefinition
import com.intellij.lang.jsgraphql.psi.GraphQLVisitor
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.util.childrenOfType

class ApolloUnusedOperationInspection : LocalInspectionTool() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return object : GraphQLVisitor() {
override fun visitTypedOperationDefinition(o: GraphQLTypedOperationDefinition) {
if (isUnusedOperation(o)) {
val nameElement = o.childrenOfType<GraphQLIdentifier>().firstOrNull() ?: return
holder.registerProblem(
o,
nameElement,
ApolloBundle.message("inspection.unusedOperation.reportText"),
DeleteElementQuickFix(label = "inspection.unusedOperation.quickFix", telemetryEvent = { TelemetryEvent.ApolloIjUnusedOperationQuickFix() }) { it }
DeleteElementQuickFix(label = "inspection.unusedOperation.quickFix", telemetryEvent = { TelemetryEvent.ApolloIjUnusedOperationQuickFix() }) { it.parent }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ApolloSchemaInGraphqlFileInspectionTest : ApolloTestCase() {
myFixture.configureByFile("SchemaInGraphqlFile.graphql")
val highlightInfos = doHighlighting()
assertTrue(highlightInfos.any { it.description == "The Apollo Kotlin compiler requires type definitions to reside in a .graphqls file" })
val quickFixAction = myFixture.findSingleIntention("Rename file to SchemaInGraphqlFile.graphqls");
val quickFixAction = myFixture.findSingleIntention("Rename file to SchemaInGraphqlFile.graphqls")
assertNotNull(quickFixAction)
myFixture.launchAction(quickFixAction)
TestCase.assertEquals("SchemaInGraphqlFile.graphqls", myFixture.editor.cast<EditorEx>()!!.virtualFile.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ApolloUnusedFieldInspectionTest : ApolloTestCase() {

moveCaret("id")

val quickFixAction = myFixture.findSingleIntention("Delete field");
val quickFixAction = myFixture.findSingleIntention("Delete field")
assertNotNull(quickFixAction)
myFixture.launchAction(quickFixAction)
myFixture.checkResult("""
Expand Down Expand Up @@ -70,7 +70,7 @@ class ApolloUnusedFieldInspectionTest : ApolloTestCase() {

moveCaret("... on Cat")

val quickFixAction = myFixture.findSingleIntention("Delete field");
val quickFixAction = myFixture.findSingleIntention("Delete field")
assertNotNull(quickFixAction)
myFixture.launchAction(quickFixAction)
myFixture.checkResult("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class ApolloUnusedOperationInspectionTest : ApolloTestCase() {
var highlightInfos = doHighlighting()
assertTrue(highlightInfos.any { it.description == "Unused operation" })

val quickFixAction = myFixture.findSingleIntention("Delete operation");
moveCaret("Computers")
val quickFixAction = myFixture.findSingleIntention("Delete operation")
assertNotNull(quickFixAction)
myFixture.launchAction(quickFixAction)
myFixture.checkResult("""
Expand Down

0 comments on commit 5a37e0c

Please sign in to comment.