Skip to content

Commit

Permalink
Fixed inner spacing for declarations parentheses
Browse files Browse the repository at this point in the history
Fixes #1688
  • Loading branch information
hurricup committed Dec 28, 2017
1 parent ad47053 commit 043cad3
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ public interface PerlFormattingTokenSets extends PerlElementTypes {
REGEX_EXPR
);

TokenSet PARENTHESISED_LIKE_EXPRESSIONS = TokenSet.create(
PARENTHESISED_EXPR,
VARIABLE_DECLARATION_LOCAL,
VARIABLE_DECLARATION_LEXICAL,
VARIABLE_DECLARATION_GLOBAL
TokenSet PARENTHESISED_LIKE_EXPRESSIONS = TokenSet.orSet(
TokenSet.create(PARENTHESISED_EXPR),
VARIABLE_DECLARATIONS
);

TokenSet OPERATORS_ASSIGNMENT = TokenSet.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import static com.perl5.lang.perl.idea.formatter.PerlFormattingContext.BLOCK_CLOSERS;
import static com.perl5.lang.perl.idea.formatter.PerlFormattingContext.BLOCK_OPENERS;
import static com.perl5.lang.perl.idea.formatter.PerlFormattingTokenSets.VARIABLE_DECLARATIONS;
import static com.perl5.lang.perl.lexer.PerlTokenSets.HEREDOC_BODIES_TOKENSET;

/**
Expand Down Expand Up @@ -152,6 +153,10 @@ public Indent getNodeIndent(@NotNull ASTNode node) {
return Indent.getNoneIndent();
}

if (VARIABLE_DECLARATIONS.contains(parentNodeType) && ( nodeType == LEFT_PAREN || nodeType == RIGHT_PAREN )) {
return Indent.getNoneIndent();
}

boolean forceFirstIndent = false;
if (HEREDOC_BODIES_TOKENSET.contains(nodeType)) {
PsiElement psi = node.getPsi();
Expand Down
1 change: 1 addition & 0 deletions test/formatter/PerlFormatterSpacingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected String getTestDataPath() {
return "testData/formatter/perl/spacing";
}

public void testIssue1688() {doFormatTest();}

public void testQwQuotesAndContent() {doFormatTest();}

Expand Down
45 changes: 45 additions & 0 deletions testData/formatter/perl/spacing/issue1688.code
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
my (
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;

our (
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;

local (
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;

state (
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;


my
(
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;

our
(
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;

local
(
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;

state
(
$rOpts , $logger_object , $config_file ,
$rraw_options , $Windows_type , $readable_options
) = @_;

43 changes: 43 additions & 0 deletions testData/formatter/perl/spacing/issue1688.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
my (
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

our (
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

local (
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

state (
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

my
(
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

our
(
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

local
(
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

state
(
$rOpts, $logger_object, $config_file,
$rraw_options, $Windows_type, $readable_options
) = @_;

0 comments on commit 043cad3

Please sign in to comment.