I personally think a stack at the top showing each expandable item in the path to the current view would be good. Apple added this to Xcode 15, and it's really nice on smaller screens. As you scroll down, containers get pinned to the top and subsequent lines scroll by under them.
In that example, you can see it has skipped some lines between the "struct DonutBarChart" on line 24 and the "var body" on line 33. Scroll down past the end of the "var body" block, and "var barChart" on line 41 will get pinned to the second level.
It's hard to explain, but incredibly obvious what's going on when you see it in action.