@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- Mostly taken from "haskell-ide-engine"
23module Development.IDE.Core.Completions (
34 CachedCompletions
@@ -32,22 +33,26 @@ import Language.Haskell.LSP.Types.Capabilities
3233import qualified Language.Haskell.LSP.VFS as VFS
3334import Development.IDE.Core.CompletionsTypes
3435import Development.IDE.Spans.Documentation
35−import Development.IDE.GHC.Util
3636import Development.IDE.GHC.Error
3737import Development.IDE.Types.Options
3838
39−-- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs
39+#ifndef GHC_LIB
40+import Development.IDE.GHC.Util
4041
41−safeTyThingId :: TyThing -> Maybe Id
42−safeTyThingId (AnId i) = Just i
43−safeTyThingId (AConLike (RealDataCon dc)) = Just $ dataConWrapId dc
44−safeTyThingId _ = Nothing
4542
4643safeTyThingType :: TyThing -> Maybe Type
4744safeTyThingType thing
4845 | Just i <- safeTyThingId thing = Just (varType i)
4946safeTyThingType (ATyCon tycon) = Just (tyConKind tycon)
5047safeTyThingType _ = Nothing
48+#endif
49+
50+-- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs
51+
52+safeTyThingId :: TyThing -> Maybe Id
53+safeTyThingId (AnId i) = Just i
54+safeTyThingId (AConLike (RealDataCon dc)) = Just $ dataConWrapId dc
55+safeTyThingId _ = Nothing
5156
5257-- From haskell-ide-engine/hie-plugin-api/Haskell/Ide/Engine/Context.hs
5358
@@ -276,9 +281,15 @@ cacheDataProducer packageState dflags tm tcs = do
276281 toCompItem :: ModuleName -> Name -> IO CompItem
277282 toCompItem mn n = do
278283 docs <- getDocumentationTryGhc packageState (tm:tcs) n
284+-- lookupName uses runInteractiveHsc, i.e., GHCi stuff which does not work with GHCi
285+-- and leads to fun errors like "Cannot continue after interface file error".
286+#ifdef GHC_LIB
287+ let ty = Right Nothing
288+#else
279289 ty <- runGhcEnv packageState $ catchSrcErrors "completion" $ do
280290 name' <- lookupName n
281291 return $ name' >>= safeTyThingType
292+#endif
282293 return $ CI n (showModName mn) (either (const Nothing) id ty) (T.pack $ showGhc n) Nothing docs
283294
284295 (unquals,quals) <- getCompls rdrElts
@@ -515,4 +526,4 @@ prefixes =
515526 , "$t"
516527 , "$c"
517528 , "$m"
518− ]
529+ ]