diff --git a/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java b/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java index b7b36590bfe4..f4350164cbcc 100644 --- a/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyArgumentListInspection.java @@ -268,7 +268,10 @@ public class PyArgumentListInspection extends PyInspection { } else { // all mappings have unmapped arguments so we couldn't determine desired argument list and suggest appropriate quick fixes - holder.registerProblem(node, addPossibleCalleesRepresentationAndWrapInHtml(PyBundle.message("INSP.unexpected.arg(s)"), mappings, context)); + holder.registerProblem( + node, + addPossibleCalleesRepresentation(PyBundle.message("INSP.unexpected.arg(s)"), mappings, context, holder.isOnTheFly()) + ); } } @@ -288,7 +291,7 @@ public class PyArgumentListInspection extends PyInspection { ContainerUtil.exists(mappings.get(0).getUnmappedParameters(), parameter -> parameter.getName() == null)) { holder.registerProblem( psi, - addPossibleCalleesRepresentationAndWrapInHtml(PyBundle.message("INSP.parameter(s).unfilled"), mappings, context) + addPossibleCalleesRepresentation(PyBundle.message("INSP.parameter(s).unfilled"), mappings, context, holder.isOnTheFly()) ); } else { @@ -303,27 +306,43 @@ public class PyArgumentListInspection extends PyInspection { } @NotNull - private static String addPossibleCalleesRepresentationAndWrapInHtml(@NotNull String prefix, - @NotNull List mappings, - @NotNull TypeEvalContext context) { - final String possibleCalleesRepresentation = XmlStringUtil.escapeString(calculatePossibleCalleesRepresentation(mappings, context)); - return XmlStringUtil.wrapInHtml(prefix + "
" + PyBundle.message("INSP.possible.callees") + ":
" + possibleCalleesRepresentation); + private static String addPossibleCalleesRepresentation(@NotNull String prefix, + @NotNull List mappings, + @NotNull TypeEvalContext context, + boolean isOnTheFly) { + final String separator = isOnTheFly ? "
" : " "; + final String possibleCalleesRepresentation = calculatePossibleCalleesRepresentation(mappings, context, isOnTheFly); + + if (isOnTheFly) { + return XmlStringUtil.wrapInHtml( + prefix + separator + + PyBundle.message("INSP.possible.callees") + ":" + separator + + XmlStringUtil.escapeString(possibleCalleesRepresentation) + ); + } + else { + return prefix + "." + separator + + PyBundle.message("INSP.possible.callees") + ":" + separator + + possibleCalleesRepresentation; + } } @NotNull private static String calculatePossibleCalleesRepresentation(@NotNull List mappings, - @NotNull TypeEvalContext context) { + @NotNull TypeEvalContext context, + boolean isOnTheFly) { return StreamEx .of(mappings) .map(PyCallExpression.PyArgumentsMapping::getMarkedCallee) .nonNull() .map(markedCallee -> calculatePossibleCalleeRepresentation(markedCallee, context)) .nonNull() - .collect(Collectors.joining("
")); + .collect(Collectors.joining(isOnTheFly ? "
" : " ")); } @Nullable - private static String calculatePossibleCalleeRepresentation(@NotNull PyCallExpression.PyMarkedCallee markedCallee, @NotNull TypeEvalContext context) { + private static String calculatePossibleCalleeRepresentation(@NotNull PyCallExpression.PyMarkedCallee markedCallee, + @NotNull TypeEvalContext context) { final String name = markedCallee.getElement() != null ? markedCallee.getElement().getName() : ""; final List callableParameters = markedCallee.getCallableType().getParameters(context); if (callableParameters == null) return null; diff --git a/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspectionProblemRegistrar.java b/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspectionProblemRegistrar.java index 90fea3384212..bba73cca930b 100644 --- a/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspectionProblemRegistrar.java +++ b/python/src/com/jetbrains/python/inspections/PyTypeCheckerInspectionProblemRegistrar.java @@ -17,6 +17,7 @@ package com.jetbrains.python.inspections; import com.google.common.collect.Sets; import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.util.ObjectUtils; @@ -75,7 +76,7 @@ class PyTypeCheckerInspectionProblemRegistrar { } else { visitor.registerProblem(getMultiCalleeElementToHighlight(callSite), - getMultiCalleeProblemMessage(argumentTypes, calleesResults, context), + getMultiCalleeProblemMessage(argumentTypes, calleesResults, context, isOnTheFly(visitor)), getMultiCalleeHighlightType(calleesResults)); } } @@ -143,9 +144,11 @@ class PyTypeCheckerInspectionProblemRegistrar { registerSingleCalleeProblem(visitor, preferredOperatorsResults.get(0), context); } else { - visitor.registerProblem(allCalleesAreRightOperators ? binaryExpression.getLeftExpression() : binaryExpression.getRightExpression(), - getMultiCalleeProblemMessage(argumentTypes, preferredOperatorsResults, context), - getMultiCalleeHighlightType(preferredOperatorsResults)); + visitor.registerProblem( + allCalleesAreRightOperators ? binaryExpression.getLeftExpression() : binaryExpression.getRightExpression(), + getMultiCalleeProblemMessage(argumentTypes, preferredOperatorsResults, context, isOnTheFly(visitor)), + getMultiCalleeHighlightType(preferredOperatorsResults) + ); } } @@ -175,11 +178,26 @@ class PyTypeCheckerInspectionProblemRegistrar { @NotNull private static String getMultiCalleeProblemMessage(@NotNull List argumentTypes, @NotNull List calleesResults, - @NotNull TypeEvalContext context) { - return XmlStringUtil.wrapInHtml("Unexpected type(s):
" + - XmlStringUtil.escapeString(getMultiCalleeActualTypesRepresentation(argumentTypes, context)) + "
" + - "Possible types:
" + - XmlStringUtil.escapeString(getMultiCalleePossibleExpectedTypesRepresentation(calleesResults, context))); + @NotNull TypeEvalContext context, + boolean isOnTheFly) { + final String separator = isOnTheFly ? "
" : " "; + final String actualTypesRepresentation = getMultiCalleeActualTypesRepresentation(argumentTypes, context); + final String expectedTypesRepresentation = getMultiCalleePossibleExpectedTypesRepresentation(calleesResults, context, isOnTheFly); + + if (isOnTheFly) { + return XmlStringUtil.wrapInHtml( + "Unexpected type(s):" + separator + + XmlStringUtil.escapeString(actualTypesRepresentation) + separator + + "Possible types:" + separator + + XmlStringUtil.escapeString(expectedTypesRepresentation) + ); + } + else { + return "Unexpected type(s):" + separator + + actualTypesRepresentation + separator + + "Possible types:" + separator + + expectedTypesRepresentation; + } } /** @@ -197,6 +215,11 @@ class PyTypeCheckerInspectionProblemRegistrar { return allExpectedTypesWereSubstituted ? ProblemHighlightType.WEAK_WARNING : ProblemHighlightType.GENERIC_ERROR_OR_WARNING; } + private static boolean isOnTheFly(@NotNull PyInspectionVisitor visitor) { + final ProblemsHolder holder = visitor.getHolder(); + return holder != null && holder.isOnTheFly(); + } + @Nullable private static Set getAttributes(@NotNull PyType type, @NotNull TypeEvalContext context) { if (type instanceof PyStructuralType) { @@ -231,11 +254,12 @@ class PyTypeCheckerInspectionProblemRegistrar { @NotNull private static String getMultiCalleePossibleExpectedTypesRepresentation(@NotNull List calleesResults, - @NotNull TypeEvalContext context) { + @NotNull TypeEvalContext context, + boolean isOnTheFly) { return calleesResults .stream() .map(calleeResult -> getMultiCalleeExpectedTypesRepresentation(calleeResult.getResults(), context)) - .collect(Collectors.joining("
")); + .collect(Collectors.joining(isOnTheFly ? "
" : " ")); } @NotNull