Skip to content

Commit 5705b96

Browse files
committed
Add internal _lookup function that passes state.
1 parent b2e5748 commit 5705b96

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

Sources/SwiftLexicalLookup/LookupState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ import Foundation
1717
/// should be skipped during lookup in sequential scopes.
1818
var skipSequentialIntroductionFrom: IntroducingToSequentialParentScopeSyntax?
1919

20-
@_spi(Experimental) public init() {}
20+
init() {}
2121
}

Sources/SwiftLexicalLookup/ScopeImplementations.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import SwiftSyntax
9696
/// - for `memberBlockUpToLastDecl` - a, b, c, d
9797
/// - for `memberBlock` - a, b, c, d, e, f
9898
/// - for `codeBlock` - a
99-
@_spi(Experimental) public func lookup(
99+
@_spi(Experimental) public func _lookup(
100100
for identifier: Identifier?,
101101
at syntax: SyntaxProtocol,
102102
with config: LookupConfig,
@@ -155,7 +155,7 @@ import SwiftSyntax
155155
}
156156
}
157157

158-
@_spi(Experimental) public func lookup(
158+
@_spi(Experimental) public func _lookup(
159159
for identifier: Identifier?,
160160
at syntax: SyntaxProtocol,
161161
with config: LookupConfig,
@@ -277,7 +277,7 @@ import SwiftSyntax
277277
/// // <-- a is not visible here
278278
/// }
279279
/// ```
280-
@_spi(Experimental) public func lookup(
280+
@_spi(Experimental) public func _lookup(
281281
for identifier: Identifier?,
282282
at syntax: SyntaxProtocol,
283283
with config: LookupConfig,
@@ -331,7 +331,7 @@ import SwiftSyntax
331331
/// }
332332
/// // a is visible here
333333
/// ```
334-
@_spi(Experimental) public func lookup(
334+
@_spi(Experimental) public func _lookup(
335335
for identifier: Identifier?,
336336
at syntax: SyntaxProtocol,
337337
with config: LookupConfig,

Sources/SwiftLexicalLookup/ScopeSyntax.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension SyntaxProtocol {
4747
for identifier: Identifier?,
4848
with config: LookupConfig = LookupConfig()
4949
) -> [LookupResult] {
50-
scope?.lookup(for: identifier, at: self, with: config, state: LookupState()) ?? []
50+
scope?.lookup(for: identifier, at: self, with: config) ?? []
5151
}
5252
}
5353

@@ -59,6 +59,16 @@ extension SyntaxProtocol {
5959
/// Finds all declarations `name` refers to. `syntax` specifies the node lookup was triggered with.
6060
/// If `name` set to `nil`, returns all available names at the given node.
6161
func lookup(
62+
for identifier: Identifier?,
63+
at syntax: SyntaxProtocol,
64+
with config: LookupConfig
65+
) -> [LookupResult]
66+
/// Finds all declarations `name` refers to. `syntax` specifies the node lookup was triggered with.
67+
/// If `name` set to `nil`, returns all available names at the given node.
68+
/// `state` represents lookup state passed between lookup methods.
69+
///
70+
/// - Note: This method is intended for internal use only. For public usage, use ``ScopeSyntax/lookup(for:at:with:)`` instead.
71+
func _lookup(
6272
for identifier: Identifier?,
6373
at syntax: SyntaxProtocol,
6474
with config: LookupConfig,
@@ -74,14 +84,28 @@ extension SyntaxProtocol {
7484
/// Returns `LookupResult` of all names introduced in this scope that `name`
7585
/// refers to and is accessible at given syntax node then passes lookup to the parent.
7686
/// If `name` set to `nil`, returns all available names at the given node.
77-
@_spi(Experimental) public func lookup(
87+
/// `state` represents lookup state passed between lookup methods.
88+
///
89+
/// - Note: This method is intended for internal use only. For public usage, use ``ScopeSyntax/lookup(for:at:with:)`` instead.
90+
@_spi(Experimental) public func _lookup(
7891
for identifier: Identifier?,
7992
at syntax: SyntaxProtocol,
8093
with config: LookupConfig,
8194
state: LookupState
8295
) -> [LookupResult] {
8396
defaultLookupImplementation(for: identifier, at: syntax, with: config, state: state)
8497
}
98+
99+
/// Returns `LookupResult` of all names introduced in this scope that `name`
100+
/// refers to and is accessible at given syntax node then passes lookup to the parent.
101+
/// If `name` set to `nil`, returns all available names at the given node.
102+
@_spi(Experimental) public func lookup(
103+
for identifier: Identifier?,
104+
at syntax: SyntaxProtocol,
105+
with config: LookupConfig
106+
) -> [LookupResult] {
107+
_lookup(for: identifier, at: syntax, with: config, state: LookupState())
108+
}
85109

86110
/// Returns `LookupResult` of all names introduced in this scope that `name`
87111
/// refers to and is accessible at given syntax node then passes lookup to the parent.
@@ -113,7 +137,7 @@ extension SyntaxProtocol {
113137
with config: LookupConfig,
114138
state: LookupState
115139
) -> [LookupResult] {
116-
parentScope?.lookup(for: identifier, at: syntax, with: config, state: state) ?? []
140+
parentScope?._lookup(for: identifier, at: syntax, with: config, state: state) ?? []
117141
}
118142

119143
func checkName(_ name: Identifier?, refersTo introducedName: LookupName, at syntax: SyntaxProtocol) -> Bool {

0 commit comments

Comments
 (0)