File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -382,12 +382,26 @@ extension IfConfigDeclSyntax {
382
382
383
383
extension SyntaxProtocol {
384
384
// Produce the source code for this syntax node with all of the comments
385
- // removed. Each comment will be replaced with either a newline or a space,
386
- // depending on whether the comment involved a newline.
385
+ // and #sourceLocations removed. Each comment will be replaced with either
386
+ // a newline or a space, depending on whether the comment involved a newline.
387
387
@_spi ( Compiler)
388
- public var descriptionWithoutComments : String {
388
+ public var descriptionWithoutCommentsAndSourceLocations : String {
389
389
var result = " "
390
+ var skipUntilRParen = false
390
391
for token in tokens ( viewMode: . sourceAccurate) {
392
+ // Skip #sourceLocation(...).
393
+ if token. tokenKind == . poundSourceLocation {
394
+ skipUntilRParen = true
395
+ continue
396
+ }
397
+
398
+ if skipUntilRParen {
399
+ if token. tokenKind == . rightParen {
400
+ skipUntilRParen = false
401
+ }
402
+ continue
403
+ }
404
+
391
405
token. leadingTrivia. writeWithoutComments ( to: & result)
392
406
token. text. write ( to: & result)
393
407
token. trailingTrivia. writeWithoutComments ( to: & result)
Original file line number Diff line number Diff line change @@ -300,12 +300,13 @@ public class VisitorTests: XCTestCase {
300
300
)
301
301
}
302
302
303
- func testRemoveComments ( ) {
303
+ func testRemoveCommentsAndSourceLocations ( ) {
304
304
let original : SourceFileSyntax = """
305
305
306
306
/// This is a documentation comment
307
307
func f() { }
308
308
309
+ #sourceLocation(file: " if-configs.swift " , line: 200)
309
310
/** Another documentation comment
310
311
that is split across
311
312
multiple lines */
@@ -318,14 +319,13 @@ public class VisitorTests: XCTestCase {
318
319
"""
319
320
320
321
assertStringsEqualWithDiff (
321
- original. descriptionWithoutComments ,
322
+ original. descriptionWithoutCommentsAndSourceLocations ,
322
323
"""
323
324
324
325
325
326
func f() { }
326
327
327
328
328
-
329
329
func g() { }
330
330
331
331
func h() {
You can’t perform that action at this time.
0 commit comments