Skip to content

[SwiftLexicalLookup] Add dollar identifier, better extension handling and more ASTScope related fixes #2877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Sources/SwiftLexicalLookup/LookupResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,34 @@ import SwiftSyntax
/// Indicates where to perform member lookup.
case lookInMembers(LookInMembersScopeSyntax)
/// Indicates to lookup generic parameters of extended type.
///
/// ### Example
/// ```swift
/// extension Foo {
/// func bar() {
/// let a = A() // <-- lookup here
/// }
/// }
/// ```
/// For a lookup started at the marked position, `lookInGenericParametersOfExtendedType`
/// will be included as one of the results prompting the client
/// to lookup the generic parameters of of the extended `Foo` type.
case lookInGenericParametersOfExtendedType(ExtensionDeclSyntax)
/// Indicates this closure expression could introduce dollar identifiers.
///
/// ### Example
/// ```swift
/// func foo() {
/// let a = {
/// $0 // <-- lookup here
/// }
/// }
/// ```
/// When looking up for any identifier at the indicated position,
/// the result will include `mightIntroduceDollarIdentifiers`
/// result kind. If it's performed for a dollar identifier, `LookupName.dollarIdentifier`
/// with the appropriate identifier will be used in the
/// result associated with the closure expression inside `a`.
case mightIntroduceDollarIdentifiers(ClosureExprSyntax)

/// Associated scope.
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftLexicalLookup/Scopes/ScopeImplementations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,14 @@ import SwiftSyntax
if inRightTypeOrSameTypeRequirement(lookUpPosition) {
return [.lookInGenericParametersOfExtendedType(self)] + [.lookInMembers(self)]
+ defaultLookupImplementation(identifier, at: lookUpPosition, with: config)
} else {
return [.lookInGenericParametersOfExtendedType(self)]
+ defaultLookupImplementation(identifier, at: lookUpPosition, with: config)
}
} else {

return [.lookInGenericParametersOfExtendedType(self)]
+ lookupInParent(identifier, at: lookUpPosition, with: config)
+ defaultLookupImplementation(identifier, at: lookUpPosition, with: config)
}

return [.lookInGenericParametersOfExtendedType(self)]
+ lookupInParent(identifier, at: lookUpPosition, with: config)
}

/// Returns `true` if `checkedPosition` is a right type of a
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftLexicalLookupTest/ExpectedName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ enum NameExpectation: ExpectedName {
case (.declaration, .declaration): break
case (.implicit(let implicitName), .implicit(let implicitNameExpectation)):
implicitNameExpectation.assertExpectation(marker: marker, for: implicitName)
case (.dollarIdentifier(_, let acutalStr), .dollarIdentifier(_, let expectedStr)):
case (.dollarIdentifier(_, let actualStr), .dollarIdentifier(_, let expectedStr)):
XCTAssert(
acutalStr == expectedStr,
"For marker \(marker), actual identifier \(acutalStr) doesn't match expected \(expectedStr)"
actualStr == expectedStr,
"For marker \(marker), actual identifier \(actualStr) doesn't match expected \(expectedStr)"
)
default:
XCTFail("For marker \(marker), actual name kind \(name) doesn't match expected \(self)")
Expand Down