Skip to content

[SourceKit/CodeFormat] Indentation fixes for multi-line string, UnresolvedSpecializeExpr, and trailing target handling. #31098

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 2 commits into from
Apr 20, 2020
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
304 changes: 202 additions & 102 deletions lib/IDE/Formatting.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ func foo() {
) in

// RUN: %sourcekitd-test -req=format -line=6 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum Foo {
case a,

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum Foo {
case

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum Foo {
case a

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct Foo<T: Equatable,

// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct Foo<T: Equatable

// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: ""
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ func foo(x: Bool) {
guard let number = patterns.index(where: {

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

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func foo(x: Bool) {
guard

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

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func foo(x: Bool) {
if let number = Optional(23),

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func foo(x: Bool) {
if

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func foo(x: Bool) {
if let number = Optional(23)

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct Foo: Equatable,

// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct Foo: Equatable

// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
func foo(x: Int,

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
func foo(

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo {
func foo(x: Int


// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public let x = 10,

// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public let x = 10

// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func foo(x: Bool) {
while let number = Optional(23),

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func foo(x: Bool) {
while

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func foo(x: Bool) {
while let number = Optional(23)

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s | %FileCheck --strict-whitespace %s
// CHECK: key.sourcetext: " "
16 changes: 16 additions & 0 deletions test/swift-indent/basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ let s = """
c
"""

func wantsToIndentContents() {
let dontLetItIndentMyValue = """
a
b
c
"""
}

print("""
foo {
bar()
Expand Down Expand Up @@ -905,6 +913,14 @@ let x = foo<Int,
String,
Int>()

let x = foo<
Int,
String,
Int
>()
.filter { $0 > 10 }
.count


// Invalid elements should still be indented.
//
Expand Down