Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indent_continue not indenting nested statements #3816

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/indent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,6 @@ void indent_text()
&& frm.at(sub).pc->IsOnSameLine(frm.top().pc))
{
sub--;
skipped = true;
}

if ( ( frm.at(sub + 1).type == CT_CLASS_COLON
Expand All @@ -2844,7 +2843,6 @@ void indent_text()
log_indent();

frm.top().indent_tab = frm.top().indent;
skipped = true;
}
else
{
Expand Down Expand Up @@ -2918,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
1 change: 1 addition & 0 deletions tests/config/cpp/Issue_3428.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ indent_columns = 4
indent_with_tabs = 0
indent_continue = 4
indent_paren_close = 2
use_indent_continue_only_once = true
1 change: 1 addition & 0 deletions tests/config/cpp/Issue_3428_2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ indent_columns = 4
indent_with_tabs = 0
indent_continue = 4
indent_paren_close = 2
use_indent_continue_only_once = true
1 change: 1 addition & 0 deletions tests/config/cpp/Issue_3428_3.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ indent_columns = 4
indent_with_tabs = 0
indent_continue = 4
indent_paren_close = 2
use_indent_continue_only_once = true
1 change: 1 addition & 0 deletions tests/config/cpp/Issue_3428_4.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ indent_columns = 4
indent_with_tabs = 0
indent_continue = 4
indent_paren_close = 2
use_indent_continue_only_once = true
1 change: 1 addition & 0 deletions tests/config/cpp/Issue_3428_5.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ indent_columns = 4
indent_with_tabs = 0
indent_continue = 4
indent_paren_close = 2
use_indent_continue_only_once = true
1 change: 1 addition & 0 deletions tests/config/cpp/Issue_3428_6.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ indent_columns = 4
indent_with_tabs = 0
indent_continue = 4
indent_paren_close = 2
use_indent_continue_only_once = true
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

3 changes: 3 additions & 0 deletions tests/config/cpp/indent_continue-0.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
indent_with_tabs = 0
indent_columns = 2
indent_continue = 0
4 changes: 4 additions & 0 deletions tests/config/cpp/indent_continue-4.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
indent_with_tabs = 0
indent_columns = 2
indent_continue = 4
use_indent_continue_only_once = true
3 changes: 3 additions & 0 deletions tests/config/cpp/indent_continue-neg-4.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
indent_with_tabs = 0
indent_columns = 2
indent_continue = -4
5 changes: 5 additions & 0 deletions tests/cpp.test
Original file line number Diff line number Diff line change
Expand Up @@ -1125,3 +1125,8 @@
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
60102 cpp/indent_continue-neg-4.cfg cpp/indent_continue.cpp
12 changes: 6 additions & 6 deletions tests/expected/cpp/30818-bug_1169.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ class MyClass
virtual void f1ooooooooooooooo(const int bar);
virtual void f2oooooooooooooooo(const int bar);
virtual void f3ooooooooooooooooo(
const int bar);
const int bar);
virtual void f4oooooooooooooooooo(
const int bar);
const int bar);
virtual void f5ooooooooooooooooooo(
const int bar);
const int bar);
};

virtual void f1oooooooooooooooooo(const int bar);
virtual void f2ooooooooooooooooooo(const int bar);
virtual void f3oooooooooooooooooooo(
const int bar);
const int bar);
virtual void f4ooooooooooooooooooooo(
const int bar);
const int bar);
virtual void f5oooooooooooooooooooooo(
const int bar);
const int bar);

void foo()
{
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
);
});
}
43 changes: 43 additions & 0 deletions tests/expected/cpp/60100-indent_continue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fn(p1,
p2
);

fn(
p1,
p2
);

x = fn(p1,
p2
);

x = fn(
p1,
p2
);

while (x &&
y
)
{
}

while (
x && y
)
{
}

fn(jk(
p1,
p2
)
);

fn(
jk(
p1,
p2
)
);

43 changes: 43 additions & 0 deletions tests/expected/cpp/60101-indent_continue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fn(p1,
p2
);

fn(
p1,
p2
);

x = fn(p1,
p2
);

x = fn(
p1,
p2
);

while (x &&
y
)
{
}

while (
x && y
)
{
}

fn(jk(
p1,
p2
)
);

fn(
jk(
p1,
p2
)
);