@@ -131,7 +131,8 @@ public struct SwiftFocusedCodeFinder: FocusedCodeFinderType {
131131 contextRange: contextRange,
132132 focusedRange: codeRange,
133133 focusedCode: code,
134- imports: visitor. imports
134+ imports: visitor. imports,
135+ includes: [ ]
135136 )
136137 }
137138}
@@ -465,142 +466,3 @@ extension String {
465466 }
466467}
467468
468- // MARK: - Visitors
469-
470- extension SwiftFocusedCodeFinder {
471- final class SwiftScopeHierarchySyntaxVisitor : SyntaxVisitor {
472- let tree : SyntaxProtocol
473- let code : String
474- let range : CursorRange
475- let locationConverter : SourceLocationConverter
476-
477- var imports : [ String ] = [ ]
478- private var _scopeHierarchy : [ SyntaxProtocol ] = [ ]
479-
480- /// The nodes containing the current range, sorted from inner to outer.
481- func findScopeHierarchy( _ node: some SyntaxProtocol ) -> [ SyntaxProtocol ] {
482- walk ( node)
483- return _scopeHierarchy. sorted { $0. position. utf8Offset > $1. position. utf8Offset }
484- }
485-
486- /// The nodes containing the current range, sorted from inner to outer.
487- func findScopeHierarchy( ) -> [ SyntaxProtocol ] {
488- walk ( tree)
489- return _scopeHierarchy. sorted { $0. position. utf8Offset > $1. position. utf8Offset }
490- }
491-
492- init (
493- tree: SyntaxProtocol ,
494- code: String ,
495- range: CursorRange ,
496- locationConverter: SourceLocationConverter
497- ) {
498- self . tree = tree
499- self . code = code
500- self . range = range
501- self . locationConverter = locationConverter
502- super. init ( viewMode: . sourceAccurate)
503- }
504-
505- func skipChildrenIfPossible( _ node: SyntaxProtocol ) -> SyntaxVisitorContinueKind {
506- if _scopeHierarchy. count > 5 { return . skipChildren }
507- if !nodeContainsRange( node) { return . skipChildren }
508- return . visitChildren
509- }
510-
511- func captureNodeIfPossible( _ node: SyntaxProtocol ) -> SyntaxVisitorContinueKind {
512- if _scopeHierarchy. count > 5 { return . skipChildren }
513- if !nodeContainsRange( node) { return . skipChildren }
514- _scopeHierarchy. append ( node)
515- return . visitChildren
516- }
517-
518- func nodeContainsRange( _ node: SyntaxProtocol ) -> Bool {
519- let sourceRange = node. sourceRange ( converter: locationConverter)
520- let cursorRange = CursorRange ( sourceRange: sourceRange)
521- return cursorRange. strictlyContains ( range)
522- }
523-
524- // skip if possible
525-
526- override func visit( _ node: MemberDeclBlockSyntax ) -> SyntaxVisitorContinueKind {
527- skipChildrenIfPossible ( node)
528- }
529-
530- override func visit( _ node: MemberDeclListItemSyntax ) -> SyntaxVisitorContinueKind {
531- skipChildrenIfPossible ( node)
532- }
533-
534- // capture if possible
535-
536- override func visit( _ node: ImportDeclSyntax ) -> SyntaxVisitorContinueKind {
537- imports. append ( node. path. trimmedDescription)
538- return . skipChildren
539- }
540-
541- override func visit( _ node: StructDeclSyntax ) -> SyntaxVisitorContinueKind {
542- captureNodeIfPossible ( node)
543- }
544-
545- override func visit( _ node: ClassDeclSyntax ) -> SyntaxVisitorContinueKind {
546- captureNodeIfPossible ( node)
547- }
548-
549- override func visit( _ node: EnumDeclSyntax ) -> SyntaxVisitorContinueKind {
550- captureNodeIfPossible ( node)
551- }
552-
553- override func visit( _ node: ActorDeclSyntax ) -> SyntaxVisitorContinueKind {
554- captureNodeIfPossible ( node)
555- }
556-
557- override func visit( _ node: MacroDeclSyntax ) -> SyntaxVisitorContinueKind {
558- captureNodeIfPossible ( node)
559- }
560-
561- override func visit( _ node: ProtocolDeclSyntax ) -> SyntaxVisitorContinueKind {
562- captureNodeIfPossible ( node)
563- }
564-
565- override func visit( _ node: ExtensionDeclSyntax ) -> SyntaxVisitorContinueKind {
566- captureNodeIfPossible ( node)
567- }
568-
569- override func visit( _ node: FunctionDeclSyntax ) -> SyntaxVisitorContinueKind {
570- captureNodeIfPossible ( node)
571- }
572-
573- override func visit( _ node: SubscriptDeclSyntax ) -> SyntaxVisitorContinueKind {
574- captureNodeIfPossible ( node)
575- }
576-
577- override func visit( _ node: ClosureExprSyntax ) -> SyntaxVisitorContinueKind {
578- captureNodeIfPossible ( node)
579- }
580-
581- override func visit( _ node: VariableDeclSyntax ) -> SyntaxVisitorContinueKind {
582- captureNodeIfPossible ( node)
583- }
584-
585- override func visit( _ node: AccessorDeclSyntax ) -> SyntaxVisitorContinueKind {
586- captureNodeIfPossible ( node)
587- }
588-
589- override func visit( _ node: InitializerDeclSyntax ) -> SyntaxVisitorContinueKind {
590- captureNodeIfPossible ( node)
591- }
592-
593- override func visit( _ node: DeinitializerDeclSyntax ) -> SyntaxVisitorContinueKind {
594- captureNodeIfPossible ( node)
595- }
596-
597- override func visit( _ node: FunctionCallExprSyntax ) -> SyntaxVisitorContinueKind {
598- captureNodeIfPossible ( node)
599- }
600-
601- override func visit( _ node: SwitchCaseSyntax ) -> SyntaxVisitorContinueKind {
602- captureNodeIfPossible ( node)
603- }
604- }
605- }
606-
0 commit comments