Open zurk opened 6 years ago
It's an interesting request. We approved adding an "structural parent" to some nodes, that would link them with the "high level structure" (function, class, etc) where they belong, even if they're several levels below. Anyway we're in the middle of a complete rewrite of the SDK and the annotations but after that is completed we could evaluate this and how to do it.
ok, it can wait, I have workarounds.
@zurk As a retrospective, have you used the SDK or Go/Python client?
I definitely used the "@internalRole" selector in the implementation of many SonarSource checks, which is not exactly the same, but I can imagine getting the parent node could be useful. But just as a side note, with XPath you can get the parent of the node with the query "/parent::*"
Yes, this is why I'm trying to figure where exactly the parent field can be helpful. Probably the native client data structures.
@dennwc I use Python client.
I need this field in some complex traversing scenarios. For example, if I need to find the shortest path between two leaves. So it is not about XPath queries, more about class property like node.parent
@dennwc any updates? Maybe this issue should be moved to python client?
Sometimes it is important to keep it on hands.
If there is no such field you need to store all parents while performing some complicated UAST traversing.