1
- {-# LANGUAGE TemplateHaskell #-}
2
- {-# LANGUAGE DeriveGeneric #-}
1
+ {-# LANGUAGE DeriveGeneric #-}
2
+ {-# LANGUAGE TemplateHaskell #-}
3
3
module Language.LSP.Types.Location where
4
4
5
5
import Control.DeepSeq
6
6
import Data.Aeson.TH
7
7
import Data.Hashable
8
- import GHC.Generics hiding (UInt )
8
+ import GHC.Generics hiding (UInt )
9
9
import Language.LSP.Types.Common
10
10
import Language.LSP.Types.Uri
11
11
import Language.LSP.Types.Utils
@@ -33,8 +33,8 @@ instance Hashable Position
33
33
34
34
data Range =
35
35
Range
36
- { _start :: Position -- ^ The range's start position.
37
- , _end :: Position -- ^ The range's end position.
36
+ { _start :: Position -- ^ The range's start position. (inclusive)
37
+ , _end :: Position -- ^ The range's end position. (exclusive)
38
38
} deriving (Show , Read , Eq , Ord , Generic )
39
39
40
40
instance NFData Range
@@ -65,12 +65,12 @@ data LocationLink =
65
65
-- range at the mouse position.
66
66
_originSelectionRange :: Maybe Range
67
67
-- | The target resource identifier of this link.
68
- , _targetUri :: Uri
68
+ , _targetUri :: Uri
69
69
-- | The full target range of this link. If the target for example is a
70
70
-- symbol then target range is the range enclosing this symbol not including
71
71
-- leading/trailing whitespace but everything else like comments. This
72
72
-- information is typically used to highlight the range in the editor.
73
- , _targetRange :: Range
73
+ , _targetRange :: Range
74
74
-- | The range that should be selected and revealed when this link is being
75
75
-- followed, e.g the name of a function. Must be contained by the the
76
76
-- 'targetRange'. See also @DocumentSymbol._range@
@@ -84,3 +84,9 @@ deriveJSON lspOptions ''LocationLink
84
84
-- prop> mkRange l c l' c' = Range (Position l c) (Position l' c')
85
85
mkRange :: UInt -> UInt -> UInt -> UInt -> Range
86
86
mkRange l c l' c' = Range (Position l c) (Position l' c')
87
+
88
+ subRange :: Range -> Range -> Bool
89
+ subRange smallRange range = _start smallRange >= _start range && _end smallRange <= _end range
90
+
91
+ positionInRange :: Position -> Range -> Bool
92
+ positionInRange p (Range sp ep) = sp <= p && p < ep
0 commit comments