Skip to content

Commit 1dcb1e0

Browse files
committed
[sourcekitd] Expose the indentation option for extra indentation of switch case
rdar://51079623
1 parent 5467232 commit 1dcb1e0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

test/SourceKit/CodeFormat/indent-switch.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ func foo3() {
4141
println("It's something else")
4242
}
4343
}
44+
45+
func foo4() {
46+
var test : Int = 1
47+
switch test {
48+
case 0:
49+
print()
50+
case 1:
51+
break
52+
default:
53+
break
54+
}
55+
}
56+
4457
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >%t.response
4558
// RUN: %sourcekitd-test -req=format -line=4 -length=1 %s >>%t.response
4659
// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >>%t.response
@@ -76,6 +89,15 @@ func foo3() {
7689
// RUN: %sourcekitd-test -req=format -line=41 -length=1 %s >>%t.response
7790
// RUN: %sourcekitd-test -req=format -line=42 -length=1 %s >>%t.response
7891

92+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=47 -length=1 %s >>%t.response
93+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=48 -length=1 %s >>%t.response
94+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=49 -length=1 %s >>%t.response
95+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=50 -length=1 %s >>%t.response
96+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=51 -length=1 %s >>%t.response
97+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=52 -length=1 %s >>%t.response
98+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=53 -length=1 %s >>%t.response
99+
// RUN: %sourcekitd-test -req=format -req-opts=indent_switch_case=1 -line=54 -length=1 %s >>%t.response
100+
79101
// RUN: %FileCheck --strict-whitespace %s <%t.response
80102

81103
// CHECK: key.sourcetext: " switch (test) {"
@@ -112,3 +134,12 @@ func foo3() {
112134
// CHECK: key.sourcetext: " default:"
113135
// CHECK: key.sourcetext: " println(\"It's something else\")"
114136
// CHECK: key.sourcetext: " }"
137+
138+
// CHECK: key.sourcetext: " switch test {"
139+
// CHECK: key.sourcetext: " case 0:"
140+
// CHECK: key.sourcetext: " print()"
141+
// CHECK: key.sourcetext: " case 1:"
142+
// CHECK: key.sourcetext: " break"
143+
// CHECK: key.sourcetext: " default:"
144+
// CHECK: key.sourcetext: " break"
145+
// CHECK: key.sourcetext: " }"

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,10 +1904,12 @@ void SwiftEditorDocument::applyFormatOptions(OptionsDictionary &FmtOptions) {
19041904
static UIdent KeyUseTabs("key.editor.format.usetabs");
19051905
static UIdent KeyIndentWidth("key.editor.format.indentwidth");
19061906
static UIdent KeyTabWidth("key.editor.format.tabwidth");
1907+
static UIdent KeyIndentSwitchCase("key.editor.format.indent_switch_case");
19071908

19081909
FmtOptions.valueForOption(KeyUseTabs, Impl.FormatOptions.UseTabs);
19091910
FmtOptions.valueForOption(KeyIndentWidth, Impl.FormatOptions.IndentWidth);
19101911
FmtOptions.valueForOption(KeyTabWidth, Impl.FormatOptions.TabWidth);
1912+
FmtOptions.valueForOption(KeyIndentSwitchCase, Impl.FormatOptions.IndentSwitchCase);
19111913
}
19121914

19131915
const CodeFormatOptions &SwiftEditorDocument::getFormatOptions() {

0 commit comments

Comments
 (0)