As I understand it, the
rowan crate is developed by the
rust-analyzer team, right? I had a few questions regarding it.
Mainly, is there a way I can change the "position" of a token? I've just been doing
"some code".into() when passing the
text argument of
GreenNodeBuilder::token, which doesn't appear to do what I want
I don't think
GreenNodes even know about positions. Only
And from what I can see you cant arbitrarily set a tokens or nodes position as its based on the entire tree, but I might be wrong.
Looking at the output of
dbg!(&builder), I think you're right. I had assumed that it might have been something that was part of
Any ideas on how I might be able to go about something similar? I want to be able to display the position of errors in source code, just like rust.
Why do you need to change the position for that?
you want to insert the error messages into the source?
No, what I want is to be able to accurately figure out where a token came from in the source code
Those TextRanges contain the offset and the size the text of the node spans
Right, but only within text that has been turned into some token. If i want to ignore whitespace, then all of the positions of keywords will be distorted
Well, SyntaxNodes only know their positions based on the entire text of the tree they belong to. If you want to ignore whitespace and have positions according to the whitespace-less text you would have to reconstruct the tree without the whitespace tokens.
Ah alright. Thanks!