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