@@ -636,12 +636,11 @@ func findSyntaxNodeInSourceFile<Node: SyntaxProtocol>(
636
636
var currentSyntax = Syntax ( token)
637
637
var resultSyntax : Node ? = nil
638
638
while let parentSyntax = currentSyntax. parent {
639
- if let typedParent = parentSyntax. as ( type) {
639
+ currentSyntax = parentSyntax
640
+ if let typedParent = currentSyntax. as ( type) {
640
641
resultSyntax = typedParent
641
642
break
642
643
}
643
-
644
- currentSyntax = parentSyntax
645
644
}
646
645
647
646
// If we didn't find anything, complain and fail.
@@ -651,26 +650,16 @@ func findSyntaxNodeInSourceFile<Node: SyntaxProtocol>(
651
650
}
652
651
653
652
// If we want the outermost node, keep looking.
654
- // FIXME: This is VERY SPECIFIC to handling of types. We must be able to
655
- // do better .
653
+ // E.g. for 'foo.bar' we want the member ref expression instead of the
654
+ // identifier expression .
656
655
if wantOutermost {
657
- while let parentSyntax = resultSyntax. parent {
658
- // Look through type compositions.
659
- if let compositionElement = parentSyntax. as ( CompositionTypeElementSyntax . self) ,
660
- let compositionList = compositionElement. parent? . as ( CompositionTypeElementListSyntax . self) ,
661
- let typedParent = compositionList. parent? . as ( type)
662
- {
656
+ while
657
+ let parentSyntax = currentSyntax. parent,
658
+ parentSyntax. position == resultSyntax. position {
659
+ currentSyntax = parentSyntax
660
+ if let typedParent = currentSyntax. as ( type) {
663
661
resultSyntax = typedParent
664
- continue
665
- }
666
-
667
- guard let typedParent = parentSyntax. as ( type) ,
668
- typedParent. position == resultSyntax. position
669
- else {
670
- break
671
662
}
672
-
673
- resultSyntax = typedParent
674
663
}
675
664
}
676
665
0 commit comments