Skip to content

Catch GHC errors in listing module names #1367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Plugin/Completions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Ide.PluginUtils (getClientConfig)
import Ide.Types
import TcRnDriver (tcRnImportDecls)
import Control.Concurrent.Async (concurrently)
import Data.Bifunctor (second)
#if defined(GHC_LIB)
import Development.IDE.Import.DependencyInformation
#endif
Expand Down Expand Up @@ -81,8 +82,7 @@ produceCompletions = do
case (global, inScope) of
((_, Just globalEnv), (_, Just inScopeEnv)) -> do
let uri = fromNormalizedUri $ normalizedFilePathToUri file
cdata <- liftIO $ cacheDataProducer uri env (ms_mod ms) globalEnv inScopeEnv imps parsedDeps
return ([], Just cdata)
second Just <$> liftIO (cacheDataProducer uri env (ms_mod ms) globalEnv inScopeEnv imps parsedDeps)
(_diag, _) ->
return ([], Nothing)
_ -> return ([], Nothing)
Expand Down
22 changes: 16 additions & 6 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ import Data.Functor
import Ide.PluginUtils (mkLspCommand)
import Ide.Types (CommandId (..), PluginId, WithSnippets (..))
import Control.Monad
import Control.Exception (evaluate)
import Control.DeepSeq (force)
import Development.IDE.Types.Diagnostics (FileDiagnostic)

-- From haskell-ide-engine/hie-plugin-api/Haskell/Ide/Engine/Context.hs

Expand Down Expand Up @@ -294,7 +297,7 @@ mkPragmaCompl label insertText =
Nothing Nothing Nothing Nothing Nothing


cacheDataProducer :: Uri -> HscEnv -> Module -> GlobalRdrEnv-> GlobalRdrEnv -> [LImportDecl GhcPs] -> [ParsedModule] -> IO CachedCompletions
cacheDataProducer :: Uri -> HscEnv -> Module -> GlobalRdrEnv-> GlobalRdrEnv -> [LImportDecl GhcPs] -> [ParsedModule] -> IO ([FileDiagnostic], CachedCompletions)
cacheDataProducer uri packageState curMod globalEnv inScopeEnv limports deps = do
let dflags = hsc_dflags packageState
curModName = moduleName curMod
Expand All @@ -309,9 +312,6 @@ cacheDataProducer uri packageState curMod globalEnv inScopeEnv limports deps = d
-- Full canonical names of imported modules
importDeclerations = map unLoc limports

-- The list of all importable Modules from all packages
moduleNames = map showModName (listVisibleModuleNames dflags)

-- The given namespaces for the imported modules (ie. full name, or alias if used)
allModNamesAsNS = map (showModName . asNamespace) importDeclerations

Expand Down Expand Up @@ -364,14 +364,24 @@ cacheDataProducer uri packageState curMod globalEnv inScopeEnv limports deps = d
return $ mkNameCompItem uri mbParent originName mn ty Nothing docs imp'
: recordCompls

-- The list of all importable Modules from all packages
(lvmnDiags, moduleNames) <-
catchSrcErrors
dflags
"listVisibleModuleNames"
(evaluate . force $ map showModName (listVisibleModuleNames dflags))
<&> \case
Left diags -> (diags, [])
Right x -> ([], x)

(unquals,quals) <- getCompls rdrElts

return $ CC
return (lvmnDiags, CC
{ allModNamesAsNS = allModNamesAsNS
, unqualCompls = unquals
, qualCompls = quals
, importableModules = moduleNames
}
})

-- | Produces completions from the top level declarations of a module.
localCompletionsForParsedModule :: Uri -> ParsedModule -> CachedCompletions
Expand Down