Skip to content

Commit a52894f

Browse files
committed
enable completions of local imports
1 parent 8d7e8f1 commit a52894f

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE GADTs #-}
33
{-# LANGUAGE MultiWayIf #-}
44

5-
65
-- Mostly taken from "haskell-ide-engine"
76
module Development.IDE.Plugin.Completions.Logic (
87
CachedCompletions
@@ -66,6 +65,7 @@ import qualified Language.LSP.VFS as VFS
6665
import Outputable (Outputable)
6766
import TyCoRep
6867

68+
6969
-- From haskell-ide-engine/hie-plugin-api/Haskell/Ide/Engine/Context.hs
7070

7171
-- | A context of a declaration in the program
@@ -403,15 +403,12 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do
403403

404404
(unquals,quals) <- getCompls rdrElts
405405

406-
-- The list of all importable Modules from all packages
407-
moduleNames <- maybe [] (map showModName) <$> envVisibleModuleNames env
408406

409407
return $ CC
410408
{ allModNamesAsNS = allModNamesAsNS
411409
, unqualCompls = unquals
412410
, qualCompls = quals
413411
, anyQualCompls = []
414-
, importableModules = moduleNames
415412
}
416413

417414
-- | Produces completions from the top level declarations of a module.
@@ -421,7 +418,6 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
421418
, unqualCompls = compls
422419
, qualCompls = mempty
423420
, anyQualCompls = []
424-
, importableModules = mempty
425421
}
426422
where
427423
typeSigIds = Set.fromList
@@ -535,7 +531,7 @@ getCompletions
535531
-> CompletionsConfig
536532
-> HM.HashMap T.Text (HashSet.HashSet IdentInfo)
537533
-> IO [CompletionItem]
538-
getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qualCompls, importableModules}
534+
getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qualCompls}
539535
maybe_parsed (localBindings, bmapping) prefixInfo caps config moduleExportsMap = do
540536
let VFS.PosPrefixInfo { fullLine, prefixModule, prefixText } = prefixInfo
541537
enteredQual = if T.null prefixModule then "" else prefixModule <> "."
@@ -604,12 +600,11 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
604600
, enteredQual `T.isPrefixOf` label
605601
]
606602

607-
filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
603+
filtImportCompls = filtListWith (mkImportCompl enteredQual) $ map fst $ HM.toList moduleExportsMap
608604
filterModuleExports moduleName = filtListWith $ mkModuleFunctionImport moduleName
609605
filtKeywordCompls
610606
| T.null prefixModule = filtListWith mkExtCompl (optKeywords ideOpts)
611607
| otherwise = []
612-
613608
if
614609
-- TODO: handle multiline imports
615610
| "import " `T.isPrefixOf` fullLine

ghcide/src/Development/IDE/Plugin/Completions/Types.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ data CachedCompletions = CC
9595
, qualCompls :: QualCompls -- ^ Completion items associated to
9696
-- to a specific module name.
9797
, anyQualCompls :: [Maybe T.Text -> CompItem] -- ^ Items associated to any qualifier
98-
, importableModules :: [T.Text] -- ^ All modules that may be imported.
9998
}
10099

101100
instance Show CachedCompletions where show _ = "<cached completions>"
@@ -104,8 +103,8 @@ instance NFData CachedCompletions where
104103
rnf = rwhnf
105104

106105
instance Monoid CachedCompletions where
107-
mempty = CC mempty mempty mempty mempty mempty
106+
mempty = CC mempty mempty mempty mempty
108107

109108
instance Semigroup CachedCompletions where
110-
CC a b c d e <> CC a' b' c' d' e' =
111-
CC (a<>a') (b<>b') (c<>c') (d<>d') (e<>e')
109+
CC a b c d <> CC a' b' c' d' =
110+
CC (a<>a') (b<>b') (c<>c') (d<>d')

0 commit comments

Comments
 (0)