mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This restructures the indentation logic around producing a single IndentContext for the line being indented. An IndentContext has: - a ContextLoc, which points to a source location to indent relative to, - a Kind, indicating whether we should align with that location exactly, or with the start of the content on its containing line, and - an IndentLevel with the relative number of levels to indent by. It also improves the handling of: - chained and nested parens, braces, square brackets and angle brackets, and how those interact with the exact alignment of parameters, call arguments, and tuple, array and dictionary elements. - Indenting to the correct level after an incomplete expression, statement or decl. Resolves: rdar://problem/59135010 rdar://problem/25519439 rdar://problem/50137394 rdar://problem/48410444 rdar://problem/48643521 rdar://problem/42171947 rdar://problem/40130724 rdar://problem/41405163 rdar://problem/39367027 rdar://problem/36332430 rdar://problem/34464828 rdar://problem/33113738 rdar://problem/32314354 rdar://problem/30106520 rdar://problem/29773848 rdar://problem/27301544 rdar://problem/27776466 rdar://problem/27230819 rdar://problem/25490868 rdar://problem/23482354 rdar://problem/20193017 rdar://problem/47117735 rdar://problem/55950781 rdar://problem/55939440 rdar://problem/53247352 rdar://problem/54326612 rdar://problem/53131527 rdar://problem/48399673 rdar://problem/51361639 rdar://problem/58285950 rdar://problem/58286076 rdar://problem/53828204 rdar://problem/58286182 rdar://problem/58504167 rdar://problem/58286327 rdar://problem/53828026 rdar://problem/57623821 rdar://problem/56965360 rdar://problem/54470937 rdar://problem/55580761 rdar://problem/46928002 rdar://problem/35807378 rdar://problem/39397252 rdar://problem/26692035 rdar://problem/33760223 rdar://problem/48934744 rdar://problem/43315903 rdar://problem/24630624
96 lines
3.3 KiB
Swift
96 lines
3.3 KiB
Swift
func foo(foo: Int, bar: Int, baz: Int, buzz: Int) -> Int {
|
|
return foo + bar + baz + buzz
|
|
}
|
|
|
|
foo(0,
|
|
bar: 1,
|
|
baz: 2,
|
|
buzz: 3)
|
|
|
|
public enum ProtobufJSONToken: Equatable {
|
|
case COLON
|
|
case COMMA
|
|
case BEGIN_OBJECT
|
|
}
|
|
|
|
public func ==(lhs: ProtobufJSONToken, rhs: ProtobufJSONToken) -> Bool {
|
|
switch (lhs, rhs) {
|
|
case (.COLON, .COLON),
|
|
(.COMMA, .COMMA),
|
|
(.BEGIN_OBJECT, .BEGIN_OBJECT),
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func f(a : Int,
|
|
bb b : Int,
|
|
cc c :Int) -> Int {
|
|
return 1
|
|
}
|
|
|
|
static func _consoleConnected(type: CGSNotificationType,
|
|
_ data: CGSNotificationData,
|
|
_ length: CGSByteCount,
|
|
_ arg: CGSNotificationArg,
|
|
_ cid: CGSConnectionID) {
|
|
}
|
|
|
|
public func someTestFunc(withArgumentLabel label: String,
|
|
someOtherArgumentLabel label2: String,
|
|
andAnotherArgumentLabel label3: String) {
|
|
}
|
|
|
|
// RUN: %sourcekitd-test -req=format -line=6 -length=1 %s >%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=7 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=8 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=9 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=19 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=20 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=29 -length=1 %s >>%t.response
|
|
|
|
// RUN: %sourcekitd-test -req=format -line=34 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=35 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=36 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=37 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=41 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=42 -length=1 %s >>%t.response
|
|
|
|
// RUN: %FileCheck --strict-whitespace %s <%t.response
|
|
|
|
// "foo(0,"
|
|
// CHECK: key.sourcetext: " bar: 1,"
|
|
|
|
// " bar: 1,"
|
|
// CHECK: key.sourcetext: " baz: 2,"
|
|
|
|
// " baz: 2,"
|
|
// CHECK: key.sourcetext: " buzz: 3)"
|
|
|
|
// " case (.COLON, .COLON),"
|
|
// CHECK: key.sourcetext: " (.COMMA, .COMMA),"
|
|
// " (.COMMA, .COMMA),"
|
|
// CHECK: key.sourcetext: " (.BEGIN_OBJECT, .BEGIN_OBJECT),"
|
|
|
|
// " bb b : Int,"
|
|
// CHECK: key.sourcetext: " cc c :Int) -> Int {"
|
|
|
|
// "static func _consoleConnected(type: CGSNotificationType,"
|
|
// CHECK: key.sourcetext: " _ data: CGSNotificationData,"
|
|
|
|
// " _ data: CGSNotificationData,"
|
|
// CHECK: key.sourcetext: " _ length: CGSByteCount,"
|
|
|
|
// " _ length: CGSByteCount,"
|
|
// CHECK: key.sourcetext: " _ arg: CGSNotificationArg,"
|
|
|
|
// " _ arg: CGSNotificationArg,"
|
|
// CHECK: key.sourcetext: " _ cid: CGSConnectionID) {"
|
|
|
|
// "public func someTestFunc(withArgumentLabel label: String,"
|
|
// CHECK: key.sourcetext: " someOtherArgumentLabel label2: String,"
|
|
|
|
// " someOtherArgumentLabel label2: String,"
|
|
// CHECK: key.sourcetext: " andAnotherArgumentLabel label3: String) {"
|