Skip to content

Commit

Permalink
Fix indent_continue not indenting nested statements
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartolini committed Aug 22, 2022
1 parent 771b9cc commit 2adf01c
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/indent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,9 @@ void indent_text()
}
log_indent();

if ( pc->level == pc->brace_level
if ( ( pc->level == pc->brace_level // Issue #3752
|| ( pc->level > pc->brace_level
&& !language_is_set(LANG_OC)))
&& !options::indent_ignore_first_continue()
&& ( pc->Is(CT_FPAREN_OPEN)
|| pc->Is(CT_SPAREN_OPEN)
Expand Down
8 changes: 8 additions & 0 deletions tests/config/cpp/Issue_3752.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
input_tab_size = 4
output_tab_size = 4
indent_columns = 4
indent_with_tabs = 0

indent_ignore_first_continue = false
indent_continue = 4

1 change: 1 addition & 0 deletions tests/cpp.test
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@
60086 cpp/indent_namespace_inner_only.cfg cpp/indent_namespace_inner_only.h
60087 cpp/Issue_3550.cfg cpp/Issue_3550.cpp
60088 common/empty.cfg cpp/Issue_3761.cpp
60089 cpp/Issue_3752.cfg cpp/Issue_3752.cpp

60100 cpp/indent_continue-0.cfg cpp/indent_continue.cpp
60101 cpp/indent_continue-4.cfg cpp/indent_continue.cpp
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/cpp/31593-sf593.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ int main()
{
int argument = 1;
sp_RatherLongClassName_t ratherLongVariableName1(new RatherLongClassName(argument,
argument, argument));
argument, argument));

int the_result = a_very_long_function_name_taking_most_of_the_line(argument,
argument, argument);
Expand Down
30 changes: 15 additions & 15 deletions tests/expected/cpp/60055-issue_3116.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ Func([] {

A(
B([] (const std::string &s) -> bool {
s = "hello";
return true;
}), 1
s = "hello";
return true;
}), 1
);

A(
Expand Down Expand Up @@ -149,24 +149,24 @@ A(
}

Func(std::count_if(v.begin(), v.end(), [&](const auto &a) {
return a == 3;
}));
return a == 3;
}));

Func(
std::count_if(v.begin(), v.end(), [&](const auto &a)
{
return a == 3;
}));
{
return a == 3;
}));

Func(
std::count_if(v.begin(), v.end(), [&](const auto &a) {
return a == 3;
}));
return a == 3;
}));

Func(
std::count_if(v.begin(), v.end(), [&](const auto &a) {
return a == 3;
})
return a == 3;
})
);

// Test case from issue #3116
Expand Down Expand Up @@ -227,7 +227,7 @@ obj->Func([]

obj->Func(
Func([]
{
return b;
})
{
return b;
})
);
32 changes: 16 additions & 16 deletions tests/expected/cpp/60056-issue_3116-2.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
obj.AddObject(Object::UniqueName(), 10, [this] {
holder.Access([this](const auto &info) {
if (IsGood(info)) {
Add(info);
}
});
if (IsGood(info)) {
Add(info);
}
});
});

obj.AddObject(
Object::UniqueName(),
10,
[this] {
holder.Access([this](const auto &info) {
if (IsGood(info)) {
Add(info);
}
});
if (IsGood(info)) {
Add(info);
}
});
}
);

{
obj.AddObject(Object::UniqueName(), 10, [this] {
holder.Access([this](const auto &info) {
if (IsGood(info)) {
Add(info);
}
});
if (IsGood(info)) {
Add(info);
}
});
});

obj.AddObject(
Object::UniqueName(),
10,
[this] {
holder.Access([this](const auto &info) {
if (IsGood(info)) {
Add(info);
}
});
if (IsGood(info)) {
Add(info);
}
});
}
);
}
59 changes: 59 additions & 0 deletions tests/expected/cpp/60089-Issue_3752.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
foo(
1
);

foo(bar(
1
)
);

foo(bar(baz(
1)
)
);

foo(bar(
baz(
1)
)
);

foo(
bar(baz(
1)
)
);

foo(
bar(
baz(
1)
)
);

foo(
1,
bar(
2,
baz(
3
)
)
);

foo(1,
bar(2,
3
)
);

namespace ns
{
foo(1
, 2
, [](a, b) {
bar(3
, 4
);
});
}
59 changes: 59 additions & 0 deletions tests/input/cpp/Issue_3752.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
foo(
1
);

foo(bar(
1
)
);

foo(bar(baz(
1)
)
);

foo(bar(
baz(
1)
)
);

foo(
bar(baz(
1)
)
);

foo(
bar(
baz(
1)
)
);

foo(
1,
bar(
2,
baz(
3
)
)
);

foo(1,
bar(2,
3
)
);

namespace ns
{
foo(1
, 2
, [](a, b) {
bar(3
, 4
);
});
}

0 comments on commit 2adf01c

Please sign in to comment.