1
+ {-# LANGUAGE CPP #-}
1
2
-- Mostly taken from "haskell-ide-engine"
2
3
module Development.IDE.Core.Completions (
3
4
CachedCompletions
@@ -32,22 +33,26 @@ import Language.Haskell.LSP.Types.Capabilities
32
33
import qualified Language.Haskell.LSP.VFS as VFS
33
34
import Development.IDE.Core.CompletionsTypes
34
35
import Development.IDE.Spans.Documentation
35
- import Development.IDE.GHC.Util
36
36
import Development.IDE.GHC.Error
37
37
import Development.IDE.Types.Options
38
38
39
- -- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs
39
+ #ifndef GHC_LIB
40
+ import Development.IDE.GHC.Util
40
41
41
- safeTyThingId :: TyThing -> Maybe Id
42
- safeTyThingId (AnId i) = Just i
43
- safeTyThingId (AConLike (RealDataCon dc)) = Just $ dataConWrapId dc
44
- safeTyThingId _ = Nothing
45
42
46
43
safeTyThingType :: TyThing -> Maybe Type
47
44
safeTyThingType thing
48
45
| Just i <- safeTyThingId thing = Just (varType i)
49
46
safeTyThingType (ATyCon tycon) = Just (tyConKind tycon)
50
47
safeTyThingType _ = 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
51
56
52
57
-- From haskell-ide-engine/hie-plugin-api/Haskell/Ide/Engine/Context.hs
53
58
@@ -276,9 +281,15 @@ cacheDataProducer packageState dflags tm tcs = do
276
281
toCompItem :: ModuleName -> Name -> IO CompItem
277
282
toCompItem mn n = do
278
283
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
279
289
ty <- runGhcEnv packageState $ catchSrcErrors " completion" $ do
280
290
name' <- lookupName n
281
291
return $ name' >>= safeTyThingType
292
+ #endif
282
293
return $ CI n (showModName mn) (either (const Nothing ) id ty) (T. pack $ showGhc n) Nothing docs
283
294
284
295
(unquals,quals) <- getCompls rdrElts
@@ -515,4 +526,4 @@ prefixes =
515
526
, " $t"
516
527
, " $c"
517
528
, " $m"
518
- ]
529
+ ]
0 commit comments