diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 29713f5f6c..df7416285b 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -51,10 +51,10 @@
  • aligning comments inside lists, enabled by default, #1676
  • wrapping and alignment of ternary expression
  • wrapping and alignment of variable declarations lists
  • +
  • wrapping and alignment of qw lists elements
  • Formatting for anon subs, hashes, arrays and lists is much better now, by @aptituz
  • qw list is now formatted like a block, meaning quotes being formatted same way as braces, #1678
  • -
  • qw contents is now wrapped on long lines string or closing quote may be moved to the next line
  • Fixes: diff --git a/resources/codeStyle/preview/wrapping.code b/resources/codeStyle/preview/wrapping.code index 91e330fb13..f9e3a3abed 100644 --- a/resources/codeStyle/preview/wrapping.code +++ b/resources/codeStyle/preview/wrapping.code @@ -25,8 +25,7 @@ if($a){ my @list = qw/ this is a list - of some cool strings - /; + of some cool strings which should be wrapped somehow /; say $a == 42 ? 'long true' : 'long expression meaning false'; $a ? $a : $b; diff --git a/resources/messages/PerlBundle.properties b/resources/messages/PerlBundle.properties index de776993f2..59602ef60b 100644 --- a/resources/messages/PerlBundle.properties +++ b/resources/messages/PerlBundle.properties @@ -149,14 +149,13 @@ perl.formatting.sub.signature=Sub signature/prototype perl.formatting.signature.parentheses=Sub signature/prototype parentheses perl.formatting.empty.signature.parentheses=Empty sub signature/prototype parentheses perl.formatting.attribute=Before sub attribute -perl.formatting.group.alignment=Alignment perl.formatting.align.list.elements=Comma-separated list perl.formatting.wrap.dereference=Chained dereference perl.formatting.align.comments.in.list=Align in lists perl.formatting.align.fat.comma=Align fat commas -perl.formatting.align.qw.elements=qw// elements +perl.formatting.align.qw.elements=Align elements perl.formatting.align.ternary=? and : in ternary expression -perl.formatting.space.inside.qw=qw// list +perl.qw.list=qw// list perl.formatting.after.my=After my/our/local/state perl.formatting.within.hash=Anon hash perl.formatting.within.array=Anon array diff --git a/src/com/perl5/lang/perl/idea/formatter/PerlFormattingContext.java b/src/com/perl5/lang/perl/idea/formatter/PerlFormattingContext.java index 6f63c3fba1..9712f5b5f8 100644 --- a/src/com/perl5/lang/perl/idea/formatter/PerlFormattingContext.java +++ b/src/com/perl5/lang/perl/idea/formatter/PerlFormattingContext.java @@ -411,7 +411,7 @@ else if (parentNodeType == COMMA_SEQUENCE_EXPR && childNodeType != COMMA && chil } else if (( parentNodeType == STRING_LIST || parentNodeType == LP_STRING_QW) && ( childNodeType == STRING_CONTENT || childNodeType == QUOTE_SINGLE_CLOSE)) { - return getWrap(parentNode, NORMAL, false); + return getWrapBySettings(parentNode, myPerlSettings.QW_LIST_WRAP, false); } else if (childNodeType == VARIABLE_DECLARATION_ELEMENT || ( childNodeType == RESERVED_UNDEF && VARIABLE_DECLARATIONS.contains(parentNodeType) )) { diff --git a/src/com/perl5/lang/perl/idea/formatter/settings/PerlCodeStyleSettings.java b/src/com/perl5/lang/perl/idea/formatter/settings/PerlCodeStyleSettings.java index 75984626bb..3e5cdc345f 100644 --- a/src/com/perl5/lang/perl/idea/formatter/settings/PerlCodeStyleSettings.java +++ b/src/com/perl5/lang/perl/idea/formatter/settings/PerlCodeStyleSettings.java @@ -54,7 +54,10 @@ public class PerlCodeStyleSettings extends CustomCodeStyleSettings { public boolean SPACE_BEFORE_ATTRIBUTE = true; public boolean ALIGN_FAT_COMMA = true; + + public int QW_LIST_WRAP = DO_NOT_WRAP; public boolean ALIGN_QW_ELEMENTS = false; + public boolean ALIGN_COMMENTS_IN_LIST = true; public int BRACE_STYLE_NAMESPACE = SAME_LINE; diff --git a/src/com/perl5/lang/perl/idea/formatter/settings/PerlLanguageCodeStyleSettingsProvider.java b/src/com/perl5/lang/perl/idea/formatter/settings/PerlLanguageCodeStyleSettingsProvider.java index 66055e2058..f52017fd12 100644 --- a/src/com/perl5/lang/perl/idea/formatter/settings/PerlLanguageCodeStyleSettingsProvider.java +++ b/src/com/perl5/lang/perl/idea/formatter/settings/PerlLanguageCodeStyleSettingsProvider.java @@ -39,7 +39,7 @@ * Created by hurricup on 03.09.2015. */ public class PerlLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider { - private static final String GROUP_ALIGNMENT = PerlBundle.message("perl.formatting.group.alignment"); + private static final String GROUP_QW = PerlBundle.message("perl.qw.list"); private static final String GROUP_QUOTATION = PerlBundle.message("perl.formatting.group.optional.quotation"); private static final String GROUP_DEREFERENCE = PerlBundle.message("perl.formatting.group.dereferencing"); private static final String GROUP_PARENTHESES = PerlBundle.message("perl.formatting.group.optional.parentheses"); @@ -143,7 +143,7 @@ public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @ consumer.showCustomOption(PerlCodeStyleSettings.class, "SPACE_WITHIN_QW_QUOTES", - PerlBundle.message("perl.formatting.space.inside.qw"), + PerlBundle.message("perl.qw.list"), SPACES_WITHIN); } else if (settingsType == WRAPPING_AND_BRACES_SETTINGS) { @@ -223,10 +223,18 @@ else if (settingsType == WRAPPING_AND_BRACES_SETTINGS) { PerlBundle.message("perl.formatting.align.fat.comma"), GROUP_LIST); + consumer.showCustomOption(PerlCodeStyleSettings.class, + "QW_LIST_WRAP", + GROUP_QW, + null, + AFTER, "ARRAY_INITIALIZER_WRAP", + WRAP_OPTIONS, WRAP_VALUES + ); consumer.showCustomOption(PerlCodeStyleSettings.class, "ALIGN_QW_ELEMENTS", PerlBundle.message("perl.formatting.align.qw.elements"), - GROUP_ALIGNMENT); + GROUP_QW); + } else if (settingsType == LANGUAGE_SPECIFIC) { diff --git a/test/formatter/PerlFormatterWrapTest.java b/test/formatter/PerlFormatterWrapTest.java index 21e714916a..570ffb8308 100644 --- a/test/formatter/PerlFormatterWrapTest.java +++ b/test/formatter/PerlFormatterWrapTest.java @@ -152,7 +152,26 @@ private void doTestTernary(int wrapType, boolean signNewLine) { doWrappingTestSingleSource("ternary"); } - public void testQwWrapping() {doFormatTest();} + public void testQwListNever() { + doTestQwList(DO_NOT_WRAP); + } + + public void testQwListAlways() { + doTestQwList(WRAP_ALWAYS); + } + + public void testQwListLong() { + doTestQwList(WRAP_AS_NEEDED); + } + + public void testQwListChomp() { + doTestQwList(WRAP_ON_EVERY_ITEM); + } + + private void doTestQwList(int wrapType) { + getCustomSettings().QW_LIST_WRAP = wrapType; + doWrappingTestSingleSource("qwList"); + } public void testCommentsWrapTrue() { diff --git a/testData/formatter/perl/spacing/spacingInQwFalse.txt b/testData/formatter/perl/spacing/spacingInQwFalse.txt index e5d698a951..b27883adb4 100644 --- a/testData/formatter/perl/spacing/spacingInQwFalse.txt +++ b/testData/formatter/perl/spacing/spacingInQwFalse.txt @@ -1,3 +1,2 @@ qw/some string here/; -qw/some string here some string here some string here some string here some string here some string here some string - here/; \ No newline at end of file +qw/some string here some string here some string here some string here some string here some string here some string here/; \ No newline at end of file diff --git a/testData/formatter/perl/spacing/spacingInQwTrue.txt b/testData/formatter/perl/spacing/spacingInQwTrue.txt index daaaef9c01..b5c6efb467 100644 --- a/testData/formatter/perl/spacing/spacingInQwTrue.txt +++ b/testData/formatter/perl/spacing/spacingInQwTrue.txt @@ -1,3 +1,2 @@ qw/ some string here /; -qw/ some string here some string here some string here some string here some string here some string here some string - here /; \ No newline at end of file +qw/ some string here some string here some string here some string here some string here some string here some string here /; \ No newline at end of file diff --git a/testData/formatter/perl/wrap/qwList.code b/testData/formatter/perl/wrap/qwList.code new file mode 100644 index 0000000000..b5e8770715 --- /dev/null +++ b/testData/formatter/perl/wrap/qwList.code @@ -0,0 +1,11 @@ +# Lazy +my @list = qw/ + this is a list + of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings/; + +my @list = qw/ + this is a list + of different strings this /; + +my @list = qw/ + this is a /; \ No newline at end of file diff --git a/testData/formatter/perl/wrap/qwListAlways.txt b/testData/formatter/perl/wrap/qwListAlways.txt new file mode 100644 index 0000000000..a4a13cf731 --- /dev/null +++ b/testData/formatter/perl/wrap/qwListAlways.txt @@ -0,0 +1,75 @@ +# Lazy +my @list = qw/ + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings/; + +my @list = qw/ + this + is + a + list + of + different + strings + this +/; + +my @list = qw/ + this + is + a +/; \ No newline at end of file diff --git a/testData/formatter/perl/wrap/qwListChomp.txt b/testData/formatter/perl/wrap/qwListChomp.txt new file mode 100644 index 0000000000..ed4cbe6029 --- /dev/null +++ b/testData/formatter/perl/wrap/qwListChomp.txt @@ -0,0 +1,72 @@ +# Lazy +my @list = qw/ + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings + this + is + a + list + of + different + strings/; + +my @list = qw/ + this + is + a + list + of + different + strings + this +/; + +my @list = qw/ + this is a/; \ No newline at end of file diff --git a/testData/formatter/perl/wrap/qwListLong.txt b/testData/formatter/perl/wrap/qwListLong.txt new file mode 100644 index 0000000000..671a9ff47d --- /dev/null +++ b/testData/formatter/perl/wrap/qwListLong.txt @@ -0,0 +1,37 @@ +# Lazy +my @list = qw/ + this is a + list + of different + strings this + is a list of + different + strings this + is a list of + different + strings this + is a list of + different + strings this + is a list of + different + strings this + is a list of + different + strings this + is a list of + different + strings this + is a list of + different + strings/; + +my @list = qw/ + this is a + list + of different + strings this +/; + +my @list = qw/ + this is a/; \ No newline at end of file diff --git a/testData/formatter/perl/wrap/qwListNever.txt b/testData/formatter/perl/wrap/qwListNever.txt new file mode 100644 index 0000000000..889d6b9e37 --- /dev/null +++ b/testData/formatter/perl/wrap/qwListNever.txt @@ -0,0 +1,11 @@ +# Lazy +my @list = qw/ + this is a list + of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings/; + +my @list = qw/ + this is a list + of different strings this/; + +my @list = qw/ + this is a/; \ No newline at end of file diff --git a/testData/formatter/perl/wrap/qwWrapping.code b/testData/formatter/perl/wrap/qwWrapping.code deleted file mode 100644 index 138bd81b97..0000000000 --- a/testData/formatter/perl/wrap/qwWrapping.code +++ /dev/null @@ -1,6 +0,0 @@ -# Lazy -my @list = qw/ - this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings this is a list of different strings/; - -my @list = qw/ - this is a list of different strings this is a list of different strings this is a list of different strings this is af/; \ No newline at end of file diff --git a/testData/formatter/perl/wrap/qwWrapping.txt b/testData/formatter/perl/wrap/qwWrapping.txt deleted file mode 100644 index e024c99460..0000000000 --- a/testData/formatter/perl/wrap/qwWrapping.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Lazy -my @list = qw/ - this is a list of different strings this is a list of different strings this is a list of different strings this - is a list of different strings this is a list of different strings this is a list of different strings this is a - list of different strings this is a list of different strings/; - -my @list = qw/ - this is a list of different strings this is a list of different strings this is a list of different strings this - is af/; \ No newline at end of file