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

Commit 25cb238

Browse files
committed
Use correct datatype
1 parent 3835a09 commit 25cb238

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/Haskell/Ide/Engine/Plugin/Hoogle.hs

+13-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,19 @@ renderTarget t = T.intercalate "\n" $
152152
-- If an error occurs, such as no hoogle database has been found,
153153
-- or the search term has no match, an empty list will be returned.
154154
searchModules :: T.Text -> IdeM [T.Text]
155-
searchModules = fmap (nub . take 5) . searchTargets (fmap (T.pack . fst) . targetModule)
155+
searchModules = fmap (map fst) . searchModules'
156+
157+
-- | Just like 'searchModules', but includes the signature of the search term
158+
-- that has been found in the module.
159+
searchModules' :: T.Text -> IdeM [(T.Text, T.Text)]
160+
searchModules' = fmap (nub . take 5)
161+
. searchTargets
162+
(\target
163+
-> (\modTarget -> (T.pack $ fst modTarget, normaliseItem . T.pack $ targetItem target))
164+
<$> targetModule target)
165+
where
166+
normaliseItem :: T.Text -> T.Text
167+
normaliseItem = innerText . parseTags
156168

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

src/Haskell/Ide/Engine/Plugin/HsImport.hs

+10-10
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ codeActionProvider plId docId _ context = do
283283
:: SearchStyle -> [ImportDiagnostic] -> IdeM [J.CodeAction]
284284
importActionsForTerms style importDiagnostics = do
285285
let searchTerms = map (applySearchStyle style . term) importDiagnostics
286-
searchResults <- mapM Hoogle.searchModules searchTerms
286+
searchResults <- mapM Hoogle.searchModules' searchTerms
287287
let importTerms = zip searchResults importDiagnostics
288288
concat <$> mapM (uncurry (termToActions style)) importTerms
289289

@@ -311,9 +311,9 @@ codeActionProvider plId docId _ context = do
311311
-- no import list can be offered, since the function name
312312
-- may be not the one we expect.
313313
termToActions
314-
:: SearchStyle -> [ModuleName] -> ImportDiagnostic -> IdeM [J.CodeAction]
314+
:: SearchStyle -> [(ModuleName, SymbolName)] -> ImportDiagnostic -> IdeM [J.CodeAction]
315315
termToActions style modules impDiagnostic =
316-
concat <$> mapM (importModuleAction style impDiagnostic) modules
316+
concat <$> mapM (uncurry (importModuleAction style impDiagnostic)) modules
317317

318318
-- | Creates various import actions for a module and the diagnostic.
319319
-- Possible import actions depend on the type of the symbol to import.
@@ -322,8 +322,8 @@ codeActionProvider plId docId _ context = do
322322
-- Thus, it may return zero, one or multiple import actions for a module.
323323
-- List of import actions does contain no duplicates.
324324
importModuleAction
325-
:: SearchStyle -> ImportDiagnostic -> ModuleName -> IdeM [J.CodeAction]
326-
importModuleAction searchStyle impDiagnostic moduleName =
325+
:: SearchStyle -> ImportDiagnostic -> ModuleName -> SymbolName -> IdeM [J.CodeAction]
326+
importModuleAction searchStyle impDiagnostic moduleName symbolTerm =
327327
catMaybes <$> sequenceA codeActions
328328
where
329329
importListActions :: [IdeM (Maybe J.CodeAction)]
@@ -339,23 +339,23 @@ codeActionProvider plId docId _ context = do
339339
-- import only this function
340340
Symbol
341341
-> [ mkImportAction moduleName impDiagnostic . Just . Only
342-
<$> symName (term impDiagnostic)
342+
<$> symName symbolTerm
343343
]
344344
-- Constructors can be imported in two ways, either all
345345
-- constructors of a type or only a subset.
346346
-- We can only import a single constructor at a time though.
347347
Constructor
348348
-> [ mkImportAction moduleName impDiagnostic . Just . AllOf
349-
<$> datatypeName (term impDiagnostic)
349+
<$> datatypeName symbolTerm
350350
, (\dt sym -> mkImportAction moduleName impDiagnostic . Just
351351
$ OneOf dt sym)
352-
<$> datatypeName (term impDiagnostic)
353-
<*> symName (term impDiagnostic)
352+
<$> datatypeName symbolTerm
353+
<*> symName symbolTerm
354354
]
355355
-- If we are looking for a type, import it as just a symbol
356356
Type
357357
-> [ mkImportAction moduleName impDiagnostic . Just . Only
358-
<$> symName (term impDiagnostic)]
358+
<$> symName symbolTerm]
359359

360360
-- | All code actions that may be available
361361
-- Currently, omits all

0 commit comments

Comments
 (0)