1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 13:02:37 +03:00

Properly calculate range for subterms

This commit is contained in:
Timothy Clem 2017-02-09 14:47:35 -08:00
parent ac4df9a7b3
commit 7ba739a508
2 changed files with 7 additions and 1 deletions

View File

@ -20,6 +20,10 @@ rangeAt a = Range a a
rangeLength :: Range -> Int
rangeLength range = end range - start range
-- | Subtract an offset from a Range.
subtractRange :: Range -> Int -> Range
subtractRange a b = Range (start a - b) (end a - b)
-- | Return a range that covers the entire text.
-- totalRange :: Foldable f => f a -> Range
-- totalRange t = Range 0 $ length t

View File

@ -9,6 +9,7 @@ import Data.Record
import Diff
import Info
import Prologue
import Range
import qualified Data.List as List
import qualified Data.Map as Map hiding (null)
import Renderer
@ -164,5 +165,6 @@ toTermName source term = case unwrap term of
_ -> toText source
where
toTermName' :: SyntaxTerm leaf fields -> Text
toTermName' subterm = toTermName (Source.slice (range subterm) source) subterm
toTermName' subterm = toTermName (Source.slice (range' subterm) source) subterm
range' subterm = subtractRange (range subterm) (start (range term))
range = characterRange . extract