mirror of
https://github.com/github/semantic.git
synced 2025-01-05 14:11:33 +03:00
Properly calculate range for subterms
This commit is contained in:
parent
ac4df9a7b3
commit
7ba739a508
@ -20,6 +20,10 @@ rangeAt a = Range a a
|
|||||||
rangeLength :: Range -> Int
|
rangeLength :: Range -> Int
|
||||||
rangeLength range = end range - start range
|
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.
|
-- | Return a range that covers the entire text.
|
||||||
-- totalRange :: Foldable f => f a -> Range
|
-- totalRange :: Foldable f => f a -> Range
|
||||||
-- totalRange t = Range 0 $ length t
|
-- totalRange t = Range 0 $ length t
|
||||||
|
@ -9,6 +9,7 @@ import Data.Record
|
|||||||
import Diff
|
import Diff
|
||||||
import Info
|
import Info
|
||||||
import Prologue
|
import Prologue
|
||||||
|
import Range
|
||||||
import qualified Data.List as List
|
import qualified Data.List as List
|
||||||
import qualified Data.Map as Map hiding (null)
|
import qualified Data.Map as Map hiding (null)
|
||||||
import Renderer
|
import Renderer
|
||||||
@ -164,5 +165,6 @@ toTermName source term = case unwrap term of
|
|||||||
_ -> toText source
|
_ -> toText source
|
||||||
where
|
where
|
||||||
toTermName' :: SyntaxTerm leaf fields -> Text
|
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
|
range = characterRange . extract
|
||||||
|
Loading…
Reference in New Issue
Block a user