module Hoogle.Type.Item where
import General.Base
import Data.Binary.Defer
import Data.Binary.Defer.Index
import Hoogle.Type.Documentation
import Hoogle.Type.TagStr
import Hoogle.Type.TypeSig
import Data.Generics.Uniplate
type Input = ([Fact], [TextItem])
data TextItem = TextItem
{itemLevel :: Int
,itemKey :: String
,itemName :: String
,itemType :: Maybe TypeSig
,itemDisp :: TagStr
,itemURL :: URL
,itemDocs :: String
,itemPriority :: Int
}
deriving Show
data Fact
= FactAlias TypeSig TypeSig
| FactInstance TypeSig
| FactDataKind String Int
| FactClassKind String Int
| FactCtorType String String
deriving Show
data Entry = Entry
{entryLocations :: [(URL, [Link Entry])]
,entryName :: String
,entryText :: TagStr
,entryDocs :: Documentation
,entryPriority :: Int
,entryKey :: String
,entryType :: Maybe TypeSig
}
deriving (Typeable)
entryURL e = head $ map fst (entryLocations e) ++ [""]
data EntryView = FocusOn String
| ArgPosNum Int Int
deriving Show
renderEntryText :: [EntryView] -> TagStr -> TagStr
renderEntryText view = transform f
where
cols = [(b+1,a+1) | ArgPosNum a b <- view]
strs = [map toLower x | FocusOn x <- view]
f (TagColor i x) = maybe x (`TagColor` x) $ lookup i $ [(0,0)|cols/=[]] ++ cols
f (TagBold (Str xs)) = TagBold $ Tags $ g xs
f x = x
g xs | ss /= [] = TagEmph (Str a) : g b
where ss = filter (`isPrefixOf` map toLower xs) strs
(a,b) = splitAt (maximum $ map length ss) xs
g (x:xs) = Str [x] : g xs
g [] = []
data EntryScore = EntryScore Int String String
deriving (Eq,Ord)
entryScore :: Entry -> EntryScore
entryScore e = EntryScore (entryPriority e) (map toLower $ entryName e) (entryName e)
instance Show Entry where
show = showTagText . entryText
instance BinaryDefer Entry where
put (Entry a b c d e f g) = put7 a b c d e f g
get = get7 Entry