mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-33060 custom wrapping modes for arguments
close #1490 GitOrigin-RevId: f882df71e9d221f5a1256e0675642ef9d8d963f1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f5d77d0c30
commit
a251e6a423
@@ -93,6 +93,7 @@ public class PyBlock implements ASTBlock {
|
||||
private Wrap myDictWrapping = null;
|
||||
private Wrap myFromImportWrapping = null;
|
||||
private Wrap myParameterListWrapping = null;
|
||||
private Wrap myArgumentListWrapping = null;
|
||||
|
||||
public PyBlock(@Nullable PyBlock parent,
|
||||
@NotNull ASTNode node,
|
||||
@@ -120,6 +121,9 @@ public class PyBlock implements ASTBlock {
|
||||
else if (node.getElementType() == PyElementTypes.PARAMETER_LIST) {
|
||||
myParameterListWrapping = Wrap.createWrap(settings.METHOD_PARAMETERS_WRAP, settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE);
|
||||
}
|
||||
else if (node.getElementType() == PyElementTypes.ARGUMENT_LIST) {
|
||||
myArgumentListWrapping = Wrap.createWrap(settings.CALL_PARAMETERS_WRAP, settings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -409,6 +413,12 @@ public class PyBlock implements ASTBlock {
|
||||
childType != PyTokenTypes.RPAR) {
|
||||
childWrap = myParameterListWrapping;
|
||||
}
|
||||
if (parentType == PyElementTypes.ARGUMENT_LIST &&
|
||||
childType != PyTokenTypes.COMMA &&
|
||||
childType != PyTokenTypes.LPAR &&
|
||||
childType != PyTokenTypes.RPAR) {
|
||||
childWrap = myArgumentListWrapping;
|
||||
}
|
||||
|
||||
if (isAfterStatementList(child) &&
|
||||
!hasLineBreaksBeforeInSameParent(child, 2) &&
|
||||
|
||||
@@ -97,6 +97,7 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin
|
||||
"WRAP_ON_TYPING",
|
||||
"KEEP_LINE_BREAKS",
|
||||
"WRAP_LONG_LINES",
|
||||
"CALL_PARAMETERS_WRAP",
|
||||
"CALL_PARAMETERS_LPAREN_ON_NEXT_LINE",
|
||||
"CALL_PARAMETERS_RPAREN_ON_NEXT_LINE",
|
||||
"ALIGN_MULTILINE_PARAMETERS",
|
||||
@@ -161,6 +162,7 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin
|
||||
// behavior
|
||||
commonSettings.KEEP_BLANK_LINES_IN_CODE = 1;
|
||||
commonSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
|
||||
commonSettings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -213,8 +215,7 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin
|
||||
"def xyzzy(a1, a2, long_parameter_1, a3, a4, long_parameter_2):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"xyzzy('long_string_constant1',\n" +
|
||||
" 'long_string_constant2')\n" +
|
||||
"xyzzy(1, 2, 'long_string_constant1', 3, 4, 'long_string_constant2')\n" +
|
||||
"\n" +
|
||||
"xyzzy(\n" +
|
||||
" 'with',\n" +
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
value = some_function("long_param1", "long_param2", "long_param3", long_kwarg1="with long value1", long_kwarg2="with long value2")
|
||||
@@ -0,0 +1,3 @@
|
||||
value = some_function("long_param1", "long_param2", "long_param3",
|
||||
long_kwarg1="with long value1",
|
||||
long_kwarg2="with long value2")
|
||||
@@ -0,0 +1 @@
|
||||
value = some_function("long_param1", "long_param2", "long_param3", long_kwarg1="with long value1", long_kwarg2="with long value2")
|
||||
@@ -0,0 +1,4 @@
|
||||
value = some_function(
|
||||
"long_param1", "long_param2", "long_param3", long_kwarg1="with long value1",
|
||||
long_kwarg2="with long value2"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
value = some_function("long_param1", "long_param2", "long_param3", long_kwarg1="with long value1", long_kwarg2="with long value2")
|
||||
@@ -0,0 +1,5 @@
|
||||
value = some_function("long_param1",
|
||||
"long_param2",
|
||||
"long_param3",
|
||||
long_kwarg1="with long value1",
|
||||
long_kwarg2="with long value2")
|
||||
@@ -0,0 +1 @@
|
||||
value = some_function("long_param1", "long_param2", "long_param3", long_kwarg1="with long value1", long_kwarg2="with long value2")
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
value = some_function(
|
||||
"long_param1",
|
||||
"long_param2",
|
||||
"long_param3",
|
||||
long_kwarg1="with long value1",
|
||||
long_kwarg2="with long value2"
|
||||
)
|
||||
@@ -190,6 +190,34 @@ public class PyFormatterTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDefaultWrappingForCallArguments() { // PY-33060
|
||||
getCodeStyleSettings().setRightMargin(PythonLanguage.getInstance(), 80);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDefaultWrappingWithNewLineParensForCallArguments() { // PY-33060
|
||||
getCodeStyleSettings().setRightMargin(PythonLanguage.getInstance(), 80);
|
||||
getCommonCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false;
|
||||
getCommonCodeStyleSettings().CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
|
||||
getCommonCodeStyleSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWrappingChopDownIfLongForCallArguments() { // PY-33060
|
||||
getCodeStyleSettings().setRightMargin(PythonLanguage.getInstance(), 80);
|
||||
getCommonCodeStyleSettings().CALL_PARAMETERS_WRAP = WrapType.CHOP_DOWN_IF_LONG.getLegacyRepresentation();
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWrappingChopDownIfLongWithNewLineParensForCallArguments() { // PY-33060
|
||||
getCodeStyleSettings().setRightMargin(PythonLanguage.getInstance(), 80);
|
||||
getCommonCodeStyleSettings().CALL_PARAMETERS_WRAP = WrapType.CHOP_DOWN_IF_LONG.getLegacyRepresentation();
|
||||
getCommonCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false;
|
||||
getCommonCodeStyleSettings().CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
|
||||
getCommonCodeStyleSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLambdaColon() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user