on b9dfd49 help sign in
63 lines 2.1 kB history raw
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4-- ORIGINALLY COPIED FROM https://github.com/commercialhaskell/intero
6-- | Types used separate to GHCi vanilla.
8module Development.IDE.Types.SpanInfo(
9 SpanInfo(..)
10 , SpanSource(..)
11 , getNameM
12 , getSrcSpan
13 ) where
15import GHC
16import Data.Maybe
17import OccName
20-- | Type of some span of source code. Most of these fields are
21-- unboxed but Haddock doesn't show that.
22data SpanInfo =
23 SpanInfo {spaninfoStartLine :: {-# UNPACK #-} !Int
24 -- ^ Start line of the span.
25 ,spaninfoStartCol :: {-# UNPACK #-} !Int
26 -- ^ Start column of the span.
27 ,spaninfoEndLine :: {-# UNPACK #-} !Int
28 -- ^ End line of the span (absolute).
29 ,spaninfoEndCol :: {-# UNPACK #-} !Int
30 -- ^ End column of the span (absolute).
31 ,spaninfoType :: !(Maybe Type)
32 -- ^ A pretty-printed representation fo the type.
33 ,spaninfoSource :: !SpanSource
34 -- ^ The actutal 'Name' associated with the span, if
35 -- any. This can be useful for accessing a variety of
36 -- information about the identifier such as module,
37 -- locality, definition location, etc.
38 }
39instance Show SpanInfo where
40 show (SpanInfo sl sc el ec t n) = show [show sl, show sc, show el, show ec, show $ isJust t, show n]
42-- we don't always get a name out so sometimes manually annotating source is more appropriate
43data SpanSource = Named Name
44 | Span SrcSpan
45 | NoSource
46 deriving (Eq)
48instance Show SpanSource where
49 show = \case
50 Named n -> "Named " ++ occNameString (occName n)
51 Span sp -> "Span " ++ show sp
52 NoSource -> "NoSource"
54getNameM :: SpanSource -> Maybe Name
55getNameM = \case
56 Named name -> Just name
57 _ -> Nothing
59getSrcSpan :: SpanSource -> Maybe SrcSpan
60getSrcSpan = \case
61 NoSource -> Nothing
62 Span sp -> Just sp
63 Named name -> Just $ nameSrcSpan name