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
170 lines
5.1 KiB
Swift
170 lines
5.1 KiB
Swift
func foo() {
|
|
bar() {
|
|
var abc = 1
|
|
let a: String = {
|
|
let b = "asdf"
|
|
return b
|
|
}()
|
|
}
|
|
}
|
|
|
|
class C {
|
|
private static let durationTimeFormatter: NSDateComponentsFormatter = {
|
|
return timeFormatter
|
|
}()
|
|
}
|
|
|
|
func foo1(a: Int, handler : () -> ()) {}
|
|
func foo2(handler : () -> ()) {}
|
|
|
|
func foo3() {
|
|
foo1(1)
|
|
{
|
|
}
|
|
}
|
|
|
|
func foo4() {
|
|
test = {
|
|
return 0
|
|
}()
|
|
let test = {
|
|
return 0
|
|
}()
|
|
}
|
|
|
|
func foo5(input: Int, block: (Int) -> ()) -> Int {
|
|
return 0
|
|
}
|
|
|
|
func foo6() {
|
|
_ = foo5(input: 0, block: { [unowned self] blockInput in
|
|
foo4()
|
|
})
|
|
}
|
|
|
|
func foo7(A: ()->(), B: ()->()) {}
|
|
|
|
func foo8() {
|
|
foo7(A: { _ in
|
|
print("hello")
|
|
}, B: {
|
|
print("world")
|
|
})
|
|
}
|
|
|
|
func foo9(input: [Int]){
|
|
input.map { (ele) in
|
|
ele + 1
|
|
}.filter{(ele) in
|
|
return ele > 10
|
|
}.map {(ele) in
|
|
return ele + 1
|
|
}
|
|
}
|
|
|
|
func foo10() {
|
|
Something() [
|
|
].whatever
|
|
}
|
|
|
|
func foo11() {
|
|
VStack {
|
|
}
|
|
.onAppear {
|
|
}
|
|
}
|
|
|
|
func foo12() {
|
|
VStack {
|
|
}
|
|
.onAppear1()
|
|
.onAppear2() {}
|
|
.onAppear3() {
|
|
}
|
|
.onAppear4() {}
|
|
}
|
|
|
|
// 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
|
|
// 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=14 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=22 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=27 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=28 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=29 -length=1 %s >>%t.response
|
|
// 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: %sourcekitd-test -req=format -line=50 -length=1 %s >>%t.response
|
|
|
|
// RUN: %sourcekitd-test -req=format -line=55 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=56 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=57 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=58 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=59 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=60 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=61 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=62 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=63 -length=1 %s >>%t.response
|
|
|
|
// RUN: %sourcekitd-test -req=format -line=66 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=67 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=73 -length=1 %s >>%t.response
|
|
|
|
// RUN: %sourcekitd-test -req=format -line=80 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=81 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=82 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=83 -length=1 %s >>%t.response
|
|
// RUN: %sourcekitd-test -req=format -line=84 -length=1 %s >>%t.response
|
|
|
|
// RUN: %FileCheck --strict-whitespace %s <%t.response
|
|
|
|
// CHECK: key.sourcetext: " var abc = 1"
|
|
// CHECK: key.sourcetext: " let a: String = {"
|
|
// CHECK: key.sourcetext: " let b = \"asdf\""
|
|
// CHECK: key.sourcetext: " return b"
|
|
// CHECK: key.sourcetext: " }()"
|
|
// CHECK: key.sourcetext: " }"
|
|
|
|
// " private static let durationTimeFormatter: NSDateComponentsFormatter = {"
|
|
// CHECK: key.sourcetext: " }()"
|
|
// " foo1(1)"
|
|
// CHECK: key.sourcetext: " {"
|
|
|
|
// CHECK: key.sourcetext: " test = {"
|
|
// CHECK: key.sourcetext: " return 0"
|
|
// CHECK: key.sourcetext: " }()"
|
|
|
|
|
|
// CHECK: key.sourcetext: " let test = {"
|
|
// CHECK: key.sourcetext: " return 0"
|
|
// CHECK: key.sourcetext: " }()"
|
|
|
|
// CHECK: key.sourcetext: " })"
|
|
|
|
// CHECK: key.sourcetext: " }, B: {"
|
|
|
|
// CHECK: key.sourcetext: "func foo9(input: [Int]){"
|
|
// CHECK: key.sourcetext: " input.map { (ele) in"
|
|
// CHECK: key.sourcetext: " ele + 1"
|
|
// CHECK: key.sourcetext: " }.filter{(ele) in"
|
|
// CHECK: key.sourcetext: " return ele > 10"
|
|
// CHECK: key.sourcetext: " }.map {(ele) in"
|
|
// CHECK: key.sourcetext: " return ele + 1"
|
|
// CHECK: key.sourcetext: " }"
|
|
// CHECK: key.sourcetext: "}"
|
|
|
|
// CHECK: key.sourcetext: " Something() ["
|
|
// CHECK: key.sourcetext: " ].whatever"
|
|
// CHECK: key.sourcetext: " .onAppear {"
|
|
|
|
// CHECK: key.sourcetext: " .onAppear1()"
|
|
// CHECK: key.sourcetext: " .onAppear2() {}"
|
|
// CHECK: key.sourcetext: " .onAppear3() {"
|
|
// CHECK: key.sourcetext: " }"
|
|
// CHECK: key.sourcetext: " .onAppear4() {}"
|