int (@NotNull final PyCallExpression.PyArgumentsMapping mapping, @NotNull final List<PyCallableParameter> parameterList, @NotNull final Map<PyCallableParameter, Integer> parameterHintToIndex, @NotNull final Map<Integer, EnumSet<ParameterFlag>> hintFlags, @NotNull final List<PyExpression> flatArgs, int currentParamOffset) { final PyCallableType callableType = mapping.getCallableType(); assert callableType != null; int lastParamIndex = callableType.getImplicitOffset(); final Map<PyExpression, PyCallableParameter> mappedParameters = mapping.getMappedParameters(); final Map<PyExpression, PyCallableParameter> mappedTupleParameters = mapping.getMappedTupleParameters(); for (PyExpression arg : flatArgs) { final boolean mustHighlight = arg.getTextRange().contains(currentParamOffset); PsiElement seeker = arg; // An argument tuple may have been flattened; find it while (!(seeker instanceof PyArgumentList) && seeker instanceof PyExpression && !mappedParameters.containsKey(seeker)) { seeker = seeker.getParent(); } if (seeker instanceof PyExpression) { final PyCallableParameter parameter = mappedParameters.get((PyExpression)seeker); lastParamIndex = Math.max(lastParamIndex, parameterList.indexOf(parameter)); if (parameter != null) { highlightParameter(parameter, parameterHintToIndex, hintFlags, mustHighlight); } } else if (PyCallExpressionHelper.isVariadicPositionalArgument(arg)) { for (PyCallableParameter parameter : mapping.getParametersMappedToVariadicPositionalArguments()) { lastParamIndex = Math.max(lastParamIndex, parameterList.indexOf(parameter)); highlightParameter(parameter, parameterHintToIndex, hintFlags, mustHighlight); } } else if (PyCallExpressionHelper.isVariadicKeywordArgument(arg)) { for (PyCallableParameter parameter : mapping.getParametersMappedToVariadicKeywordArguments()) { lastParamIndex = Math.max(lastParamIndex, parameterList.indexOf(parameter)); highlightParameter(parameter, parameterHintToIndex, hintFlags, mustHighlight); } } else { final PyTupleParameter tupleParameter = Optional .ofNullable(mappedTupleParameters.get(arg)) .map(PyCallableParameter::getParameter) .map(psi -> PyUtil.as(psi, PyTupleParameter.class)) .orElse(null); if (tupleParameter != null) { for (PyCallableParameter parameter : getFlattenedTupleParameterComponents(tupleParameter)) { lastParamIndex = Math.max(lastParamIndex, parameterList.indexOf(parameter)); highlightParameter(parameter, parameterHintToIndex, hintFlags, mustHighlight); } } } } return lastParamIndex; }