Skip to content

[5.1] SourceKit/Indentation: avoid indenting closing paren of function-like decls if it appears in a new line #25943

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

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/IDE/Formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ class FormatContext {
}
}

// func foo(a: Int,
// b: Int
// ) {} <- Avoid adding indentation here
SourceLoc SignatureEnd;
if (auto *AFD = dyn_cast_or_null<AbstractFunctionDecl>(Cursor->getAsDecl())) {
SignatureEnd = AFD->getSignatureSourceRange().End;
} else if (auto *SD = dyn_cast_or_null<SubscriptDecl>(Cursor->getAsDecl())) {
SignatureEnd = SD->getSignatureSourceRange().End;
}
if (SignatureEnd.isValid() && TInfo &&
TInfo.StartOfLineTarget->getLoc() == SignatureEnd) {
return false;
}

// If we're at the beginning of a brace on a separate line in the context
// of anything other than BraceStmt, don't add an indent.
// For example:
Expand Down
23 changes: 23 additions & 0 deletions test/SourceKit/CodeFormat/indent-param.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public static func buildBlock(
_ shapes: PathShape...
) -> PathShape {
return nil
}

class C {
init(a: Int,
b: Int
) {}
subscript(index1: Int,
index2: Int
) -> Int { get {} }
}

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >%t.response
// RUN: %sourcekitd-test -req=format -line=10 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=13 -length=1 %s >>%t.response
// RUN: %FileCheck --strict-whitespace %s <%t.response

// CHECK: key.sourcetext: ") -> PathShape {"
// CHECK: key.sourcetext: " ) {}"
// CHECK: key.sourcetext: " ) -> Int { get {} }"