File tree Expand file tree Collapse file tree 4 files changed +18
-8
lines changed
Sources/SwiftLexicalLookup Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -14,12 +14,12 @@ import SwiftSyntax
14
14
15
15
/// Specifies how names should be introduced at the file scope.
16
16
@_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.
20
19
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.
22
22
case memberBlock
23
- /// File scope behaves like code block scope .
23
+ /// This is the behavior that is being used for e.g. function bodies .
24
24
case codeBlock
25
25
}
Original file line number Diff line number Diff line change 13
13
import Foundation
14
14
15
15
@_spi ( Experimental) public struct LookupConfig {
16
- /// Specifies behaviour of file scope.
17
- /// `memberBlockUpToLastDecl` by default.
16
+ /// Specifies behavior of file scope.
18
17
@_spi ( Experimental) public var fileScopeHandling : FileScopeHandlingConfig
19
18
19
+ /// Creates a new lookup configuration.
20
+ ///
21
+ /// - `fileScopeHandling` - specifies behavior of file scope.
22
+ /// `memberBlockUpToLastDecl` by default.
20
23
@_spi ( Experimental) public init (
21
24
fileScopeHandling: FileScopeHandlingConfig = . memberBlockUpToLastDecl
22
25
) {
Original file line number Diff line number Diff line change @@ -125,6 +125,13 @@ import SwiftSyntax
125
125
}
126
126
127
127
/// 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.
128
135
static func getNames(
129
136
from syntax: SyntaxProtocol ,
130
137
accessibleAfter: AbsolutePosition ? = nil
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ import SwiftSyntax
81
81
}
82
82
83
83
/// Returns names matching lookup using provided file
84
- /// scope handling configuration (by default: `memberBlockUpToLastDecl`) .
84
+ /// scope handling configuration.
85
85
///
86
86
/// Example usage:
87
87
/// ```swift
You can’t perform that action at this time.
0 commit comments