on 8bce2dd help sign in
61 lines 2.0 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.Spans.Type(
9 SpanInfo(..)
10 , SpanSource(..)
11 , getNameM
12 ) where
14import GHC
15import Control.DeepSeq
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, zero-based.
25 ,spaninfoStartCol :: {-# UNPACK #-} !Int
26 -- ^ Start column of the span, zero-based.
27 ,spaninfoEndLine :: {-# UNPACK #-} !Int
28 -- ^ End line of the span (absolute), zero-based.
29 ,spaninfoEndCol :: {-# UNPACK #-} !Int
30 -- ^ End column of the span (absolute), zero-based.
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]
42instance NFData SpanInfo where
43 rnf = rwhnf
46-- we don't always get a name out so sometimes manually annotating source is more appropriate
47data SpanSource = Named Name
48 | SpanS SrcSpan
49 | NoSource
50 deriving (Eq)
52instance Show SpanSource where
53 show = \case
54 Named n -> "Named " ++ occNameString (occName n)
55 SpanS sp -> "Span " ++ show sp
56 NoSource -> "NoSource"
58getNameM :: SpanSource -> Maybe Name
59getNameM = \case
60 Named name -> Just name
61 _ -> Nothing