mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
better detection of incomplete blocks in formatter (PY-6360)
This commit is contained in:
@@ -601,12 +601,14 @@ public class PyBlock implements ASTBlock {
|
||||
|
||||
public boolean isIncomplete() {
|
||||
// if there's something following us, we're not incomplete
|
||||
PsiElement element = _node.getPsi().getNextSibling();
|
||||
while (element instanceof PsiWhiteSpace) {
|
||||
element = element.getNextSibling();
|
||||
}
|
||||
if (element != null) {
|
||||
return false;
|
||||
if (!PsiTreeUtil.hasErrorElements(_node.getPsi())) {
|
||||
PsiElement element = _node.getPsi().getNextSibling();
|
||||
while (element instanceof PsiWhiteSpace) {
|
||||
element = element.getNextSibling();
|
||||
}
|
||||
if (element != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ASTNode lastChild = getLastNonSpaceChild(_node, false);
|
||||
@@ -619,21 +621,36 @@ public class PyBlock implements ASTBlock {
|
||||
}
|
||||
}
|
||||
if (lastChild.getElementType() == PyElementTypes.BINARY_EXPRESSION) {
|
||||
PyBinaryExpression binaryExpression = (PyBinaryExpression) lastChild.getPsi();
|
||||
PyBinaryExpression binaryExpression = (PyBinaryExpression)lastChild.getPsi();
|
||||
if (binaryExpression.getRightExpression() == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (isIncompleteCall(lastChild)) return true;
|
||||
}
|
||||
|
||||
if (_node.getPsi() instanceof PyArgumentList) {
|
||||
final PyArgumentList argumentList = (PyArgumentList)_node.getPsi();
|
||||
return argumentList.getClosingParen() == null;
|
||||
}
|
||||
if (isIncompleteCall(_node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isIncompleteCall(ASTNode node) {
|
||||
if (node.getElementType() == PyElementTypes.CALL_EXPRESSION) {
|
||||
PyCallExpression callExpression = (PyCallExpression)node.getPsi();
|
||||
PyArgumentList argumentList = callExpression.getArgumentList();
|
||||
if (argumentList == null || argumentList.getClosingParen() == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLeaf() {
|
||||
return _node.getFirstChildNode() == null;
|
||||
}
|
||||
|
||||
@@ -333,4 +333,16 @@ public class PyIndentTest extends PyTestCase {
|
||||
" <caret>= [a,\n" +
|
||||
" b]");
|
||||
}
|
||||
|
||||
public void testAlignInIncompleteCall() { // PY-6360
|
||||
doTest("q = query.Nested(query.Term(\"type\", \"class\"),<caret>\n" +
|
||||
"\n" +
|
||||
"def bar():\n" +
|
||||
" print('hello')",
|
||||
"q = query.Nested(query.Term(\"type\", \"class\"),\n" +
|
||||
" <caret>\n" +
|
||||
"\n" +
|
||||
"def bar():\n" +
|
||||
" print('hello')");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user