Skip to content

Commit 796138b

Browse files
committed
Support folding of switch cases
1 parent cc4cfac commit 796138b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Sources/SourceKitLSP/Swift/FoldingRange.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ fileprivate final class FoldingRangeFinder: SyntaxAnyVisitor {
162162
)
163163
}
164164

165+
override func visit(_ node: SwitchCaseSyntax) -> SyntaxVisitorContinueKind {
166+
return self.addFoldingRange(
167+
start: node.label.endPositionBeforeTrailingTrivia.utf8Offset,
168+
end: node.statements.endPosition.utf8Offset
169+
)
170+
}
171+
165172
__consuming func finalize() -> Set<FoldingRange> {
166173
return self.ranges
167174
}

Tests/SourceKitLSPTests/FoldingRangeTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,24 @@ final class FoldingRangeTests: XCTestCase {
283283
]
284284
)
285285
}
286+
287+
func testFoldSwitchCase() async throws {
288+
try await assertFoldingRanges(
289+
markedSource: """
290+
switch foo {1️⃣
291+
case 1:2️⃣
292+
break 3️⃣
293+
default:4️⃣
294+
let x = 1
295+
print(5️⃣x6️⃣)7️⃣
296+
8️⃣}
297+
""",
298+
expectedRanges: [
299+
FoldingRangeSpec(from: "1️⃣", to: "8️⃣"),
300+
FoldingRangeSpec(from: "2️⃣", to: "3️⃣"),
301+
FoldingRangeSpec(from: "4️⃣", to: "7️⃣"),
302+
FoldingRangeSpec(from: "5️⃣", to: "6️⃣"),
303+
]
304+
)
305+
}
286306
}

0 commit comments

Comments
 (0)