Skip to content

Commit c5988ed

Browse files
committed
Improve documentation.
1 parent 940b06e commit c5988ed

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

Sources/SwiftLexicalLookup/Configurations/FileScopeNameIntroductionStrategy.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import SwiftSyntax
1414

1515
/// Specifies how names should be introduced at the file scope.
1616
@_spi(Experimental) public enum FileScopeHandlingConfig {
17-
/// Default behavior. Names introduced sequentially like in member block
18-
/// scope up to the first non-declaration after and including which,
19-
/// the declarations are treated like in code block scope.
17+
/// This is the behavior that is being used
18+
/// for Swift files with top-level code.
2019
case memberBlockUpToLastDecl
21-
/// File scope behaves like member block scope.
20+
/// This is the behavior that is being used
21+
/// for Swift files that don’t allow top-level code.
2222
case memberBlock
23-
/// File scope behaves like code block scope.
23+
/// This is the behavior that is being used for e.g. function bodies.
2424
case codeBlock
2525
}

Sources/SwiftLexicalLookup/Configurations/LookupConfig.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
import Foundation
1414

1515
@_spi(Experimental) public struct LookupConfig {
16-
/// Specifies behaviour of file scope.
17-
/// `memberBlockUpToLastDecl` by default.
16+
/// Specifies behavior of file scope.
1817
@_spi(Experimental) public var fileScopeHandling: FileScopeHandlingConfig
1918

19+
/// Creates a new lookup configuration.
20+
///
21+
/// - `fileScopeHandling` - specifies behavior of file scope.
22+
/// `memberBlockUpToLastDecl` by default.
2023
@_spi(Experimental) public init(
2124
fileScopeHandling: FileScopeHandlingConfig = .memberBlockUpToLastDecl
2225
) {

Sources/SwiftLexicalLookup/LookupName.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ import SwiftSyntax
125125
}
126126

127127
/// Extracts names introduced by the given `syntax` structure.
128+
///
129+
/// When e.g. looking up a variable declaration like `let a = a`,
130+
/// we expect `a` to be visible after the whole declaration.
131+
/// That's why we can't just use `syntax.endPosition` for the `a` identifier pattern,
132+
/// as the name would already be visible at the `a` reference withing the declaration.
133+
/// That’s why code block and file scopes have to set
134+
/// `accessibleAfter` to be the end position of the entire declaration syntax node.
128135
static func getNames(
129136
from syntax: SyntaxProtocol,
130137
accessibleAfter: AbsolutePosition? = nil

Sources/SwiftLexicalLookup/ScopeImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import SwiftSyntax
8181
}
8282

8383
/// Returns names matching lookup using provided file
84-
/// scope handling configuration (by default: `memberBlockUpToLastDecl`).
84+
/// scope handling configuration.
8585
///
8686
/// Example usage:
8787
/// ```swift

0 commit comments

Comments
 (0)