String (PsiElement element, IElementType elementType) { final var parentStatement = PsiTreeUtil.getParentOfType(element, PyStatement.class); if (parentStatement == null) { return element.getText(); } if (elementType == PyTokenTypes.FROM_KEYWORD) { // We want to show yield doc in 'yield from ...' expressions when hover to 'from', // but there is no particular PyStatement for 'yield' keyword, therefore we make such a check. if (parentStatement.getFirstChild() instanceof PyYieldExpression) { return PyNames.YIELD; } else if (parentStatement instanceof PyRaiseStatement) { return PyNames.RAISE; } } else if (elementType == PyTokenTypes.AS_KEYWORD) { if (parentStatement instanceof PyWithStatement) { return PyNames.WITH; } else if (parentStatement instanceof PyTryExceptStatement) { return PyNames.EXCEPT; } } else if (elementType == PyTokenTypes.ELSE_KEYWORD) { if (parentStatement instanceof PyWhileStatement) { return PyNames.WHILE; } else if (parentStatement instanceof PyForStatement) { return PyNames.FOR; } else if (parentStatement instanceof PyTryExceptStatement) { return PyNames.TRY; } } else if (elementType == PyTokenTypes.IN_KEYWORD && parentStatement instanceof PyForStatement) { return PyNames.FOR; } return element.getText(); }