Skip to content

Commit bb28ab7

Browse files
committed
Remove createResultsForThisScopeWith parameter from sequentialLookup method.
1 parent d457715 commit bb28ab7

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Sources/SwiftLexicalLookup/LookupResult.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@ import SwiftSyntax
3636
return names
3737
}
3838
}
39+
40+
/// Returns result specific for the particular `scope` kind with provided `names`.
41+
static func getResult(for scope: ScopeSyntax, withNames names: [LookupName]) -> LookupResult {
42+
switch Syntax(scope).as(SyntaxEnum.self) {
43+
case .sourceFile(let sourceFileSyntax):
44+
return .fromFileScope(sourceFileSyntax, withNames: names)
45+
default:
46+
return .fromScope(scope, withNames: names)
47+
}
48+
}
3949
}

Sources/SwiftLexicalLookup/ScopeImplementations.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ import SwiftSyntax
134134
in: sequentialItems,
135135
identifier,
136136
at: lookUpPosition,
137-
with: config,
138-
createResultsForThisScopeWith: { .fromFileScope(self, withNames: $0) }
137+
with: config
139138
)
140139

141140
return (members.isEmpty ? [] : [.fromFileScope(self, withNames: members)]) + sequentialNames
@@ -161,8 +160,7 @@ import SwiftSyntax
161160
in: statements,
162161
identifier,
163162
at: lookUpPosition,
164-
with: config,
165-
createResultsForThisScopeWith: { .fromScope(self, withNames: $0) }
163+
with: config
166164
)
167165
}
168166
}

Sources/SwiftLexicalLookup/SequentialScopeSyntax.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ extension SequentialScopeSyntax {
4242
in codeBlockItems: some Collection<CodeBlockItemSyntax>,
4343
_ identifier: Identifier?,
4444
at lookUpPosition: AbsolutePosition,
45-
with config: LookupConfig,
46-
createResultsForThisScopeWith getResults: ([LookupName]) -> (LookupResult)
45+
with config: LookupConfig
4746
) -> [LookupResult] {
4847
// Sequential scope needs to ensure all type declarations are
4948
// available in the whole scope (first loop) and
@@ -88,7 +87,7 @@ extension SequentialScopeSyntax {
8887

8988
// If there are some names collected, create a new result for this scope.
9089
if !currentChunk.isEmpty {
91-
results.append(getResults(currentChunk))
90+
results.append(LookupResult.getResult(for: self, withNames: currentChunk))
9291
currentChunk = []
9392
}
9493

@@ -106,7 +105,7 @@ extension SequentialScopeSyntax {
106105

107106
// If there are some names collected, create a new result for this scope.
108107
if !currentChunk.isEmpty {
109-
results.append(getResults(currentChunk))
108+
results.append(LookupResult.getResult(for: self, withNames: currentChunk))
110109
}
111110

112111
return results.reversed() + lookupInParent(identifier, at: lookUpPosition, with: config)

0 commit comments

Comments
 (0)