[kotlin] narrow down the highlighting range for foreach parameter unused inspection

^KTIJ-33767 fixed

GitOrigin-RevId: 2b5b70fa422dd2b052945744d8e67f0e6f7fc1e4
This commit is contained in:
Anna Kozlova
2025-04-12 14:41:31 +00:00
committed by intellij-monorepo-bot
parent 3c0c804b94
commit 0cd1da0307
4 changed files with 25 additions and 0 deletions
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeInsight.inspections.shared.ForEachParameterNotUsedInspection.UnusedForEachParameterInfo
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections.KotlinApplicableInspectionBase
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections.KotlinModCommandQuickFix
import org.jetbrains.kotlin.idea.codeinsights.impl.base.applicators.ApplicabilityRanges
import org.jetbrains.kotlin.idea.refactoring.moveFunctionLiteralOutsideParentheses
import org.jetbrains.kotlin.idea.refactoring.util.setParameterListIfAny
import org.jetbrains.kotlin.name.CallableId
@@ -49,6 +50,10 @@ internal class ForEachParameterNotUsedInspection :
/* ...fixes = */ *createQuickFixes(element, context).toTypedArray()
)
override fun getApplicableRanges(element: KtCallExpression): List<TextRange> {
return ApplicabilityRanges.calleeExpression(element)
}
private fun createQuickFixes(
element: KtCallExpression,
context: UnusedForEachParameterInfo,
@@ -1298,6 +1298,11 @@ public abstract class SharedK1LocalInspectionTestGenerated extends AbstractShare
runTest("../testData/inspectionsLocal/forEachParameterNotUsed/normal.kt");
}
@TestMetadata("outsideOfApplicableRange.kt")
public void testOutsideOfApplicableRange() throws Exception {
runTest("../testData/inspectionsLocal/forEachParameterNotUsed/outsideOfApplicableRange.kt");
}
@TestMetadata("repeat.kt")
public void testRepeat() throws Exception {
runTest("../testData/inspectionsLocal/forEachParameterNotUsed/repeat.kt");
@@ -1298,6 +1298,11 @@ public abstract class SharedK2LocalInspectionTestGenerated extends AbstractShare
runTest("../testData/inspectionsLocal/forEachParameterNotUsed/normal.kt");
}
@TestMetadata("outsideOfApplicableRange.kt")
public void testOutsideOfApplicableRange() throws Exception {
runTest("../testData/inspectionsLocal/forEachParameterNotUsed/outsideOfApplicableRange.kt");
}
@TestMetadata("repeat.kt")
public void testRepeat() throws Exception {
runTest("../testData/inspectionsLocal/forEachParameterNotUsed/repeat.kt");
@@ -0,0 +1,10 @@
// WITH_STDLIB
// PROBLEM: none
fun test(list: List<String>) {
list.forEach {
//
//<caret>
//
}
}