Let's say I have two SyntaxTree
s A and B,
where B has been produced by applying changes to A.
I would like to get the following information:
Is there an API for this?
If not, how can this be efficiently computed?
This information must be available to Roslyn,
since unchanged GreenNode
s are shared between the trees.
One solution I can think of is to use SyntaxTree.GetChangedSpans()
and then lookup the intersecting tokens.
However that feels like a hack and I'm not sure if it is always accurate.
A small text change might have a large impact on a SyntaxTree
:
(e.g. replacing *
with +
in an expression might change its order/precedence)
We internally have a differ that lives in the compiler layer and thus uses green nodes, we just haven't exposed it as an API. This is what we use to drive GetChangedSpans, actually. We intentionally didn't expose green nodes directly because that's an implementation detail.
There's no specific reason that API couldn't be public. I think when this one came around we were worried about how one actually specs what the behavior is, or what's a minimal "goodness" you can expect from the diff. That, and we didn't have a motivating scenario to actually make sure our work was useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With