From a52894f480dfc253b32ef232f0024e4d9090eaf0 Mon Sep 17 00:00:00 2001 From: Alex Naspo Date: Mon, 13 Sep 2021 07:59:42 -0400 Subject: [PATCH] enable completions of local imports --- .../src/Development/IDE/Plugin/Completions/Logic.hs | 11 +++-------- .../src/Development/IDE/Plugin/Completions/Types.hs | 7 +++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index c3f1de1a4a..d27815b981 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -2,7 +2,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiWayIf #-} - -- Mostly taken from "haskell-ide-engine" module Development.IDE.Plugin.Completions.Logic ( CachedCompletions @@ -66,6 +65,7 @@ import qualified Language.LSP.VFS as VFS import Outputable (Outputable) import TyCoRep + -- From haskell-ide-engine/hie-plugin-api/Haskell/Ide/Engine/Context.hs -- | A context of a declaration in the program @@ -403,15 +403,12 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do (unquals,quals) <- getCompls rdrElts - -- The list of all importable Modules from all packages - moduleNames <- maybe [] (map showModName) <$> envVisibleModuleNames env return $ CC { allModNamesAsNS = allModNamesAsNS , unqualCompls = unquals , qualCompls = quals , anyQualCompls = [] - , importableModules = moduleNames } -- | Produces completions from the top level declarations of a module. @@ -421,7 +418,6 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod , unqualCompls = compls , qualCompls = mempty , anyQualCompls = [] - , importableModules = mempty } where typeSigIds = Set.fromList @@ -535,7 +531,7 @@ getCompletions -> CompletionsConfig -> HM.HashMap T.Text (HashSet.HashSet IdentInfo) -> IO [CompletionItem] -getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qualCompls, importableModules} +getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qualCompls} maybe_parsed (localBindings, bmapping) prefixInfo caps config moduleExportsMap = do let VFS.PosPrefixInfo { fullLine, prefixModule, prefixText } = prefixInfo enteredQual = if T.null prefixModule then "" else prefixModule <> "." @@ -604,12 +600,11 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu , enteredQual `T.isPrefixOf` label ] - filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules + filtImportCompls = filtListWith (mkImportCompl enteredQual) $ map fst $ HM.toList moduleExportsMap filterModuleExports moduleName = filtListWith $ mkModuleFunctionImport moduleName filtKeywordCompls | T.null prefixModule = filtListWith mkExtCompl (optKeywords ideOpts) | otherwise = [] - if -- TODO: handle multiline imports | "import " `T.isPrefixOf` fullLine diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Types.hs b/ghcide/src/Development/IDE/Plugin/Completions/Types.hs index b8660887b6..998355664c 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Types.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Types.hs @@ -95,7 +95,6 @@ data CachedCompletions = CC , qualCompls :: QualCompls -- ^ Completion items associated to -- to a specific module name. , anyQualCompls :: [Maybe T.Text -> CompItem] -- ^ Items associated to any qualifier - , importableModules :: [T.Text] -- ^ All modules that may be imported. } instance Show CachedCompletions where show _ = "" @@ -104,8 +103,8 @@ instance NFData CachedCompletions where rnf = rwhnf instance Monoid CachedCompletions where - mempty = CC mempty mempty mempty mempty mempty + mempty = CC mempty mempty mempty mempty instance Semigroup CachedCompletions where - CC a b c d e <> CC a' b' c' d' e' = - CC (a<>a') (b<>b') (c<>c') (d<>d') (e<>e') + CC a b c d <> CC a' b' c' d' = + CC (a<>a') (b<>b') (c<>c') (d<>d')