Skip to content

Commit e180a62

Browse files
authored
Avoid lookupName on ghc-lib (#327)
This fixes an issue that we encountered in DAML. I’ll add a test for this in the DAML repo since we cannot test the ghc-lib codepath here (since we don’t setup an environment that works).
1 parent 789f403 commit e180a62

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

.hlint.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
- {name: ImplicitParams, within: []}
7777
- name: CPP
7878
within:
79+
- Development.IDE.Core.Completions
7980
- Development.IDE.Core.FileStore
8081
- Development.IDE.Core.Compile
8182
- Development.IDE.GHC.Compat

src/Development/IDE/Core/Completions.hs

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
-- Mostly taken from "haskell-ide-engine"
23
module Development.IDE.Core.Completions (
34
CachedCompletions
@@ -32,22 +33,26 @@ import Language.Haskell.LSP.Types.Capabilities
3233
import qualified Language.Haskell.LSP.VFS as VFS
3334
import Development.IDE.Core.CompletionsTypes
3435
import Development.IDE.Spans.Documentation
35-
import Development.IDE.GHC.Util
3636
import Development.IDE.GHC.Error
3737
import 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

4643
safeTyThingType :: TyThing -> Maybe Type
4744
safeTyThingType thing
4845
| Just i <- safeTyThingId thing = Just (varType i)
4946
safeTyThingType (ATyCon tycon) = Just (tyConKind tycon)
5047
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
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+
]

0 commit comments

Comments
 (0)