@@ -14,7 +14,7 @@ import LSPLogging
14
14
import LanguageServerProtocol
15
15
import SwiftSyntax
16
16
17
- fileprivate final class FoldingRangeFinder : SyntaxVisitor {
17
+ fileprivate final class FoldingRangeFinder : SyntaxAnyVisitor {
18
18
private let snapshot : DocumentSnapshot
19
19
/// Some ranges might occur multiple times.
20
20
/// E.g. for `print("hi")`, `"hi"` is both the range of all call arguments and the range the first argument in the call.
@@ -124,39 +124,14 @@ fileprivate final class FoldingRangeFinder: SyntaxVisitor {
124
124
}
125
125
}
126
126
127
- override func visit( _ node: CodeBlockSyntax ) -> SyntaxVisitorContinueKind {
128
- return self . addFoldingRange (
129
- start: node. statements. position. utf8Offset,
130
- end: node. rightBrace. positionAfterSkippingLeadingTrivia. utf8Offset
131
- )
132
- }
133
-
134
- override func visit( _ node: MemberBlockSyntax ) -> SyntaxVisitorContinueKind {
135
- return self . addFoldingRange (
136
- start: node. members. position. utf8Offset,
137
- end: node. rightBrace. positionAfterSkippingLeadingTrivia. utf8Offset
138
- )
139
- }
140
-
141
- override func visit( _ node: ClosureExprSyntax ) -> SyntaxVisitorContinueKind {
142
- return self . addFoldingRange (
143
- start: node. statements. position. utf8Offset,
144
- end: node. rightBrace. positionAfterSkippingLeadingTrivia. utf8Offset
145
- )
146
- }
147
-
148
- override func visit( _ node: AccessorBlockSyntax ) -> SyntaxVisitorContinueKind {
149
- return self . addFoldingRange (
150
- start: node. accessors. position. utf8Offset,
151
- end: node. rightBrace. positionAfterSkippingLeadingTrivia. utf8Offset
152
- )
153
- }
154
-
155
- override func visit( _ node: SwitchExprSyntax ) -> SyntaxVisitorContinueKind {
156
- return self . addFoldingRange (
157
- start: node. cases. position. utf8Offset,
158
- end: node. rightBrace. positionAfterSkippingLeadingTrivia. utf8Offset
159
- )
127
+ override func visitAny( _ node: Syntax ) -> SyntaxVisitorContinueKind {
128
+ if let braced = node. asProtocol ( BracedSyntax . self) {
129
+ return self . addFoldingRange (
130
+ start: braced. leftBrace. endPositionBeforeTrailingTrivia. utf8Offset,
131
+ end: braced. rightBrace. positionAfterSkippingLeadingTrivia. utf8Offset
132
+ )
133
+ }
134
+ return . visitChildren
160
135
}
161
136
162
137
override func visit( _ node: FunctionCallExprSyntax ) -> SyntaxVisitorContinueKind {
0 commit comments