Commit Graph

7 Commits

Author SHA1 Message Date
Alex Hoppen
56bf9a3469 [SwiftSyntax] Refactor AbsolutePosition
AbsolutePosition being a mutable reference type easily leads to bugs
where an AbsolutePosition is modified. Making it immutable eliminates
this issue. Furthermore, the introduction of SourceLength should allow
easier manipulation of AbsolutePositions on the client side.

We still cannot make AbsolutePosition a value type since it is used
inside AtomicCache, but the immutability gives the same safety.
2018-08-01 11:55:35 -07:00
Harlan Haskins
572a144d2d Rename byteOffset to utf8Offset and remove utf16 2018-04-24 16:14:37 -04:00
Harlan Haskins
6189e6f1e9 Simplify AbsolutePosition offset calculation and support columns 2018-04-24 11:42:24 -04:00
Xi Ge
20bc656261 SwiftSyntax: make absolute position calculation independent of specific encoding. NFC (#15352) 2018-03-19 16:33:05 -07:00
Xi Ge
af868778b6 SwiftSyntax: add an API to teach Trivia to calculate byte size. (#15251)
This missing piece will allow clients to customize the size of
SyntaxNode better.
2018-03-14 17:14:52 -07:00
Xi Ge
ee36dbeda3 [WIP] SwiftSyntax: Implement APIs for Syntax nodes to calculate absolute positions. (#15097)
Syntax nodes are designed as reusable blocks to construct Swift source
code. For this reason, we don't track absolute position in each node;
instead, the absolute position should be calculated on the fly when
needed. We recently found absolute positions are useful to bridge with
sourcekitd, which typically speaks in the language of line, column and
offset. Therefore, this patch tries to add a computed
property on SyntaxNode to get its absolute position.

To compute the absolute position of a SyntaxNode from scratch requires tree traversal.
However, getting the absolute position from these added APIs doesn't necessarily
mean we'll traverse since SyntaxData will actively cache the computed position.
Also, since we recursively compute the absolute position, all the position caches
for a SyntaxNode's previous siblings and ancestors will be populated as well during
the calculation of this SyntaxNode.
2018-03-12 15:42:46 -07:00
Xi Ge
e61c8958fd SwiftSyntax: simply trivia implementation on the Swift side. 2018-03-07 16:19:09 -08:00