Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Reuse unHTML for searchModules' #1323

Merged
merged 1 commit into from
Jul 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/Haskell/Ide/Engine/Plugin/Hoogle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ renderTarget t = T.intercalate "\n" $
annotate :: (String, String) -> String
annotate (thing,url) = "["<>thing<>"]"<>"("<>url<>")"

-- | Hoogle results contain html like tags.
-- We remove them with `tagsoup` here.
-- So, if something hoogle related shows html tags,
-- then maybe this function is responsible.
unHTML :: T.Text -> T.Text
unHTML = T.replace "<0>" "" . innerText . parseTags

Expand Down Expand Up @@ -172,21 +176,14 @@ searchModules = fmap (map fst) . searchModules'
searchModules' :: T.Text -> IdeM [(T.Text, T.Text)]
searchModules' = fmap (take 5 . nub) . searchTargets retrieveModuleAndSignature
where
-- | Hoogle results contain html like tags.
-- We remove them with `tagsoup` here.
-- So, if something hoogle related shows html tags,
-- then maybe this function is responsible.
normaliseItem :: T.Text -> T.Text
normaliseItem = innerText . parseTags

retrieveModuleAndSignature :: Target -> Maybe (T.Text, T.Text)
retrieveModuleAndSignature target = liftA2 (,) (packModuleName target) (packSymbolSignature target)

packModuleName :: Target -> Maybe T.Text
packModuleName = fmap (T.pack . fst) . targetModule

packSymbolSignature :: Target -> Maybe T.Text
packSymbolSignature = Just . normaliseItem . T.pack . targetItem
packSymbolSignature = Just . unHTML . T.pack . targetItem

-- | Search for packages that satisfy the given search text.
-- Will return at most five, unique results.
Expand Down