Skip to content

Commit 334fd59

Browse files
committed
Use ConfiguredRegions in LookupConfig for handling #if clauses.
1 parent df86e80 commit 334fd59

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

Sources/SwiftLexicalLookup/LookupConfig.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ import SwiftIfConfig
3333
/// If `finishInSequentialScope` would be set to `false`, the only name
3434
/// returned by lookup would be the `a` declaration from inside function body.
3535
@_spi(Experimental) public var finishInSequentialScope: Bool
36-
@_spi(Experimental) public var buildConfiguration: BuildConfiguration?
36+
@_spi(Experimental) public var configuredRegions: ConfiguredRegions?
3737

3838
/// Creates a new lookup configuration.
3939
///
4040
/// - `finishInSequentialScope` - specifies whether lookup should finish
4141
/// in the closest sequential scope. `false` by default.
4242
@_spi(Experimental) public init(
4343
finishInSequentialScope: Bool = false,
44-
buildConfiguration: BuildConfiguration? = nil
44+
configuredRegions: ConfiguredRegions? = nil
4545
) {
4646
self.finishInSequentialScope = finishInSequentialScope
47-
self.buildConfiguration = buildConfiguration
47+
self.configuredRegions = configuredRegions
4848
}
4949
}

Sources/SwiftLexicalLookup/Scopes/ScopeImplementations.swift

+24-5
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,26 @@ import SwiftSyntax
498498
}
499499

500500
@_spi(Experimental) extension CatchClauseSyntax: ScopeSyntax {
501-
/// Implicit `error` when there are no catch items.
501+
/// Name introduced by the catch clause.
502+
///
503+
/// `defaultIntroducedNames` contains implicit `error` name if
504+
/// no names are declared in catch items and they don't contain any expression patterns.
505+
/// Otherwise, `defaultIntroducedNames` contains names introduced by the clause.
506+
///
507+
/// ### Example
508+
/// ```swift
509+
/// do {
510+
/// // ...
511+
/// } catch SomeError, .x(let a) {
512+
/// // <-- lookup here, result: [a]
513+
/// } catch .x(let a) {
514+
/// // <-- lookup here, result: [a]
515+
/// } catch SomeError {
516+
/// // <-- lookup here, result: [empty]
517+
/// } catch {
518+
/// // <-- lookup here, result: implicit(error)
519+
/// }
520+
/// ```
502521
@_spi(Experimental) public var defaultIntroducedNames: [LookupName] {
503522
var containsExpressionSyntax = false
504523

@@ -942,8 +961,8 @@ extension SubscriptDeclSyntax: WithGenericParametersScopeSyntax, CanInterleaveRe
942961
) -> [LookupResult] {
943962
let clause: IfConfigClauseSyntax?
944963

945-
if let buildConfiguration = config.buildConfiguration {
946-
(clause, _) = activeClause(in: buildConfiguration)
964+
if let configuredRegions = config.configuredRegions {
965+
clause = configuredRegions.activeClause(for: self)
947966
} else {
948967
clause =
949968
clauses
@@ -967,8 +986,8 @@ extension SubscriptDeclSyntax: WithGenericParametersScopeSyntax, CanInterleaveRe
967986
func getNamedDecls(for config: LookupConfig) -> [NamedDeclSyntax] {
968987
let clause: IfConfigClauseSyntax?
969988

970-
if let buildConfiguration = config.buildConfiguration {
971-
(clause, _) = activeClause(in: buildConfiguration)
989+
if let configuredRegions = config.configuredRegions {
990+
clause = configuredRegions.activeClause(for: self)
972991
} else {
973992
clause =
974993
clauses

0 commit comments

Comments
 (0)