Hanging indent detection takes into account named parameters and default values of arguments

This commit is contained in:
Mikhail Golubev
2015-04-23 22:06:22 +03:00
parent efc43fbd53
commit 5181eedd3d
6 changed files with 34 additions and 1 deletions
@@ -398,7 +398,16 @@ public class PyBlock implements ASTBlock {
return !PyTokenTypes.CLOSE_BRACES.contains(elem.getLastChild().getNode().getElementType());
}
else {
return hasHangingIndent(items[0]);
final PsiElement firstItem = items[0];
if (firstItem instanceof PyNamedParameter) {
final PyExpression defaultValue = ((PyNamedParameter)firstItem).getDefaultValue();
return defaultValue != null && hasHangingIndent(defaultValue);
}
else if (firstItem instanceof PyKeywordArgument) {
final PyExpression valueExpression = ((PyKeywordArgument)firstItem).getValueExpression();
return valueExpression != null && hasHangingIndent(valueExpression);
}
return hasHangingIndent(firstItem);
}
}
else {
@@ -0,0 +1,3 @@
funcWithLongName(x=[
],
y=42)
@@ -0,0 +1,3 @@
funcWithLongName(x=[
],
y=42)
@@ -0,0 +1,5 @@
def funcWithLongName(x=[
],
y=42):
pass
@@ -0,0 +1,5 @@
def funcWithLongName(x=[
],
y=42):
pass
@@ -546,6 +546,14 @@ public class PyFormatterTest extends PyTestCase {
doTest();
}
public void testHangingIndentInNamedArgumentValue() {
doTest();
}
public void testHangingIndentInParameterDefaultValue() {
doTest();
}
private CommonCodeStyleSettings getCommonSettings() {
return settings().getCommonSettings(PythonLanguage.getInstance());
}