HtmlChunk (@NotNull PyExpression expression, @NotNull TypeEvalContext context) { final @NlsSafe String expressionText = expression.getText(); if (expression instanceof PyReferenceExpression referenceExpression) { if (!referenceExpression.isQualified()) { final PyResolveContext resolveContext = PyResolveContext.defaultContext(context); for (ResolveResult result : referenceExpression.getReference(resolveContext).multiResolve(false)) { if (result.getElement() instanceof PyClass pyClass && pyClass.getQualifiedName() != null) { return styledReference(PyDocumentationLink.toClass(pyClass, expressionText), pyClass); } } } } else if (expression instanceof PySubscriptionExpression) { final PyExpression operand = ((PySubscriptionExpression)expression).getOperand(); final PyExpression indexExpression = ((PySubscriptionExpression)expression).getIndexExpression(); if (indexExpression != null) { return new HtmlBuilder() .append(describeSuperClass(operand, context)) .append(styledSpan("[", PyHighlighter.PY_BRACKETS)) .append(describeSuperClass(indexExpression, context)) .append(styledSpan("]", PyHighlighter.PY_BRACKETS)) .toFragment(); } } else if (expression instanceof PyKeywordArgument) { final String keyword = ((PyKeywordArgument)expression).getKeyword(); final PyExpression valueExpression = ((PyKeywordArgument)expression).getValueExpression(); if (PyNames.METACLASS.equals(keyword) && valueExpression != null) { return new HtmlBuilder() .append(styledSpan(PyNames.METACLASS, PyHighlighter.PY_KEYWORD_ARGUMENT)) .append(styledSpan("=", PyHighlighter.PY_OPERATION_SIGN)) .append(describeSuperClass(valueExpression, context)) .toFragment(); } } else if (PyClassImpl.isSixWithMetaclassCall(expression)) { final PyCallExpression callExpression = (PyCallExpression)expression; final PyExpression callee = callExpression.getCallee(); if (callee != null) { return new HtmlBuilder() .append(styledSpan(callee.getText(), DefaultLanguageHighlighterColors.IDENTIFIER)) .append(styledSpan("(", PyHighlighter.PY_PARENTHS)) .append(StreamEx .of(callExpression.getArguments()) .map(argument -> describeSuperClass(argument, context)) .collect(HtmlChunk.toFragment(styledSpan(", ", PyHighlighter.PY_COMMA)))) .append(styledSpan(")", PyHighlighter.PY_PARENTHS)) .toFragment(); } } return HtmlChunk.text(expressionText); }