]> granicus.if.org Git - clang/commit
[clang-format] tweaked another case of lambda formatting
authorKrasimir Georgiev <krasimir@google.com>
Wed, 31 Oct 2018 17:56:57 +0000 (17:56 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Wed, 31 Oct 2018 17:56:57 +0000 (17:56 +0000)
commit262f33340b2a1f9d14ce812bf568bbd42ea11f23
tree0e1f8f9cd28d5fbb0770b221d306d099448f6440
parent5eb3d750c68ec9b2bef977d9bfa9e895d1d869c8
[clang-format] tweaked another case of lambda formatting

Summary:
This is done in order to improve cases where the lambda's body is moved too far to the right. Consider the following snippet with column limit set to 79:

```
void f() {
  leader::MakeThisCallHere(&leader_service_,
                           cq_.get(),
                           [this, liveness](const leader::ReadRecordReq& req,
                                            std::function<void()> done) {
                             logger_->HandleReadRecord(
                                 req, resp, std::move(done));
                           });

  leader::MakeAnother(&leader_service_,
                      cq_.get(),
                      [this, liveness](const leader::ReadRecordReq& req,
                                       std::function<void()> done) {
                        logger_->HandleReadRecord(
                            req, resp, std::move(done), a);
                      });
}
```

The tool favors extra indentation for the lambda body and so the code incurs extra wrapping and adjacent calls are indented to a different level. I find this behavior annoying and I'd like the tool to favor new lines and, thus, use the extra width.

The fix, reduced, brings the following formatting.

Before:

    function(1,
             [] {
               DoStuff();
               //
             },
             1);

After:

    function(
        1,
        [] {
          DoStuff();
          //
        },
        1);

Refer to the new tests in FormatTest.cpp

Contributed by oleg.smolsky!

Reviewers: djasper, klimek, krasimir

Subscribers: cfe-commits, owenpan

Tags: #clang

Differential Revision: https://reviews.llvm.org/D52676

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345753 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Format/ContinuationIndenter.cpp
lib/Format/FormatToken.h
lib/Format/TokenAnnotator.cpp
lib/Format/UnwrappedLineFormatter.cpp
unittests/Format/FormatTest.cpp