LineRange (@NotNull final Document document, @NotNull final PsiElement rawElement) { PsiElement element = getCommentOrStatement(document, rawElement); PyStatementList statementList2 = getStatementList(element); if (statementList2 != null) { // move to one-line conditional/loop statement final int number = document.getLineNumber(element.getTextOffset()); final int number2 = document.getLineNumber(statementList2.getParent().getTextOffset()); if (number == number2) { return new ScopeRange(statementList2, statementList2.getFirstChild(), true); } } final PyStatementPart statementPart = PsiTreeUtil.getParentOfType(rawElement, PyStatementPart.class, true, PyStatement.class, PyStatementList.class); final PyFunction functionDefinition = PsiTreeUtil.getParentOfType(rawElement, PyFunction.class, true, PyStatement.class, PyStatementList.class); final PyClass classDefinition = PsiTreeUtil.getParentOfType(rawElement, PyClass.class, true, PyStatement.class, PyStatementList.class); PyStatementList list = null; if (statementPart != null) list = statementPart.getStatementList(); else if (functionDefinition != null) list = functionDefinition.getStatementList(); else if (classDefinition != null) list = classDefinition.getStatementList(); if (list != null) { return new ScopeRange(list, list.getFirstChild(), true); } return null; }