mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
PY-22272 Don't use brackets of indexed dict values for alignment
In general, don't apply this special casing if dict value doesn't start with a bracket.
This commit is contained in:
@@ -390,12 +390,11 @@ public class PyBlock implements ASTBlock {
|
||||
}
|
||||
|
||||
if (settings.DICT_ALIGNMENT == DICT_ALIGNMENT_ON_VALUE) {
|
||||
if (isValueOfKeyValuePairOfDictLiteral(child) && !ourListElementTypes.contains(childType)) {
|
||||
// Align not the whole value but its left bracket if it starts with it
|
||||
if (isValueOfKeyValuePairOfDictLiteral(child) && !isOpeningBracket(child.getFirstChildNode())) {
|
||||
childAlignment = myParent.myDictAlignment;
|
||||
}
|
||||
else if (isValueOfKeyValuePairOfDictLiteral(myNode) &&
|
||||
ourListElementTypes.contains(parentType) &&
|
||||
PyTokenTypes.OPEN_BRACES.contains(childType)) {
|
||||
else if (isValueOfKeyValuePairOfDictLiteral(myNode) && isOpeningBracket(child)) {
|
||||
childAlignment = myParent.myParent.myDictAlignment;
|
||||
}
|
||||
}
|
||||
@@ -419,6 +418,10 @@ public class PyBlock implements ASTBlock {
|
||||
return new PyBlock(this, child, childAlignment, childIndent, childWrap, myContext);
|
||||
}
|
||||
|
||||
private static boolean isOpeningBracket(@Nullable ASTNode node) {
|
||||
return node != null && PyTokenTypes.OPEN_BRACES.contains(node.getElementType()) && node == node.getTreeParent().getFirstChildNode();
|
||||
}
|
||||
|
||||
private static boolean isValueOfKeyValuePairOfDictLiteral(@NotNull ASTNode node) {
|
||||
return isValueOfKeyValuePair(node) && isChildOfDictLiteral(node.getTreeParent());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
my_dict = {
|
||||
"one": example_list[0],
|
||||
"two": example_list[1],
|
||||
"three": example_list[2:3],
|
||||
"some really long element name that takes a lot of space": "four"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
my_dict = {
|
||||
"one": example_list[0],
|
||||
"two": example_list[1],
|
||||
"three": example_list[2:3],
|
||||
"some really long element name that takes a lot of space": "four"
|
||||
}
|
||||
@@ -603,6 +603,12 @@ public class PyFormatterTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-22272
|
||||
public void testAlightDictLiteralOnValueSubscriptionsAndSlices() {
|
||||
getPythonCodeStyleSettings().DICT_ALIGNMENT = PyCodeStyleSettings.DICT_ALIGNMENT_ON_VALUE;
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-14962
|
||||
public void testAlignDictLiteralOnColon() {
|
||||
getPythonCodeStyleSettings().DICT_ALIGNMENT = PyCodeStyleSettings.DICT_ALIGNMENT_ON_COLON;
|
||||
|
||||
Reference in New Issue
Block a user