Files
swift-mirror/test/SourceKit/CodeFormat/indent-list-exact.swift
Nathan Hawes a368434432 [SourceKit/CodeFormat] Re-work and improve the indentation implementation.
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
2020-03-10 21:04:21 -07:00

190 lines
6.1 KiB
Swift

class Foo {
func foo(Value1 : Int,
Value2 : Int) {
}
func bar(value1 : Int,
value2 : Int,
value3 : Int) {
}
func foo1(Value1 : Int,
Value2 : Int) {}
func foo3() {
foo(1,
2)
foo(2,
3)
foo(3,
4)
}
func intGen() -> Int { return 0 }
func foo4() {
var a = [1,
2,
3,
1 + 2,
intGen()]
}
func foo5() {
var a = [1 : 1,
2 : 2,
3 + 2 : 3,
intGen() : intGen()]
var b = (2,
3,
4,
5)
}
func foo6<T1: Testable,
T2: Testable,
T3: Testable,
T4: where T4 : Testable>(t1 : T1, t2 : T2, t3 : T2) {}
func foo7(i1: Int, i2: Int,
i3: Int, i4: Int,
i5 : Int) {}
func foo7(i1 : Int,
i2 : Int) {
var a : Int
}
}
protocol Testable {}
class Foo1 {
func foo1(i : Int,
) {}
func foo2(i : Int, j : Int,
)
}
class Foo2 {
func foo1(i : Int, j : Int, k : Int) {}
func foo2(i : Int, j : Int) {}
func foo3() {
foo1(1,
)
foo2(1,
j : 1)
foo2(1, j: 2,
)
foo2(1,
}
}
// RUN: %sourcekitd-test -req=format -line=3 -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=10 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=13 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=15 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=17 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=22 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=23 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=24 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=25 -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=33 -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=38 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=39 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=40 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=42 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=43 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=46 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=53 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=55 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=63 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=65 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=67 -length=1 %s >>%t.response
// RUN: %sourcekitd-test -req=format -line=69 -length=1 %s >>%t.response
// RUN: %FileCheck --strict-whitespace %s <%t.response
// " func foo(Value1 : Int,"
// CHECK: key.sourcetext: " Value2 : Int) {"
// "func bar(value1 : Int,"
// CHECK: key.sourcetext: " value2 : Int,"
// "value2 : Int,"
// CHECK: key.sourcetext: "value3 : Int) {"
// " func foo1(Value1 : Int,"
// CHECK: key.sourcetext: " Value2 : Int) {}"
// " foo(1,"
// CHECK: key.sourcetext: " 2)"
// " foo(2,"
// CHECK: key.sourcetext: " 3)"
// " foo(3,"
// CHECK: key.sourcetext: " 4)"
// " var a = [1,"
// CHECK: key.sourcetext: " 2,"
// " 2,"
// CHECK: key.sourcetext: " 3,"
// " 3,"
// CHECK: key.sourcetext: " 1 + 2,"
// " 1 + 2,"
// CHECK: key.sourcetext: " intGen()]"
// " var a = [1 : 1,"
// CHECK: key.sourcetext: " 2 : 2,"
// " 2 : 2,"
// CHECK: key.sourcetext: " 3 + 2 : 3,"
// " 3 + 2 : 3,"
// CHECK: key.sourcetext: " intGen() : intGen()]"
// " var b = (2,"
// CHECK: key.sourcetext: " 3,"
// " 3,"
// CHECK: key.sourcetext: " 4,"
// " 4,"
// CHECK: key.sourcetext: " 5)"
// " func foo6<T1: Testable,"
// CHECK: key.sourcetext: " T2: Testable,"
// " T2: Testable,"
// CHECK: key.sourcetext: " T3: Testable,"
// " T3: Testable,"
// CHECK: key.sourcetext: " T4: where T4 : Testable>(t1 : T1, t2 : T2, t3 : T2) {}"
// " func foo7(i1: Int, i2: Int,"
// CHECK: key.sourcetext: " i3: Int, i4: Int,"
// " i3: Int, i4: Int,"
// CHECK: key.sourcetext: " i5 : Int) {}"
// " func foo7(i1 : Int,"
// CHECK: key.sourcetext: " var a : Int"
// " func foo1(i : Int,"
// CHECK: key.sourcetext: " ) {}"
// " func foo2(i : Int, j : Int,"
// CHECK: key.sourcetext: " )"
// " foo1(1,"
// CHECK: key.sourcetext: " )"
// " foo2(1,"
// CHECK: key.sourcetext: " j : 1)"
// " foo2(1, j: 2,"
// CHECK: key.sourcetext: " )"
// " foo2(1,"
// CHECK: key.sourcetext: " "