Iterating skipped/whitespace nodes in a SyntaxTree

I’m working on designing a code formatting extension for CodeMirror. My understanding of the high-level process Prettier uses is to first parse the code and then use the AST to generate new code, applying a set of standardized formatting rules. My general plan is to have an extension use the AST produced by the CM parser and identify places where the actual code diverges from the “correctly formatted” code, represented as a potential ChangeSet.

For now, I’m trying to get a handle on iterating over a SyntaxTree. Given that formatting deals particularly with whitespace, I’m interested in identifying the whitespace nodes (or lack of node) in the tree. Is this possible with a TreeCursor? The NodeType.isSkipped field indicates that a node is produced by a skip rule. Am I correct in thinking that this means a node produced by the (for example) @skip { whitespace } directive in a grammar? So far, the only place I’ve seen nodes where isSkipped is true are nodes where isError is also true, which would seem to be two distinct properties of a node, right?

I could treat the negative space between nodes as indicating a gap between nodes, but I’m curious if there’s any additional information I could be getting from the parse tree. Thanks!

Typically, whitespace isn’t encoded in the tree (as a lower-case node name), so there’s no way to see where it was matched. isSkipped is often used for comment nodes, so that they can be highlighted.