File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Sources/SourceKitLSP/Swift Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,17 @@ fileprivate final class FoldingRangeFinder: SyntaxAnyVisitor {
164
164
return . visitChildren
165
165
}
166
166
167
+ override func visit( _ node: IfConfigClauseSyntax ) -> SyntaxVisitorContinueKind {
168
+ guard let closePound = node. lastToken ( viewMode: . sourceAccurate) ? . nextToken ( viewMode: . sourceAccurate) else {
169
+ return . visitChildren
170
+ }
171
+
172
+ return self . addFoldingRange (
173
+ start: node. poundKeyword. positionAfterSkippingLeadingTrivia,
174
+ end: closePound. positionAfterSkippingLeadingTrivia
175
+ )
176
+ }
177
+
167
178
override func visit( _ node: SubscriptCallExprSyntax ) -> SyntaxVisitorContinueKind {
168
179
return self . addFoldingRange (
169
180
start: node. leftSquare. endPositionBeforeTrailingTrivia,
Original file line number Diff line number Diff line change @@ -357,4 +357,52 @@ final class FoldingRangeTests: XCTestCase {
357
357
expectedRanges: [ FoldingRangeSpec ( from: " 1️⃣ " , to: " 2️⃣ " ) ]
358
358
)
359
359
}
360
+
361
+ func testFoldArgumentsForConditionalIfCompileDirectives( ) async throws {
362
+ try await assertFoldingRanges (
363
+ markedSource: """
364
+ 1️⃣#if DEBUG
365
+ let foo = " x "
366
+ 2️⃣#endif
367
+ """ ,
368
+ expectedRanges: [
369
+ FoldingRangeSpec ( from: " 1️⃣ " , to: " 2️⃣ " )
370
+ ]
371
+ )
372
+ }
373
+
374
+ func testFoldArgumentsForConditionalElseIfCompileDirectives( ) async throws {
375
+ try await assertFoldingRanges (
376
+ markedSource: """
377
+ 1️⃣#if DEBUG
378
+ let foo = " x "
379
+ 2️⃣#elseif TEST
380
+ let foo = " y "
381
+ 3️⃣#else
382
+ let foo = " z "
383
+ 4️⃣#endif
384
+ """ ,
385
+ expectedRanges: [
386
+ FoldingRangeSpec ( from: " 1️⃣ " , to: " 2️⃣ " ) ,
387
+ FoldingRangeSpec ( from: " 2️⃣ " , to: " 3️⃣ " ) ,
388
+ FoldingRangeSpec ( from: " 3️⃣ " , to: " 4️⃣ " ) ,
389
+ ]
390
+ )
391
+ }
392
+
393
+ func testFoldArgumentsForConditionalElseCompileDirectives( ) async throws {
394
+ try await assertFoldingRanges (
395
+ markedSource: """
396
+ 1️⃣#if DEBUG
397
+ let foo = " x "
398
+ 2️⃣#else
399
+ let foo = " y "
400
+ 3️⃣#endif
401
+ """ ,
402
+ expectedRanges: [
403
+ FoldingRangeSpec ( from: " 1️⃣ " , to: " 2️⃣ " ) ,
404
+ FoldingRangeSpec ( from: " 2️⃣ " , to: " 3️⃣ " ) ,
405
+ ]
406
+ )
407
+ }
360
408
}
You can’t perform that action at this time.
0 commit comments