Fix false positive ILLEGAL_COMMAND_NAME and potential other mistakes, fix #340

This commit is contained in:
Him188 2021-04-21 18:25:32 +08:00
parent 706daec4ac
commit 17e616d544
2 changed files with 4 additions and 9 deletions

View File

@ -22,7 +22,6 @@ import net.mamoe.mirai.console.compiler.common.resolve.ResolveContextKind
import net.mamoe.mirai.console.compiler.common.resolve.resolveContextKinds
import net.mamoe.mirai.console.intellij.resolve.bodyCalls
import net.mamoe.mirai.console.intellij.resolve.resolveStringConstantValues
import net.mamoe.mirai.console.intellij.resolve.valueParametersWithArguments
import net.mamoe.mirai.console.intellij.util.RequirementHelper
import net.mamoe.mirai.console.intellij.util.RequirementParser
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
@ -50,8 +49,10 @@ class ContextualParametersChecker : DeclarationChecker {
val calls = declaration.bodyCalls(context.bindingContext) ?: return
for ((call, _) in calls) {
for ((parameter, argument) in call.valueParametersWithArguments()) {
checkArgument(parameter, argument, context)
for ((parameter, resolvedArgument) in call.valueArguments) {
for (valueArgument in resolvedArgument.arguments) {
checkArgument(parameter, valueArgument, context)
}
}
}
}

View File

@ -16,7 +16,6 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.references.resolveToDescriptors
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@ -28,7 +27,6 @@ import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.constants.ArrayValue
import org.jetbrains.kotlin.resolve.constants.ConstantValue
@ -203,10 +201,6 @@ fun KtElement.resolveAllCallsWithElement(
}
}
fun ResolvedCall<*>.valueParametersWithArguments(): List<Pair<ValueParameterDescriptor, ValueArgument>> {
return this.valueParameters.zip(this.valueArgumentsByIndex?.mapNotNull { it.arguments.firstOrNull() }.orEmpty())
}
fun ValueArgument.resolveStringConstantValues(bindingContext: BindingContext): Sequence<String>? {
return this.getArgumentExpression()?.resolveStringConstantValues(bindingContext)
}