Sable / mclab-ide

MATLAB IDE prototype
Apache License 2.0
6 stars 2 forks source link

Add mechanism for getting at parent AST nodes #5

Open isbadawi opened 10 years ago

isbadawi commented 10 years ago

In a couple of places we go from an ace token (e.g. that was clicked, on in a selection) to an AST node, using line/column positions as a bridge. This is sort of brittle to begin with, and of limited usefulness because we can only get at the node that has that exact position.

One way this manifests is that to jump to the callers of an anonymous function, we have to click the @, because that's the token that has the same position as the LambdaExpr AST node. It would be nice to click anywhere in the body.

To address this (and also more generally), it would be nice if we could get at the parents of a given AST node, either as fields on the nodes or maybe exposed by a tree walking function (similar to traverseAst but passing in e.g. the path from the root -- see estraverse project for inspiration). Then, if we click somewhere and say "jump to caller", we could get at the node with that position and walk up the tree until we hit a node that can be a call target.