Skip to content

Commit f4164d0

Browse files
committed
Rename compositeName to multipleNames. Simplify LookupName.debugDescription string concatenation for multipleNames case.
1 parent 862b526 commit f4164d0

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

Sources/SwiftLexicalLookup/LookupName.swift

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ import SwiftSyntax
139139
case implicit(ImplicitDecl)
140140
/// Dollar identifier introduced by a closure without parameters.
141141
case dollarIdentifier(ClosureExprSyntax, strRepresentation: String)
142-
/// Represents equivalent identifiers grouped together.
142+
/// Represents equivalent names grouped together.
143143
/// - Important: The array should be non-empty.
144144
///
145145
/// ### Example:
@@ -150,8 +150,8 @@ import SwiftSyntax
150150
/// }
151151
/// ```
152152
/// For lookup at the given position, the result
153-
/// contains only one (composite) name
154-
case compositeName([LookupName])
153+
/// contains only one name, that represents both `let x` declarations.
154+
case equivalentNames([LookupName])
155155

156156
/// Syntax associated with this name.
157157
@_spi(Experimental) public var syntax: SyntaxProtocol {
@@ -164,7 +164,7 @@ import SwiftSyntax
164164
return implicitName.syntax
165165
case .dollarIdentifier(let closureExpr, _):
166166
return closureExpr
167-
case .compositeName(let names):
167+
case .equivalentNames(let names):
168168
return names.first!.syntax
169169
}
170170
}
@@ -180,7 +180,7 @@ import SwiftSyntax
180180
return kind.identifier
181181
case .dollarIdentifier(_, strRepresentation: _):
182182
return nil
183-
case .compositeName(let names):
183+
case .equivalentNames(let names):
184184
return names.first!.identifier
185185
}
186186
}
@@ -202,7 +202,7 @@ import SwiftSyntax
202202
return implicitName.position
203203
case .dollarIdentifier(let closureExpr, _):
204204
return closureExpr.positionAfterSkippingLeadingTrivia
205-
case .compositeName(let names):
205+
case .equivalentNames(let names):
206206
return names.first!.position
207207
}
208208
}
@@ -338,20 +338,8 @@ import SwiftSyntax
338338
return "implicit: \(strName)"
339339
case .dollarIdentifier(_, strRepresentation: let str):
340340
return "dollarIdentifier: \(str)"
341-
case .compositeName(let names):
342-
var result = "Composite name: [ "
343-
344-
for (index, name) in names.enumerated() {
345-
result += name.debugDescription
346-
347-
if index < names.count - 1 {
348-
result += ", "
349-
} else {
350-
result += " ]"
351-
}
352-
}
353-
354-
return result
341+
case .equivalentNames(let names):
342+
return "Composite name: [ \(names.map(\.debugDescription).joined(separator: ", ")) ]"
355343
}
356344
}
357345
}

Sources/SwiftLexicalLookup/Scopes/ScopeImplementations.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,19 +598,15 @@ import SwiftSyntax
598598
orderedKeys.append(identifier)
599599
}
600600

601-
if partitioned[identifier] == nil {
602-
partitioned[identifier] = [extractedName]
603-
} else {
604-
partitioned[identifier]?.append(extractedName)
605-
}
601+
partitioned[identifier, default: []].append(extractedName)
606602
}
607603

608604
return
609605
orderedKeys
610606
.compactMap { key in
611607
guard let names = partitioned[key] else { return nil }
612608

613-
return .compositeName(names)
609+
return .equivalentNames(names)
614610
}
615611
}
616612

Tests/SwiftLexicalLookupTest/Assertions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func assertLexicalNameLookup(
106106

107107
return result.flatMap { lookUpResult in
108108
lookUpResult.names.flatMap { lookupName in
109-
if case .compositeName(let names) = lookupName {
109+
if case .equivalentNames(let names) = lookupName {
110110
return names.map(\.syntax)
111111
} else {
112112
return [lookupName.syntax]

Tests/SwiftLexicalLookupTest/ExpectedName.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ enum NameExpectation: ExpectedName {
9393
actualStr == expectedStr,
9494
"For marker \(marker), actual identifier \(actualStr) doesn't match expected \(expectedStr)"
9595
)
96-
case (.compositeName(let actualNames), .compositeName(let expectedNames)):
96+
case (.equivalentNames(let actualNames), .compositeName(let expectedNames)):
9797
XCTAssert(
9898
actualNames.count == expectedNames.count,
9999
"For marker \(marker), actual composite name count \(actualNames.count) doesn't match expected \(expectedNames.count)"

0 commit comments

Comments
 (0)