1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Offset the child range correctly.

This commit is contained in:
Rob Rix 2017-02-10 16:57:33 -05:00
parent f8cc3b8933
commit 2bfc2d91c8

View File

@ -48,14 +48,14 @@ documentToTerm language document SourceBlob{..} = alloca $ \ root -> do
name <- ts_node_p_name node document
name <- peekCString name
count <- ts_node_p_named_child_count node
children <- filter isNonEmpty <$> traverse (alloca . getChild ts_node_p_named_child (start range) node) (take (fromIntegral count) [0..])
children <- filter isNonEmpty <$> traverse (alloca . getChild ts_node_p_named_child node) (take (fromIntegral count) [0..])
let startPos = SourcePos (1 + (fromIntegral $! ts_node_p_start_point_row node)) (1 + (fromIntegral $! ts_node_p_start_point_column node))
let endPos = SourcePos (1 + (fromIntegral $! ts_node_p_end_point_row node)) (1 + (fromIntegral $! ts_node_p_end_point_column node))
let sourceSpan = SourceSpan { spanStart = startPos , spanEnd = endPos }
allChildrenCount <- ts_node_p_child_count node
let allChildren = filter isNonEmpty <$> traverse (alloca . getChild ts_node_p_child (start range) node) (take (fromIntegral allChildrenCount) [0..])
let allChildren = filter isNonEmpty <$> traverse (alloca . getChild ts_node_p_child node) (take (fromIntegral allChildrenCount) [0..])
-- Note: The strict application here is semantically important.
-- Without it, we may not evaluate the value until after weve exited
@ -65,7 +65,7 @@ documentToTerm language document SourceBlob{..} = alloca $ \ root -> do
where getChild getter node n out = do
_ <- getter node n out
let childRange = nodeRange node
toTerm out childRange (slice childRange source)
toTerm out childRange (slice (offsetRange childRange (start childRange - start range)) source)
{-# INLINE getChild #-}
isNonEmpty child = category (extract child) /= Empty