Skip to content

Commit a208099

Browse files
committed
Remove TokenFinder
swift-syntax has functionality for this built in.
1 parent 6c53c64 commit a208099

File tree

1 file changed

+1
-40
lines changed

1 file changed

+1
-40
lines changed

Sources/SourceKitLSP/Rename.swift

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -826,50 +826,11 @@ extension SwiftLanguageServer {
826826

827827
/// If `position` is on an argument label or a parameter name, find the position of the function's base name.
828828
private func findFunctionBaseNamePosition(of position: Position, in snapshot: DocumentSnapshot) async -> Position? {
829-
class TokenFinder: SyntaxAnyVisitor {
830-
/// The position at which the token should be found.
831-
let position: AbsolutePosition
832-
833-
/// Once found, the token at the requested position.
834-
var foundToken: TokenSyntax?
835-
836-
init(position: AbsolutePosition) {
837-
self.position = position
838-
super.init(viewMode: .sourceAccurate)
839-
}
840-
841-
override func visitAny(_ node: Syntax) -> SyntaxVisitorContinueKind {
842-
guard (node.position..<node.endPosition).contains(position) else {
843-
// Node doesn't contain the position. No point visiting it.
844-
return .skipChildren
845-
}
846-
guard foundToken == nil else {
847-
// We have already found a token. No point visiting this one
848-
return .skipChildren
849-
}
850-
return .visitChildren
851-
}
852-
853-
override func visit(_ token: TokenSyntax) -> SyntaxVisitorContinueKind {
854-
if (token.position..<token.endPosition).contains(position) {
855-
self.foundToken = token
856-
}
857-
return .skipChildren
858-
}
859-
860-
/// Dedicated entry point for `TokenFinder`.
861-
static func findToken(at position: AbsolutePosition, in tree: some SyntaxProtocol) -> TokenSyntax? {
862-
let finder = TokenFinder(position: position)
863-
finder.walk(tree)
864-
return finder.foundToken
865-
}
866-
}
867-
868829
let tree = await self.syntaxTreeManager.syntaxTree(for: snapshot)
869830
guard let absolutePosition = snapshot.position(of: position) else {
870831
return nil
871832
}
872-
guard let token = TokenFinder.findToken(at: absolutePosition, in: tree) else {
833+
guard let token = tree.token(at: absolutePosition) else {
873834
return nil
874835
}
875836

0 commit comments

Comments
 (0)