Skip to content

Commit f0ae03e

Browse files
authored
Merge pull request #25042 from akyrtzi/5.1-sourcekitd-expose-indent-switch-option
2 parents 805952f + 6a78790 commit f0ae03e

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
@@ -1887,10 +1887,12 @@ void SwiftEditorDocument::applyFormatOptions(OptionsDictionary &FmtOptions) {
18871887
static UIdent KeyUseTabs("key.editor.format.usetabs");
18881888
static UIdent KeyIndentWidth("key.editor.format.indentwidth");
18891889
static UIdent KeyTabWidth("key.editor.format.tabwidth");
1890+
static UIdent KeyIndentSwitchCase("key.editor.format.indent_switch_case");
18901891

18911892
FmtOptions.valueForOption(KeyUseTabs, Impl.FormatOptions.UseTabs);
18921893
FmtOptions.valueForOption(KeyIndentWidth, Impl.FormatOptions.IndentWidth);
18931894
FmtOptions.valueForOption(KeyTabWidth, Impl.FormatOptions.TabWidth);
1895+
FmtOptions.valueForOption(KeyIndentSwitchCase, Impl.FormatOptions.IndentSwitchCase);
18941896
}
18951897

18961898
const CodeFormatOptions &SwiftEditorDocument::getFormatOptions() {

0 commit comments

Comments
 (0)