Le 11/08/2014 10:09, Mark Rizun a écrit :
> Hello,
>
> I have MyTextModel class - a subclass of TextModel, it holds an ast of it's
> text.
> When I replace node of the ast using replaceWith: ast is changed, then I say
> text: ast formattedCode, so the text is changed too.
> But! when I inspect new ast(after replacing some node), I see that source
> interval isn't changed. Why?
> If I say bestNodeFor: someInterval, it doesn't give me the right node,
> because sourceInterval of ast wasn't changed, and I don't know why.
> Hope you will help me out:)
It is possible to update the positions, but this isn't easy to do (and
not what an ast user may want in some cases).
In practice, when playing with asts this way, you even specifically want
to keep the positions of the original ast nodes (and another numbering
for the insertions : replacements) so that, if needed, you can make the
distinction between the original nodes and the added nodes.
In short, I would suggest a reparse, especially if you have produced the
output. It will also ensure that bindings and all are properly rebuilt.
Thierry