1
1
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2
2
-- SPDX-License-Identifier: Apache-2.0
3
3
4
- {-# LANGUAGE CPP #-}
5
- {-# LANGUAGE ConstraintKinds #-}
4
+ {-# LANGUAGE CPP #-}
5
+ {-# LANGUAGE ConstraintKinds #-}
6
6
{-# LANGUAGE FlexibleInstances #-}
7
- {-# LANGUAGE PatternSynonyms #-}
7
+ {-# LANGUAGE PatternSynonyms #-}
8
8
{-# OPTIONS -Wno-dodgy-imports -Wno-incomplete-uni-patterns #-}
9
9
{-# OPTIONS -Wno-missing-signatures #-} -- TODO: Remove!
10
10
#include "ghc-api-version.h"
@@ -70,6 +70,8 @@ module Development.IDE.GHC.Compat(
70
70
Scaled ,
71
71
scaledThing ,
72
72
73
+ lookupUnit' ,
74
+ preloadClosureUs ,
73
75
-- Reexports from Package
74
76
InstalledUnitId ,
75
77
PackageConfig ,
@@ -82,7 +84,7 @@ module Development.IDE.GHC.Compat(
82
84
packageVersion ,
83
85
toInstalledUnitId ,
84
86
lookupPackage ,
85
- lookupPackage' ,
87
+ -- lookupPackage',
86
88
explicitPackages ,
87
89
exposedModules ,
88
90
packageConfigId ,
@@ -122,71 +124,67 @@ module Development.IDE.GHC.Compat(
122
124
,isQualifiedImport ) where
123
125
124
126
#if MIN_GHC_API_VERSION(8,10,0)
125
- import LinkerTypes
127
+ import LinkerTypes
126
128
#endif
127
129
128
- import StringBuffer
130
+ import DynFlags hiding ( ExposePackage )
129
131
import qualified DynFlags
130
- import DynFlags hiding (ExposePackage )
131
- import Fingerprint (Fingerprint )
132
- import qualified Outputable as Out
133
- import qualified ErrUtils as Err
132
+ import qualified ErrUtils as Err
133
+ import Fingerprint (Fingerprint )
134
134
import qualified Module
135
+ import qualified Outputable as Out
136
+ import StringBuffer
135
137
#if MIN_GHC_API_VERSION(9,0,1)
136
- import qualified SrcLoc
137
- import qualified Data.Set as S
138
+ import qualified Data.Set as S
139
+ import GHC.Core.TyCo.Rep ( Scaled , scaledThing )
138
140
import GHC.Iface.Load
139
- import GHC.Core.TyCo.Rep (Scaled , scaledThing )
140
141
import GHC.Types.Unique.Set (emptyUniqSet )
142
+ import qualified SrcLoc
141
143
#else
142
- import Module (InstalledUnitId ,toInstalledUnitId )
144
+ import Module (InstalledUnitId , toInstalledUnitId )
143
145
#endif
144
- import Packages
145
- import Data.IORef
146
- import HscTypes
147
- import NameCache
148
- import qualified Data.ByteString as BS
149
- import MkIface
150
- import TcRnTypes
151
- import Compat.HieAst ( mkHieFile , enrichHie )
152
- import Compat.HieBin
153
- import Compat.HieTypes
154
- import Compat.HieUtils
146
+ import Compat.HieAst ( enrichHie , mkHieFile )
147
+ import Compat.HieBin
148
+ import Compat.HieTypes
149
+ import Compat.HieUtils
150
+ import qualified Data.ByteString as BS
151
+ import Data.IORef
152
+ import HscTypes
153
+ import MkIface
154
+ import NameCache
155
+ import Packages
156
+ import TcRnTypes
155
157
156
158
#if MIN_GHC_API_VERSION(8,10,0)
157
- import GHC.Hs.Extension
159
+ import GHC.Hs.Extension
158
160
#else
159
- import HsExtension
161
+ import HsExtension
160
162
#endif
161
163
164
+ import Avail
165
+ import GHC hiding (HasSrcSpan , ModLocation , getLoc ,
166
+ lookupName )
162
167
import qualified GHC
163
168
import qualified TyCoRep
164
- import GHC hiding (
165
- ModLocation ,
166
- HasSrcSpan ,
167
- lookupName ,
168
- getLoc
169
- )
170
- import Avail
171
169
#if MIN_GHC_API_VERSION(8,8,0)
172
- import Data.List (foldl' )
170
+ import Data.List (foldl' )
173
171
#else
174
- import Data.List (foldl' , isSuffixOf )
172
+ import Data.List (foldl' , isSuffixOf )
175
173
#endif
176
174
177
- import DynamicLoading
178
- import Plugins ( Plugin ( parsedResultAction ), withPlugins )
179
- import qualified Data.Map as M
175
+ import qualified Data.Map as M
176
+ import DynamicLoading
177
+ import Plugins ( Plugin ( parsedResultAction ), withPlugins )
180
178
181
179
#if !MIN_GHC_API_VERSION(8,8,0)
182
- import System.FilePath ((-<.>) )
180
+ import System.FilePath ((-<.>) )
183
181
#endif
184
182
185
183
#if !MIN_GHC_API_VERSION(8,8,0)
186
184
import qualified EnumSet
187
185
188
- import System.IO
189
- import Foreign.ForeignPtr
186
+ import Foreign.ForeignPtr
187
+ import System.IO
190
188
191
189
192
190
hPutStringBuffer :: Handle -> StringBuffer -> IO ()
@@ -250,10 +248,11 @@ addIncludePathsQuote path x = x{includePaths = f $ includePaths x}
250
248
where f i = i{includePathsQuote = path : includePathsQuote i}
251
249
252
250
pattern ModLocation :: Maybe FilePath -> FilePath -> FilePath -> GHC. ModLocation
253
- pattern ModLocation a b c <-
254
251
#if MIN_GHC_API_VERSION(8,8,0)
252
+ pattern ModLocation a b c <-
255
253
GHC. ModLocation a b c _ where ModLocation a b c = GHC. ModLocation a b c " "
256
254
#else
255
+ pattern ModLocation a b c <-
257
256
GHC. ModLocation a b c where ModLocation a b c = GHC. ModLocation a b c
258
257
#endif
259
258
@@ -356,9 +355,11 @@ packageName = Packages.unitPackageName
356
355
lookupPackage = Packages. lookupUnit . unitState
357
356
-- lookupPackage' = undefined
358
357
-- lookupPackage' b pm u = Packages.lookupUnit' b pm undefined u
359
- lookupPackage' b pm u = Packages. lookupUnit' b pm emptyUniqSet u -- TODO: Is this correct?
358
+ -- lookupPackage' b pm u = Packages.lookupUnit' b pm emptyUniqSet u -- TODO: Is this correct?
360
359
-- lookupPackage' = fmap Packages.lookupUnit' . unitState
361
360
getPackageConfigMap = Packages. unitInfoMap . unitState
361
+ preloadClosureUs = Packages. preloadClosure . unitState
362
+ -- getPackageConfigMap = unitState
362
363
-- getPackageIncludePath = undefined
363
364
getPackageIncludePath = Packages. getUnitIncludePath
364
365
explicitPackages = Packages. explicitUnits
@@ -394,23 +395,35 @@ oldLookupModuleWithSuggestions = Packages.lookupModuleWithSuggestions . unitStat
394
395
oldRenderWithStyle dflags sdoc sty = Out. renderWithStyle (initSDocContext dflags sty) sdoc
395
396
oldMkUserStyle _ = Out. mkUserStyle
396
397
oldMkErrStyle _ = Out. mkErrStyle
398
+
399
+ -- TODO: This is still a mess!
397
400
oldFormatErrDoc :: DynFlags -> Err. ErrDoc -> Out. SDoc
398
- oldFormatErrDoc = Err. formatErrDoc . undefined
401
+ oldFormatErrDoc dflags = Err. formatErrDoc dummySDocContext
402
+ where dummySDocContext = initSDocContext dflags Out. defaultUserStyle
399
403
-- oldFormatErrDoc = Err.formatErrDoc . undefined
400
404
writeIfaceFile = writeIface
401
405
402
406
#else
403
407
type Unit = Module. UnitId
404
408
-- type PackageConfig = Packages.PackageConfig
409
+ definiteUnitId :: Module. DefUnitId -> UnitId
405
410
definiteUnitId = Module. DefiniteUnitId
411
+ defUnitId :: InstalledUnitId -> Module. DefUnitId
406
412
defUnitId = Module. DefUnitId
413
+ installedModule :: InstalledUnitId -> ModuleName -> Module. InstalledModule
407
414
installedModule = Module. InstalledModule
415
+ oldLookupInstalledPackage :: DynFlags -> InstalledUnitId -> Maybe PackageConfig
408
416
oldLookupInstalledPackage = Packages. lookupInstalledPackage
409
417
-- packageName = Packages.packageName
410
418
-- lookupPackage = Packages.lookupPackage
411
419
-- getPackageConfigMap = Packages.getPackageConfigMap
420
+ setThisInstalledUnitId :: InstalledUnitId -> DynFlags -> DynFlags
412
421
setThisInstalledUnitId uid df = df { thisInstalledUnitId = uid}
413
422
423
+ lookupUnit' :: Bool -> PackageConfigMap -> p -> UnitId -> Maybe PackageConfig
424
+ lookupUnit' b pcm _ = Packages. lookupPackage' b pcm
425
+ preloadClosureUs = const ()
426
+
414
427
oldUnhelpfulSpan = UnhelpfulSpan
415
428
pattern OldRealSrcSpan :: RealSrcSpan -> SrcSpan
416
429
pattern OldRealSrcSpan x = RealSrcSpan x
@@ -486,15 +499,15 @@ pattern FunTy arg res <- TyCoRep.FunTy arg res
486
499
isQualifiedImport :: ImportDecl a -> Bool
487
500
#if MIN_GHC_API_VERSION(8,10,0)
488
501
isQualifiedImport ImportDecl {ideclQualified = NotQualified } = False
489
- isQualifiedImport ImportDecl {} = True
502
+ isQualifiedImport ImportDecl {} = True
490
503
#else
491
- isQualifiedImport ImportDecl {ideclQualified} = ideclQualified
504
+ isQualifiedImport ImportDecl {ideclQualified} = ideclQualified
492
505
#endif
493
- isQualifiedImport _ = False
506
+ isQualifiedImport _ = False
494
507
495
508
getRealSpan :: SrcSpan -> Maybe RealSrcSpan
496
509
getRealSpan (OldRealSrcSpan x) = Just x
497
- getRealSpan _ = Nothing
510
+ getRealSpan _ = Nothing
498
511
499
512
500
513
0 commit comments