mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correctly check isIncomplete() for unclosed argument lists (PY-4863)
This commit is contained in:
@@ -488,17 +488,6 @@ public class PyBlock implements ASTBlock {
|
||||
}
|
||||
|
||||
return Indent.getNoneIndent();
|
||||
//return null;
|
||||
|
||||
/*
|
||||
Indent indent;
|
||||
if (isIncomplete()) {
|
||||
indent = Indent.getContinuationIndent();
|
||||
} else {
|
||||
indent = Indent.getNoneIndent();
|
||||
}
|
||||
return indent;
|
||||
*/
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -542,6 +531,11 @@ public class PyBlock implements ASTBlock {
|
||||
}
|
||||
}
|
||||
|
||||
if (_node.getPsi() instanceof PyArgumentList) {
|
||||
final PyArgumentList argumentList = (PyArgumentList)_node.getPsi();
|
||||
return argumentList.getClosingParen() == null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,4 +33,7 @@ public interface PyArgumentList extends PyElement {
|
||||
*/
|
||||
@NotNull
|
||||
CallArgumentsMapping analyzeCall(PyResolveContext resolveContext);
|
||||
|
||||
@Nullable
|
||||
ASTNode getClosingParen();
|
||||
}
|
||||
|
||||
@@ -130,9 +130,8 @@ public class PyArgumentListImpl extends PyElementImpl implements PyArgumentList
|
||||
}
|
||||
|
||||
private void addArgumentLastWithoutComma(PyExpression arg) {
|
||||
ASTNode node = getNode();
|
||||
ASTNode[] pars = node.getChildren(TokenSet.create(PyTokenTypes.RPAR));
|
||||
if (pars.length == 0) {
|
||||
ASTNode par = getClosingParen();
|
||||
if (par == null) {
|
||||
// there's no ending paren
|
||||
try {
|
||||
add(arg);
|
||||
@@ -143,10 +142,17 @@ public class PyArgumentListImpl extends PyElementImpl implements PyArgumentList
|
||||
|
||||
}
|
||||
else {
|
||||
node.addChild(arg.getNode(), pars[pars.length - 1]);
|
||||
getNode().addChild(arg.getNode(), par);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ASTNode getClosingParen() {
|
||||
ASTNode node = getNode();
|
||||
final ASTNode[] children = node.getChildren(TokenSet.create(PyTokenTypes.RPAR));
|
||||
return children.length == 0 ? null : children[children.length-1];
|
||||
}
|
||||
|
||||
private void addArgumentNode(PyExpression arg, ASTNode beforeThis, boolean commaFirst) {
|
||||
ASTNode comma = PyElementGenerator.getInstance(getProject()).createComma();
|
||||
ASTNode node = getNode();
|
||||
@@ -244,6 +250,4 @@ public class PyArgumentListImpl extends PyElementImpl implements PyArgumentList
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -192,6 +192,16 @@ public class PyIndentTest extends PyTestCase {
|
||||
" <caret>params=1)");
|
||||
}
|
||||
|
||||
public void testEnterInNonClosedArgList() { // PY-4863
|
||||
doTest("class C:\n" +
|
||||
" def new_method(self):\n" +
|
||||
" variable = self._stats.get('outer_key', 'inner_key',<caret>",
|
||||
"class C:\n" +
|
||||
" def new_method(self):\n" +
|
||||
" variable = self._stats.get('outer_key', 'inner_key',\n" +
|
||||
" <caret>");
|
||||
}
|
||||
|
||||
public void testEnterInSet() { // PY-1947
|
||||
doTest("test_set = {<caret>'some_value'}",
|
||||
"test_set = {\n" +
|
||||
|
||||
Reference in New Issue
Block a user