PsiElement (@NotNull Editor editor, @NotNull PsiFile file, @Nullable PsiElement contextElement, int targetOffset) { if (contextElement != null) { final IElementType elementType = contextElement.getNode().getElementType(); if (PythonDialectsTokenSetProvider.getInstance().getKeywordTokens().contains(elementType)) { return contextElement; } final PsiElement parent = contextElement.getParent(); if (parent instanceof PyArgumentList && (PyTokenTypes.LPAR == elementType || PyTokenTypes.RPAR == elementType)) { final PyCallExpression expression = PsiTreeUtil.getParentOfType(contextElement, PyCallExpression.class); if (expression != null) { final PyExpression callee = expression.getCallee(); if (callee != null) { final PsiReference reference = callee.getReference(); if (reference != null) { return reference.resolve(); } } } } final PyExpression expression = PsiTreeUtil.getParentOfType(contextElement, PyExpression.class); if (expression != null && DocStringUtil.isDocStringExpression(expression)) { final PyDocStringOwner docstringOwner = PsiTreeUtil.getParentOfType(contextElement, PyDocStringOwner.class); if (docstringOwner != null) return docstringOwner; } } return null; }