From ebeb4d8edbf9659d09f68dd06b8f1114aadc7e98 Mon Sep 17 00:00:00 2001 From: Xi Ge Date: Tue, 13 Sep 2016 13:03:17 -0700 Subject: [PATCH] [SourceKit] Avoid adding indentation at the end of a CaptureListExpr. rdar://28193169 --- lib/IDE/Formatting.cpp | 3 ++- test/SourceKit/CodeFormat/indent-closure.swift | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/IDE/Formatting.cpp b/lib/IDE/Formatting.cpp index 824e206d44fb1..45c57a6755621 100644 --- a/lib/IDE/Formatting.cpp +++ b/lib/IDE/Formatting.cpp @@ -366,7 +366,8 @@ class FormatContext { Expr *AtExprEnd = End.getAsExpr(); if (AtExprEnd && (isa(AtExprEnd) || isa(AtExprEnd) || - isa(AtExprEnd))) { + isa(AtExprEnd) || + isa(AtExprEnd))) { if (auto *Paren = dyn_cast_or_null(Cursor->getAsExpr())) { auto *SubExpr = Paren->getSubExpr(); diff --git a/test/SourceKit/CodeFormat/indent-closure.swift b/test/SourceKit/CodeFormat/indent-closure.swift index e3b91170d25f4..dc26cb36724ab 100644 --- a/test/SourceKit/CodeFormat/indent-closure.swift +++ b/test/SourceKit/CodeFormat/indent-closure.swift @@ -32,6 +32,16 @@ func foo4() { }() } +func foo5(input: Int, block: (Int) -> ()) -> Int { + return 0 +} + +func foo6() { + _ = foo5(input: 0, block: { [unowned self] blockInput in + foo4() + }) +} + // RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >%t.response // RUN: %sourcekitd-test -req=format -line=4 -length=1 %s >>%t.response // RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >>%t.response @@ -46,6 +56,7 @@ func foo4() { // RUN: %sourcekitd-test -req=format -line=30 -length=1 %s >>%t.response // RUN: %sourcekitd-test -req=format -line=31 -length=1 %s >>%t.response // RUN: %sourcekitd-test -req=format -line=32 -length=1 %s >>%t.response +// RUN: %sourcekitd-test -req=format -line=42 -length=1 %s >>%t.response // RUN: %FileCheck --strict-whitespace %s <%t.response // CHECK: key.sourcetext: " var abc = 1" @@ -68,3 +79,5 @@ func foo4() { // CHECK: key.sourcetext: " let test = {" // CHECK: key.sourcetext: " return 0" // CHECK: key.sourcetext: " }()" + +// CHECK: key.sourcetext: " })"