mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-33060 continuation indent for parameters
close #1490 GitOrigin-RevId: c0a7225913b73100dc479a0a3d96026f2a4dd465
This commit is contained in:
committed by
intellij-monorepo-bot
parent
09c9c2ca26
commit
c5d3bc5e3f
@@ -551,6 +551,7 @@ formatter.panel.dict.alignment.label=Dict alignment:
|
||||
formatter.panel.add.trailing.line.feed=Add line feed at the end of file
|
||||
|
||||
formatter.panel.use.continuation.indent.for.title=Use continuation indent for
|
||||
formatter.panel.use.continuation.indent.for.parameters=Method declaration parameters
|
||||
formatter.panel.use.continuation.indent.for.arguments=Method call arguments
|
||||
formatter.panel.use.continuation.indent.for.collection.literals=Collections and comprehensions
|
||||
|
||||
|
||||
@@ -358,8 +358,8 @@ public class PyBlock implements ASTBlock {
|
||||
if (childType == PyTokenTypes.RPAR && !settings.HANG_CLOSING_BRACKETS) {
|
||||
childIndent = Indent.getNoneIndent();
|
||||
}
|
||||
else if (parentType == PyElementTypes.PARAMETER_LIST ||
|
||||
settings.USE_CONTINUATION_INDENT_FOR_ARGUMENTS ||
|
||||
else if ((parentType == PyElementTypes.PARAMETER_LIST && settings.USE_CONTINUATION_INDENT_FOR_PARAMETERS) ||
|
||||
(parentType == PyElementTypes.ARGUMENT_LIST && settings.USE_CONTINUATION_INDENT_FOR_ARGUMENTS) ||
|
||||
argumentMayHaveSameIndentAsFollowingStatementList()) {
|
||||
childIndent = Indent.getContinuationIndent();
|
||||
}
|
||||
@@ -1074,7 +1074,7 @@ public class PyBlock implements ASTBlock {
|
||||
final IElementType parentType = myNode.getElementType();
|
||||
// constructs that imply indent for their children
|
||||
final PyCodeStyleSettings settings = myContext.getPySettings();
|
||||
if (parentType == PyElementTypes.PARAMETER_LIST ||
|
||||
if ((parentType == PyElementTypes.PARAMETER_LIST && settings.USE_CONTINUATION_INDENT_FOR_PARAMETERS) ||
|
||||
(parentType == PyElementTypes.ARGUMENT_LIST && settings.USE_CONTINUATION_INDENT_FOR_ARGUMENTS)) {
|
||||
return Indent.getContinuationIndent();
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public class PyCodeStyleSettings extends CustomCodeStyleSettings {
|
||||
* (as long as they're multiple of 4), though examples in PEP 8 itself use mostly normal indent. Nonetheless, some users prefer to have
|
||||
* the same indentation level for arguments as for parameters.
|
||||
*/
|
||||
public boolean USE_CONTINUATION_INDENT_FOR_PARAMETERS = true;
|
||||
public boolean USE_CONTINUATION_INDENT_FOR_ARGUMENTS = false;
|
||||
public boolean USE_CONTINUATION_INDENT_FOR_COLLECTION_AND_COMPREHENSIONS = false;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="7c517" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="7c517" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -72,9 +72,17 @@
|
||||
<text resource-bundle="messages/PyBundle" key="formatter.panel.use.continuation.indent.for.arguments"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6f4f2" class="com.intellij.ui.components.JBCheckBox" binding="myUseContinuationIndentForParameters" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/PyBundle" key="formatter.panel.use.continuation.indent.for.parameters"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="44647" class="com.intellij.ui.components.JBCheckBox" binding="myUseContinuationIndentForCollectionsAndComprehensions">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/PyBundle" key="formatter.panel.use.continuation.indent.for.collection.literals"/>
|
||||
|
||||
@@ -43,6 +43,7 @@ public class PyOtherCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
|
||||
private JPanel myPanel;
|
||||
private JBCheckBox myAddTrailingBlankLineCheckbox;
|
||||
private JBCheckBox myUseContinuationIndentForParameters;
|
||||
private JBCheckBox myUseContinuationIndentForArguments;
|
||||
private JBCheckBox myUseContinuationIndentForCollectionsAndComprehensions;
|
||||
private ComboBox myDictAlignmentCombo;
|
||||
@@ -74,6 +75,13 @@ public class PyOtherCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
}
|
||||
});
|
||||
|
||||
myUseContinuationIndentForParameters.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
somethingChanged();
|
||||
}
|
||||
});
|
||||
|
||||
myUseContinuationIndentForArguments.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -113,6 +121,7 @@ public class PyOtherCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
}
|
||||
}
|
||||
myAddTrailingBlankLineCheckbox.setSelected(pySettings.BLANK_LINE_AT_FILE_END);
|
||||
myUseContinuationIndentForParameters.setSelected(pySettings.USE_CONTINUATION_INDENT_FOR_PARAMETERS);
|
||||
myUseContinuationIndentForArguments.setSelected(pySettings.USE_CONTINUATION_INDENT_FOR_ARGUMENTS);
|
||||
myUseContinuationIndentForCollectionsAndComprehensions.setSelected(pySettings.USE_CONTINUATION_INDENT_FOR_COLLECTION_AND_COMPREHENSIONS);
|
||||
}
|
||||
@@ -122,6 +131,7 @@ public class PyOtherCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
final PyCodeStyleSettings customSettings = getCustomSettings(settings);
|
||||
customSettings.DICT_ALIGNMENT = getDictAlignmentAsInt();
|
||||
customSettings.BLANK_LINE_AT_FILE_END = ensureTrailingBlankLine();
|
||||
customSettings.USE_CONTINUATION_INDENT_FOR_PARAMETERS = useContinuationIndentForParameters();
|
||||
customSettings.USE_CONTINUATION_INDENT_FOR_ARGUMENTS = useContinuationIndentForArguments();
|
||||
customSettings.USE_CONTINUATION_INDENT_FOR_COLLECTION_AND_COMPREHENSIONS = useContinuationIndentForCollectionLiterals();
|
||||
}
|
||||
@@ -131,6 +141,7 @@ public class PyOtherCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
final PyCodeStyleSettings customSettings = getCustomSettings(settings);
|
||||
return customSettings.DICT_ALIGNMENT != getDictAlignmentAsInt() ||
|
||||
customSettings.BLANK_LINE_AT_FILE_END != ensureTrailingBlankLine() ||
|
||||
customSettings.USE_CONTINUATION_INDENT_FOR_PARAMETERS != useContinuationIndentForParameters() ||
|
||||
customSettings.USE_CONTINUATION_INDENT_FOR_ARGUMENTS != useContinuationIndentForArguments() ||
|
||||
customSettings.USE_CONTINUATION_INDENT_FOR_COLLECTION_AND_COMPREHENSIONS != useContinuationIndentForCollectionLiterals();
|
||||
}
|
||||
@@ -153,6 +164,10 @@ public class PyOtherCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
return myAddTrailingBlankLineCheckbox.isSelected();
|
||||
}
|
||||
|
||||
private boolean useContinuationIndentForParameters() {
|
||||
return myUseContinuationIndentForParameters.isSelected();
|
||||
}
|
||||
|
||||
private boolean useContinuationIndentForArguments() {
|
||||
return myUseContinuationIndentForArguments.isSelected();
|
||||
}
|
||||
@@ -166,6 +181,12 @@ public class PyOtherCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
" 2,\n" +
|
||||
" 3)\n" +
|
||||
"\n" +
|
||||
"def foo_decl(\n" +
|
||||
" a,\n" +
|
||||
" b,\n" +
|
||||
" c):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"{\n" +
|
||||
" \"green\": 42,\n" +
|
||||
" \"eggs and ham\": -0.0e0\n" +
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
def foo_decl1(
|
||||
a,
|
||||
b, c,
|
||||
d,
|
||||
):
|
||||
pass
|
||||
|
||||
def foo_decl2(
|
||||
a,
|
||||
b, c,
|
||||
d):
|
||||
pass
|
||||
@@ -0,0 +1,13 @@
|
||||
def foo_decl1(
|
||||
a,
|
||||
b, c,
|
||||
d,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def foo_decl2(
|
||||
a,
|
||||
b, c,
|
||||
d):
|
||||
pass
|
||||
@@ -0,0 +1,12 @@
|
||||
def foo_decl1(
|
||||
a,
|
||||
b, c,
|
||||
d,
|
||||
):
|
||||
pass
|
||||
|
||||
def foo_decl2(
|
||||
a,
|
||||
b, c,
|
||||
d):
|
||||
pass
|
||||
@@ -0,0 +1,13 @@
|
||||
def foo_decl1(
|
||||
a,
|
||||
b, c,
|
||||
d,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def foo_decl2(
|
||||
a,
|
||||
b, c,
|
||||
d):
|
||||
pass
|
||||
@@ -660,6 +660,17 @@ public class PyFormatterTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-33060
|
||||
public void testContinuationIndentBeforeFunctionParameters() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-33060
|
||||
public void testNoContinuationIndentBeforeFunctionParameters() {
|
||||
getPythonCodeStyleSettings().USE_CONTINUATION_INDENT_FOR_PARAMETERS = false;
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-17979, PY-13304
|
||||
public void testContinuationIndentBeforeFunctionArguments() {
|
||||
getPythonCodeStyleSettings().USE_CONTINUATION_INDENT_FOR_ARGUMENTS = true;
|
||||
|
||||
Reference in New Issue
Block a user