Skip to content

Commit fbb77c6

Browse files
committed
Don’t report empty folding ranges
1 parent 2bae1f0 commit fbb77c6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Sources/SourceKitLSP/Swift/FoldingRange.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ fileprivate final class FoldingRangeFinder: SyntaxAnyVisitor {
190190
if let limit = self.rangeLimit, self.ranges.count >= limit {
191191
return .skipChildren
192192
}
193+
if start == end {
194+
// Don't report empty ranges
195+
return .visitChildren
196+
}
193197

194198
guard let start: Position = snapshot.positionOf(utf8Offset: start.utf8Offset),
195199
let end: Position = snapshot.positionOf(utf8Offset: end.utf8Offset)

Tests/SourceKitLSPTests/FoldingRangeTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,12 @@ final class FoldingRangeTests: XCTestCase {
221221
// And some more test 2️⃣
222222
223223
3️⃣// And another comment separated by newlines4️⃣
224-
func foo() {5️⃣}
224+
func foo() {}
225225
"""
226226
,
227227
expectedRanges: [
228228
FoldingRangeSpec(from: "1️⃣", to: "2️⃣", kind: .comment),
229229
FoldingRangeSpec(from: "3️⃣", to: "4️⃣", kind: .comment),
230-
FoldingRangeSpec(from: "5️⃣", to: "5️⃣"),
231230
]
232231
)
233232
}

0 commit comments

Comments
 (0)