Skip to content

Commit 57183fc

Browse files
committed
Add suggested changes.
1 parent c05403a commit 57183fc

File tree

6 files changed

+80
-14
lines changed

6 files changed

+80
-14
lines changed

Sources/SwiftLexicalLookup/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ add_swift_syntax_library(SwiftLexicalLookup
2525
)
2626

2727
target_link_swift_syntax_libraries(SwiftLexicalLookup PUBLIC
28-
SwiftSyntax)
28+
SwiftSyntax)
2929

Sources/SwiftLexicalLookup/Scopes/GenericParameterScopeSyntax.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
import SwiftSyntax
1414

1515
/// Scope that introduces generic parameter names and directs
16-
/// futher lookup to it's `WithGenericParametersScopeSyntax`
16+
/// futher lookup to its `WithGenericParametersScopeSyntax`
1717
/// parent scope's parent scope (i.e. on return, bypasses names
18-
/// introduced by it's parent).
18+
/// introduced by its parent).
1919
@_spi(Experimental) public protocol GenericParameterScopeSyntax: ScopeSyntax {}
2020

2121
@_spi(Experimental) extension GenericParameterScopeSyntax {
2222
/// Returns names matching lookup and bypasses
2323
/// `WithGenericParametersScopeSyntax` parent scope in futher lookup.
2424
///
25-
/// example:
25+
/// ### Example
2626
/// ```swift
2727
/// let a = 23
2828
/// func foo<A>(a: A) {
@@ -57,7 +57,7 @@ import SwiftSyntax
5757

5858
/// Bypasses names introduced by `WithGenericParametersScopeSyntax` parent scope.
5959
///
60-
/// example:
60+
/// ### Example
6161
/// ```swift
6262
/// let a = 23
6363
/// func foo<A>(a: A) {

Sources/SwiftLexicalLookup/Scopes/ScopeImplementations.swift

+22-6
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ import SwiftSyntax
176176
/// All names introduced by the closure signature.
177177
/// Could be closure captures or (shorthand) parameters.
178178
///
179-
/// Example:
179+
/// ### Example
180180
/// ```swift
181181
/// let x = { [weak self, a] b, _ in
182182
/// // <--
@@ -222,7 +222,7 @@ import SwiftSyntax
222222

223223
/// Finds parent scope, omitting ancestor `if` statements if part of their `else if` clause.
224224
///
225-
/// Example:
225+
/// ### Example
226226
/// ```swift
227227
/// func foo() {
228228
/// if let a = x {
@@ -262,7 +262,7 @@ import SwiftSyntax
262262
/// Lookup triggered from inside of `else`
263263
/// clause is immediately forwarded to parent scope.
264264
///
265-
/// Example:
265+
/// ### Example
266266
/// ```swift
267267
/// if let a = x {
268268
/// // <-- a is visible here
@@ -326,7 +326,7 @@ import SwiftSyntax
326326
/// Lookup triggered from within of the `else` body
327327
/// returns no names.
328328
///
329-
/// Example:
329+
/// ### Example
330330
/// ```swift
331331
/// guard let a = x else {
332332
/// return // a is not visible here
@@ -399,7 +399,7 @@ import SwiftSyntax
399399
/// all associated type declarations made inside the
400400
/// protocol member block.
401401
///
402-
/// example:
402+
/// ### Example
403403
/// ```swift
404404
/// class A {}
405405
///
@@ -436,7 +436,7 @@ import SwiftSyntax
436436
@_spi(Experimental) extension GenericParameterClauseSyntax: GenericParameterScopeSyntax {
437437
/// Generic parameter names introduced by this clause.
438438
@_spi(Experimental) public var introducedNames: [LookupName] {
439-
parameters.children(viewMode: .sourceAccurate).flatMap { child in
439+
parameters.children(viewMode: .fixedUp).flatMap { child in
440440
LookupName.getNames(from: child, accessibleAfter: child.endPosition)
441441
}
442442
}
@@ -450,3 +450,19 @@ import SwiftSyntax
450450
}
451451
}
452452
}
453+
454+
@_spi(Experimental) extension SubscriptDeclSyntax: WithGenericParametersScopeSyntax {
455+
/// Parameters introduced by this subscript.
456+
@_spi(Experimental) public var introducedNames: [LookupName] {
457+
parameterClause.parameters.flatMap { parameter in
458+
LookupName.getNames(from: parameter)
459+
}
460+
}
461+
}
462+
463+
@_spi(Experimental) extension TypeAliasDeclSyntax: WithGenericParametersScopeSyntax {
464+
/// Type alias doesn't introduce any names to it's children.
465+
@_spi(Experimental) public var introducedNames: [LookupName] {
466+
[]
467+
}
468+
}

Sources/SwiftLexicalLookup/Scopes/SequentialScopeSyntax.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension SequentialScopeSyntax {
2222
/// and included `IntroducingToSequentialParentScopeSyntax` children
2323
/// scopes that match the lookup.
2424
///
25-
/// Example:
25+
/// ### Example
2626
/// ```swift
2727
/// func foo() {
2828
/// let a = 1

Sources/SwiftLexicalLookup/Scopes/WithGenericParametersScopeSyntax.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftSyntax
2020
/// Returns names matching lookup and passes lookup to
2121
/// the generic parameter clause scopes.
2222
///
23-
/// example:
23+
/// ### Example
2424
/// ```swift
2525
/// let a = 23
2626
/// func foo<A>(a: A) {
@@ -54,7 +54,7 @@ import SwiftSyntax
5454
/// Passes lookup to this scope's generic parameter or
5555
/// primary associated type clause scope (`WithGenericParametersScopeSyntax`).
5656
///
57-
/// example:
57+
/// ### Example
5858
/// ```swift
5959
/// let a = 23
6060
/// func foo<A>(a: A) {

Tests/SwiftLexicalLookupTest/NameLookupTests.swift

+50
Original file line numberDiff line numberDiff line change
@@ -968,4 +968,54 @@ final class testNameLookup: XCTestCase {
968968
)
969969
)
970970
}
971+
972+
func testSubscript() {
973+
assertLexicalNameLookup(
974+
source: """
975+
class X {
976+
let 0️⃣c = 123
977+
978+
subscript<1️⃣A, 2️⃣B>(3️⃣a: 4️⃣A, 5️⃣b: 6️⃣B) -> 7️⃣B {
979+
return 8️⃣a + 9️⃣b + 🔟c
980+
}
981+
}
982+
""",
983+
references: [
984+
"4️⃣": [.fromScope(GenericParameterClauseSyntax.self, expectedNames: ["1️⃣"])],
985+
"6️⃣": [.fromScope(GenericParameterClauseSyntax.self, expectedNames: ["2️⃣"])],
986+
"7️⃣": [.fromScope(GenericParameterClauseSyntax.self, expectedNames: ["2️⃣"])],
987+
"8️⃣": [.fromScope(SubscriptDeclSyntax.self, expectedNames: ["3️⃣"])],
988+
"9️⃣": [.fromScope(SubscriptDeclSyntax.self, expectedNames: ["5️⃣"])],
989+
"🔟": [.fromScope(MemberBlockSyntax.self, expectedNames: ["0️⃣"])],
990+
],
991+
expectedResultTypes: .all(
992+
GenericParameterSyntax.self,
993+
except: [
994+
"0️⃣": IdentifierPatternSyntax.self,
995+
"3️⃣": FunctionParameterSyntax.self,
996+
"5️⃣": FunctionParameterSyntax.self,
997+
]
998+
)
999+
)
1000+
}
1001+
1002+
func testTypealias() {
1003+
assertLexicalNameLookup(
1004+
source: """
1005+
typealias SomeType<1️⃣A> = X<2️⃣A, 3️⃣NoMatch>
1006+
1007+
7️⃣typealias SomeOtherType<4️⃣A> = X<5️⃣A, 6️⃣SomeOtherType>
1008+
""",
1009+
references: [
1010+
"2️⃣": [.fromScope(GenericParameterClauseSyntax.self, expectedNames: ["1️⃣"])],
1011+
"3️⃣": [],
1012+
"5️⃣": [.fromScope(GenericParameterClauseSyntax.self, expectedNames: ["4️⃣"])],
1013+
"6️⃣": [.fromFileScope(expectedNames: ["7️⃣"])],
1014+
],
1015+
expectedResultTypes: .all(
1016+
GenericParameterSyntax.self,
1017+
except: ["7️⃣": TypeAliasDeclSyntax.self]
1018+
)
1019+
)
1020+
}
9711021
}

0 commit comments

Comments
 (0)