1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 00:42:33 +03:00

Properly slice source for root node

Fixes a nasty bug where source files that begin with a newline weren't
getting properly sliced at the root node (code was erroneously assuming
that the first node starts at byte 0). If a file starts with a newline
the program node ends up starting at byte 1 and everything afterward was
offset by one.
This commit is contained in:
Timothy Clem 2017-06-14 10:29:11 -06:00
parent e8165a0d28
commit 8f6d25b9d8

View File

@ -72,11 +72,11 @@ safeToEnum n | (fromEnum (minBound :: n), fromEnum (maxBound :: n)) `inRange` n
-- | Return a parser for a tree sitter language & document.
documentToTerm :: Language -> Ptr Document -> Source -> IO (Term (Syntax.Syntax Text) (Record DefaultFields))
documentToTerm language document source = do
documentToTerm language document allSource = do
root <- alloca (\ rootPtr -> do
ts_document_root_node_p document rootPtr
peek rootPtr)
toTerm root source
toTerm root (slice (nodeRange root) allSource)
where toTerm :: Node -> Source -> IO (Term (Syntax.Syntax Text) (Record DefaultFields))
toTerm node source = do
name <- peekCString (nodeType node)