Skip to content

Commit b85751b

Browse files
committed
Remove codeBlock file scope config. Minor code and documentation adjustments.
1 parent e1831be commit b85751b

File tree

5 files changed

+5
-54
lines changed

5 files changed

+5
-54
lines changed

Sources/SwiftLexicalLookup/Configurations/FileScopeNameIntroductionStrategy.swift renamed to Sources/SwiftLexicalLookup/Configurations/FileScopeHandlingConfig.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@ import SwiftSyntax
2020
/// This is the behavior that is being used
2121
/// for Swift files that don’t allow top-level code.
2222
case memberBlock
23-
/// This is the behavior that is being used for e.g. function bodies.
24-
case codeBlock
2523
}

Sources/SwiftLexicalLookup/ScopeImplementations.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SwiftSyntax
1414

1515
@_spi(Experimental) extension SyntaxProtocol {
1616
/// Parent scope of this syntax node, or scope introduced by this syntax node.
17-
@_spi(Experimental) public var scope: ScopeSyntax? {
17+
var scope: ScopeSyntax? {
1818
if let scopeSyntax = Syntax(self).asProtocol(SyntaxProtocol.self) as? ScopeSyntax {
1919
return scopeSyntax
2020
} else {
@@ -69,10 +69,6 @@ import SwiftSyntax
6969
}
7070
}
7171
}
72-
case .codeBlock:
73-
return statements.flatMap { codeBlockItem in
74-
LookupName.getNames(from: codeBlockItem.item, accessibleAfter: codeBlockItem.endPosition)
75-
}
7672
case .memberBlock:
7773
return statements.flatMap { codeBlockItem in
7874
LookupName.getNames(from: codeBlockItem.item)

Sources/SwiftLexicalLookup/ScopeSyntax.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extension SyntaxProtocol {
9292
let filteredNames =
9393
introducedNames
9494
.filter { introducedName in
95-
does(name: name, referTo: introducedName, at: syntax)
95+
checkName(name, refersTo: introducedName, at: syntax)
9696
}
9797

9898
if filteredNames.isEmpty {
@@ -111,7 +111,7 @@ extension SyntaxProtocol {
111111
parentScope?.lookup(for: name, at: syntax, with: config) ?? []
112112
}
113113

114-
func does(name: String?, referTo introducedName: LookupName, at syntax: SyntaxProtocol) -> Bool {
114+
func checkName(_ name: String?, refersTo introducedName: LookupName, at syntax: SyntaxProtocol) -> Bool {
115115
introducedName.isAccessible(at: syntax) && (name == nil || introducedName.refersTo(name!))
116116
}
117117
}

Tests/SwiftLexicalLookupTest/Assertions.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ enum MarkerExpectation {
5252
}
5353
}
5454

55-
/// Used to define
55+
/// Used to define result assertion.
5656
enum ResultExpectation {
5757
case fromScope(ScopeSyntax.Type, expectedNames: [String])
5858
case fromFileScope(expectedNames: [String])
@@ -118,19 +118,7 @@ func assertLexicalScopeQuery(
118118

119119
// Assert validity of the output
120120
for (actual, (expectedMarker, expectedPosition)) in zip(result, zip(expectedMarkers, expectedPositions)) {
121-
if actual == nil && expectedPosition == nil { continue }
122-
123-
guard let actual else {
124-
XCTFail(
125-
"For marker \(marker), actual is nil while expected is \(sourceFileSyntax.token(at: expectedPosition!)?.description ?? "nil")"
126-
)
127-
continue
128-
}
129-
130-
guard let expectedPosition else {
131-
XCTFail("For marker \(marker), actual is \(actual) while expected position is nil")
132-
continue
133-
}
121+
guard let actual, let expectedPosition else { continue }
134122

135123
XCTAssert(
136124
actual.positionAfterSkippingLeadingTrivia == expectedPosition,

Tests/SwiftLexicalLookupTest/NameLookupTests.swift

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -532,37 +532,6 @@ final class testNameLookup: XCTestCase {
532532
config: LookupConfig(fileScopeHandling: .memberBlock)
533533
)
534534
}
535-
536-
func testFileScopeAsCodeBlock() {
537-
assertLexicalNameLookup(
538-
source: """
539-
1️⃣class a {}
540-
541-
2️⃣class b {
542-
let x = 3️⃣a + 4️⃣b + 5️⃣c + 6️⃣d
543-
}
544-
545-
let 8️⃣a = 0
546-
547-
7️⃣class c {}
548-
549-
if a == 0 {}
550-
551-
9️⃣class d {}
552-
553-
let 🔟a = 0️⃣d
554-
""",
555-
references: [
556-
"3️⃣": [.fromFileScope(expectedNames: ["1️⃣"])],
557-
"4️⃣": [.fromFileScope(expectedNames: ["2️⃣"])],
558-
"5️⃣": [.fromFileScope(expectedNames: ["7️⃣"])],
559-
"6️⃣": [.fromFileScope(expectedNames: ["9️⃣"])],
560-
"0️⃣": [.fromFileScope(expectedNames: ["9️⃣"])],
561-
],
562-
expectedResultTypes: .all(ClassDeclSyntax.self, except: ["8️⃣": IdentifierPatternSyntax.self]),
563-
config: LookupConfig(fileScopeHandling: .codeBlock)
564-
)
565-
}
566535

567536
func testDeclarationAvailabilityInCodeBlock() {
568537
assertLexicalNameLookup(

0 commit comments

Comments
 (0)