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

Improve import action of hsimport #1284

Merged
merged 12 commits into from
Jun 13, 2019
18 changes: 15 additions & 3 deletions src/Haskell/Ide/Engine/Plugin/Hoogle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ hoogleDescriptor plId = PluginDescriptor

-- ---------------------------------------------------------------------

data HoogleError
data HoogleError
= NoDb
| DbFail T.Text
| NoResults
| NoResults
deriving (Eq,Ord,Show)

newtype HoogleDb = HoogleDb (Maybe FilePath)
Expand Down Expand Up @@ -152,7 +152,19 @@ renderTarget t = T.intercalate "\n" $
-- If an error occurs, such as no hoogle database has been found,
-- or the search term has no match, an empty list will be returned.
searchModules :: T.Text -> IdeM [T.Text]
searchModules = fmap (nub . take 5) . searchTargets (fmap (T.pack . fst) . targetModule)
searchModules = fmap (map fst) . searchModules'

-- | Just like 'searchModules', but includes the signature of the search term
-- that has been found in the module.
searchModules' :: T.Text -> IdeM [(T.Text, T.Text)]
searchModules' = fmap (nub . take 5)
fendor marked this conversation as resolved.
Show resolved Hide resolved
. searchTargets
(\target
-> (\modTarget -> (T.pack $ fst modTarget, normaliseItem . T.pack $ targetItem target))
fendor marked this conversation as resolved.
Show resolved Hide resolved
<$> targetModule target)
where
normaliseItem :: T.Text -> T.Text
normaliseItem = innerText . parseTags

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