Skip to content

Commit e01c1a1

Browse files
author
Nathan Hawes
committed
[SourceKit/CodeFormat] Get 'trailing' indentation to work in more places and fix a bug where multi-line string indentation was modified.
E.g. if/guard condition patterns are column-aligned, but hitting enter after the ',' below wasn't column-aligning the next empty line: guard let x = Optional(42), // No indentation added here after enter Also the isTargetContext() check takes a start and end token location, but wasn't accounting for the end location pointing a multiline string, so we weren't walking into such nodes. This meant we didn't realise the target location was within a multiline string in some cases, and we ended up interfering with whitespace in its content.
1 parent 9e0e611 commit e01c1a1

25 files changed

+308
-104
lines changed

lib/IDE/Formatting.cpp

Lines changed: 198 additions & 102 deletions
Large diffs are not rendered by default.

test/SourceKit/CodeFormat/indent-trailing/trailing-closure-in.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ func foo() {
55
) in
66

77
// RUN: %sourcekitd-test -req=format -line=6 -length=1 %s | %FileCheck --strict-whitespace %s
8-
// CHECK: key.sourcetext: " "
8+
// CHECK: key.sourcetext: " "
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum Foo {
2+
case a,
3+
4+
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
5+
// CHECK: key.sourcetext: " "
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum Foo {
2+
case
3+
4+
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
5+
// CHECK: key.sourcetext: " "
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum Foo {
2+
case a
3+
4+
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
5+
// CHECK: key.sourcetext: " "
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct Foo<T: Equatable,
2+
3+
// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
4+
// CHECK: key.sourcetext: " "
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct Foo<T: Equatable
2+
3+
// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
4+
// CHECK: key.sourcetext: ""

test/SourceKit/CodeFormat/indent-trailing/trailing-guard-condition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ func foo(x: Bool) {
22
guard let number = patterns.index(where: {
33

44
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
5-
// CHECK: key.sourcetext: " "
5+
// CHECK: key.sourcetext: " "
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
func foo(x: Bool) {
2+
guard let number = Optional(23),
3+
4+
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
5+
// CHECK: key.sourcetext: " "
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
func foo(x: Bool) {
2+
guard
3+
4+
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
5+
// CHECK: key.sourcetext: " "

0 commit comments

Comments
 (0)