@@ -826,50 +826,11 @@ extension SwiftLanguageServer {
826
826
827
827
/// If `position` is on an argument label or a parameter name, find the position of the function's base name.
828
828
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
-
868
829
let tree = await self . syntaxTreeManager. syntaxTree ( for: snapshot)
869
830
guard let absolutePosition = snapshot. position ( of: position) else {
870
831
return nil
871
832
}
872
- guard let token = TokenFinder . findToken ( at: absolutePosition, in : tree ) else {
833
+ guard let token = tree . token ( at: absolutePosition) else {
873
834
return nil
874
835
}
875
836
0 commit comments