Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 2eded16

Browse files
committed
Update HIE to use latest hie-bios
1 parent 0fd7e3f commit 2eded16

21 files changed

+147
-104
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
# rm -rf path_to_submodule
1111

1212

13+
[submodule "hie-bios"]
14+
path = hie-bios
15+
url = https://github.com/mpickering/hie-bios.git

app/MainHie.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import qualified Data.Text as T
1313
import qualified Data.Text.IO as T
1414
import qualified Data.Yaml as Yaml
1515
import HIE.Bios.Types
16-
import Haskell.Ide.Engine.Cradle (findLocalCradle, cradleDisplay, getProjectGhcLibDir)
16+
import Haskell.Ide.Engine.Cradle (findLocalCradle, cradleDisplay
17+
, getProjectGhcLibDir, CabalHelper)
1718
import Haskell.Ide.Engine.MonadFunctions
1819
import Haskell.Ide.Engine.MonadTypes
1920
import Haskell.Ide.Engine.Options
@@ -198,7 +199,7 @@ run opts = do
198199

199200
-- ---------------------------------------------------------------------
200201

201-
getCradleInfo :: FilePath -> IO (Either Yaml.ParseException Cradle)
202+
getCradleInfo :: FilePath -> IO (Either Yaml.ParseException (Cradle CabalHelper))
202203
getCradleInfo currentDir = do
203204
let dummyCradleFile = currentDir </> "File.hs"
204205
cradleRes <- E.try (findLocalCradle dummyCradleFile)

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
packages:
22
./
33
./hie-plugin-api/
4-
4+
./hie-bios/
55
-- ./submodules/HaRe
66

77
tests: true

hie-bios

Submodule hie-bios added at d9f6023

hie-plugin-api/Haskell/Ide/Engine/ArtifactMap.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import qualified GHC
88
import GHC (TypecheckedModule)
99
import qualified SrcLoc as GHC
1010
import qualified Var
11-
import Haskell.Ide.Engine.GhcCompat
11+
import Haskell.Ide.Engine.GhcCompat
1212

1313
import Language.Haskell.LSP.Types
1414

hie-plugin-api/Haskell/Ide/Engine/Cradle.hs

Lines changed: 82 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55

66
module Haskell.Ide.Engine.Cradle where
77

8-
import HIE.Bios as BIOS
9-
import HIE.Bios.Types as BIOS
10-
import Haskell.Ide.Engine.MonadFunctions
8+
import HIE.Bios as Bios
9+
import qualified HIE.Bios.Cradle as Bios
10+
import HIE.Bios.Types (Cradle(..), CradleAction(..))
11+
import qualified HIE.Bios.Types as Bios
1112
import Distribution.Helper (Package, projectPackages, pUnits,
1213
pSourceDir, ChComponentInfo(..),
1314
unChModuleName, Ex(..), ProjLoc(..),
1415
QueryEnv, mkQueryEnv, runQuery,
1516
Unit, unitInfo, uiComponents,
1617
ChEntrypoint(..), UnitInfo(..))
1718
import Distribution.Helper.Discover (findProjects, getDefaultDistDir)
18-
import Data.Char (toLower)
1919
import Data.Function ((&))
20-
import Data.List (isPrefixOf, isInfixOf, sortOn, find)
20+
import Data.List (isPrefixOf, sortOn, find)
2121
import qualified Data.List.NonEmpty as NonEmpty
2222
import Data.List.NonEmpty (NonEmpty)
2323
import qualified Data.Map as Map
@@ -32,6 +32,8 @@ import System.Directory (getCurrentDirectory, canonicalizePath, findEx
3232
import System.Exit
3333
import System.Process (readCreateProcessWithExitCode, shell)
3434

35+
import Haskell.Ide.Engine.Logger
36+
3537
-- | Find the cradle that the given File belongs to.
3638
--
3739
-- First looks for a "hie.yaml" file in the directory of the file
@@ -42,44 +44,67 @@ import System.Process (readCreateProcessWithExitCode, shell)
4244
-- If no "hie.yaml" can be found, the implicit config is used.
4345
-- The implicit config uses different heuristics to determine the type
4446
-- of the project that may or may not be accurate.
45-
findLocalCradle :: FilePath -> IO Cradle
47+
findLocalCradle :: FilePath -> IO (Cradle CabalHelper)
4648
findLocalCradle fp = do
47-
cradleConf <- BIOS.findCradle fp
48-
crdl <- case cradleConf of
49+
cradleConf <- Bios.findCradle fp
50+
crdl <- case cradleConf of
4951
Just yaml -> do
5052
debugm $ "Found \"" ++ yaml ++ "\" for \"" ++ fp ++ "\""
51-
BIOS.loadCradle yaml
52-
Nothing -> cabalHelperCradle fp
53+
crdl <- Bios.loadCradle yaml
54+
return $ relaxCradle crdl
55+
Nothing -> cabalHelperCradle fp
5356
logm $ "Module \"" ++ fp ++ "\" is loaded by Cradle: " ++ show crdl
5457
return crdl
58+
where
59+
relaxCradle :: Cradle a -> Cradle CabalHelper
60+
relaxCradle crdl =
61+
let newActionName = case actionName $ cradleOptsProg crdl of
62+
Bios.Other _ -> Bios.Other CabalNone
63+
Bios.Stack -> Bios.Stack
64+
Bios.Cabal -> Bios.Cabal
65+
Bios.Direct -> Bios.Direct
66+
Bios.None -> Bios.None
67+
Bios.Multi -> Bios.Multi
68+
Bios.Default -> Bios.Default
69+
Bios.Bios -> Bios.Bios
70+
in crdl
71+
{ cradleOptsProg = (cradleOptsProg crdl) { actionName = newActionName
72+
}
73+
}
5574

5675
-- | Check if the given cradle is a stack cradle.
5776
-- This might be used to determine the GHC version to use on the project.
5877
-- If it is a stack-cradle, we have to use @"stack path --compiler-exe"@
5978
-- otherwise we may ask `ghc` directly what version it is.
60-
isStackCradle :: Cradle -> Bool
61-
isStackCradle = (`elem` ["stack", "Cabal-Helper-Stack", "Cabal-Helper-Stack-None"])
62-
. BIOS.actionName
63-
. BIOS.cradleOptsProg
64-
79+
isStackCradle :: Cradle CabalHelper -> Bool
80+
isStackCradle =
81+
( `elem`
82+
[ Bios.Other Stack
83+
, Bios.Other StackNone
84+
]
85+
)
86+
. Bios.actionName
87+
. Bios.cradleOptsProg
6588
-- | Check if the given cradle is a cabal cradle.
6689
-- This might be used to determine the GHC version to use on the project.
6790
-- If it is a stack-cradle, we have to use @"stack path --compiler-exe"@
6891
-- otherwise we may ask @ghc@ directly what version it is.
69-
isCabalCradle :: Cradle -> Bool
92+
isCabalCradle :: Cradle CabalHelper -> Bool
7093
isCabalCradle =
71-
(`elem`
72-
[ "cabal"
73-
, "Cabal-Helper-Cabal-V1"
74-
, "Cabal-Helper-Cabal-V2"
75-
, "Cabal-Helper-Cabal-V1-Dir"
76-
, "Cabal-Helper-Cabal-V2-Dir"
77-
, "Cabal-Helper-Cabal-V2-None"
78-
, "Cabal-Helper-Cabal-None"
79-
]
94+
( `elem`
95+
[ Bios.Other CabalV2
96+
, Bios.Other CabalNone
97+
]
8098
)
81-
. BIOS.actionName
82-
. BIOS.cradleOptsProg
99+
. Bios.actionName
100+
. Bios.cradleOptsProg
101+
102+
data CabalHelper
103+
= Stack
104+
| StackNone
105+
| CabalV2
106+
| CabalNone
107+
deriving (Show, Eq, Ord)
83108

84109
-- | Execute @ghc@ that is based on the given cradle.
85110
-- Output must be a single line. If an error is raised, e.g. the command
@@ -88,7 +113,7 @@ isCabalCradle =
88113
--
89114
-- E.g. for a stack cradle, we use @stack ghc@ and for a cabal cradle
90115
-- we are taking the @ghc@ that is on the path.
91-
execProjectGhc :: Cradle -> [String] -> IO (Maybe String)
116+
execProjectGhc :: Cradle CabalHelper -> [String] -> IO (Maybe String)
92117
execProjectGhc crdl args = do
93118
isStackInstalled <- isJust <$> findExecutable "stack"
94119
-- isCabalInstalled <- isJust <$> findExecutable "cabal"
@@ -144,7 +169,7 @@ tryCommand cmd = do
144169

145170

146171
-- | Get the directory of the libdir based on the project ghc.
147-
getProjectGhcLibDir :: Cradle -> IO (Maybe FilePath)
172+
getProjectGhcLibDir :: Cradle CabalHelper -> IO (Maybe FilePath)
148173
getProjectGhcLibDir crdl =
149174
execProjectGhc crdl ["--print-libdir"] >>= \case
150175
Nothing -> do
@@ -441,7 +466,7 @@ the compiler options obtained from Cabal-Helper are relative to the package
441466
source directory, which is "\/Repo\/SubRepo".
442467
443468
-}
444-
cabalHelperCradle :: FilePath -> IO Cradle
469+
cabalHelperCradle :: FilePath -> IO (Cradle CabalHelper)
445470
cabalHelperCradle file = do
446471
projM <- findCabalHelperEntryPoint file
447472
case projM of
@@ -451,7 +476,7 @@ cabalHelperCradle file = do
451476
return
452477
Cradle { cradleRootDir = cwd
453478
, cradleOptsProg =
454-
CradleAction { actionName = "Direct"
479+
CradleAction { actionName = Bios.Direct
455480
, runCradle = \_ _ ->
456481
return
457482
$ CradleSuccess
@@ -484,9 +509,7 @@ cabalHelperCradle file = do
484509
return
485510
Cradle { cradleRootDir = root
486511
, cradleOptsProg =
487-
CradleAction { actionName = "Cabal-Helper-"
488-
++ actionNameSuffix
489-
++ "-None"
512+
CradleAction { actionName = Bios.None
490513
, runCradle = \_ _ -> return CradleNone
491514
}
492515
}
@@ -501,8 +524,7 @@ cabalHelperCradle file = do
501524
return
502525
Cradle { cradleRootDir = normalisedPackageLocation
503526
, cradleOptsProg =
504-
CradleAction { actionName =
505-
"Cabal-Helper-" ++ actionNameSuffix
527+
CradleAction { actionName = Bios.Other actionNameSuffix
506528
, runCradle = \_ fp -> cabalHelperAction
507529
(Ex proj)
508530
env
@@ -751,12 +773,12 @@ projectRootDir ProjLocV2File { plProjectDirV2 } = plProjectDirV2
751773
projectRootDir ProjLocV2Dir { plProjectDirV2 } = plProjectDirV2
752774
projectRootDir ProjLocStackYaml { plStackYaml } = takeDirectory plStackYaml
753775

754-
projectSuffix :: ProjLoc qt -> FilePath
755-
projectSuffix ProjLocV1CabalFile {} = "Cabal-V1"
756-
projectSuffix ProjLocV1Dir {} = "Cabal-V1-Dir"
757-
projectSuffix ProjLocV2File {} = "Cabal-V2"
758-
projectSuffix ProjLocV2Dir {} = "Cabal-V2-Dir"
759-
projectSuffix ProjLocStackYaml {} = "Stack"
776+
projectSuffix :: ProjLoc qt -> CabalHelper
777+
projectSuffix ProjLocV1CabalFile {} = CabalV2
778+
projectSuffix ProjLocV1Dir {} = CabalV2
779+
projectSuffix ProjLocV2File {} = CabalV2
780+
projectSuffix ProjLocV2Dir {} = CabalV2
781+
projectSuffix ProjLocStackYaml {} = Stack
760782

761783
-- ----------------------------------------------------------------------------
762784
--
@@ -867,14 +889,22 @@ relativeTo file sourceDirs =
867889

868890
-- | Returns a user facing display name for the cradle type,
869891
-- e.g. "Stack project" or "GHC session"
870-
cradleDisplay :: IsString a => BIOS.Cradle -> a
892+
cradleDisplay :: IsString a => Cradle CabalHelper -> a
871893
cradleDisplay cradle = fromString result
872-
where
873-
result
874-
| "stack" `isInfixOf` name = "Stack project"
875-
| "cabal-v1" `isInfixOf` name = "Cabal (V1) project"
876-
| "cabal" `isInfixOf` name = "Cabal project"
877-
| "direct" `isInfixOf` name = "GHC session"
878-
| "multi" `isInfixOf` name = "Multi Component project"
879-
| otherwise = "project"
880-
name = map toLower $ BIOS.actionName (BIOS.cradleOptsProg cradle)
894+
where
895+
result
896+
| Bios.isStackCradle cradle
897+
|| name
898+
`elem` [Bios.Other Stack, Bios.Other StackNone]
899+
= "Stack project"
900+
| Bios.isCabalCradle cradle
901+
|| name
902+
`elem` [Bios.Other CabalV2, Bios.Other CabalNone]
903+
= "Cabal project"
904+
| Bios.isDirectCradle cradle
905+
= "GHC session"
906+
| Bios.isMultiCradle cradle
907+
= "Multi Component project"
908+
| otherwise
909+
= "project"
910+
name = Bios.actionName (Bios.cradleOptsProg cradle)

hie-plugin-api/Haskell/Ide/Engine/GhcModuleCache.hs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44

55
module Haskell.Ide.Engine.GhcModuleCache where
66

7-
import qualified Data.Map as Map
7+
import qualified Data.ByteString.Char8 as B
88
import Data.Dynamic (Dynamic)
9-
import Data.Typeable (TypeRep)
10-
11-
import qualified HIE.Bios as BIOS
9+
import Data.List
10+
import qualified Data.Map as Map
1211
import qualified Data.Trie as T
13-
import qualified Data.ByteString.Char8 as B
12+
import Data.Typeable (TypeRep)
1413

14+
import qualified HIE.Bios as Bios
1515
import GHC (TypecheckedModule, ParsedModule, HscEnv)
1616

17-
import Data.List
18-
19-
import Haskell.Ide.Engine.ArtifactMap
20-
21-
import Language.Haskell.LSP.Types
17+
import Haskell.Ide.Engine.ArtifactMap
18+
import Haskell.Ide.Engine.Cradle
19+
import Language.Haskell.LSP.Types
2220

2321
type UriCaches = Map.Map FilePath UriCacheResult
2422

@@ -103,7 +101,7 @@ lookupCradle fp gmc =
103101

104102
-- | Find the cradle wide 'ComponentOptions' that apply to a 'FilePath'
105103
lookupComponentOptions
106-
:: HasGhcModuleCache m => FilePath -> m (Maybe BIOS.ComponentOptions)
104+
:: HasGhcModuleCache m => FilePath -> m (Maybe Bios.ComponentOptions)
107105
lookupComponentOptions fp = do
108106
gmc <- getModuleCache
109107
return $ lookupInCache fp gmc (const Just) (Just . compOpts) Nothing
@@ -112,7 +110,7 @@ lookupInCache
112110
:: FilePath
113111
-> GhcModuleCache
114112
-- | Called when file is in the current cradle
115-
-> (BIOS.Cradle -> BIOS.ComponentOptions -> a)
113+
-> (Bios.Cradle CabalHelper -> Bios.ComponentOptions -> a)
116114
-- | Called when file is a member of a cached cradle
117115
-> (CachedCradle -> a)
118116
-- | Default value to return if a cradle is not found
@@ -126,9 +124,9 @@ lookupInCache fp gmc cur cached def = case currentCradle gmc of
126124

127125
-- | A 'Cradle', it's 'HscEnv' and 'ComponentOptions'
128126
data CachedCradle = CachedCradle
129-
{ ccradle :: BIOS.Cradle
127+
{ ccradle :: Bios.Cradle CabalHelper
130128
, hscEnv :: HscEnv
131-
, compOpts :: BIOS.ComponentOptions
129+
, compOpts :: Bios.ComponentOptions
132130
}
133131

134132
instance Show CachedCradle where
@@ -139,7 +137,7 @@ data GhcModuleCache = GhcModuleCache
139137
-- ^ map from FilePath to cradle and it's config.
140138
-- May not include currentCradle
141139
, uriCaches :: !UriCaches
142-
, currentCradle :: Maybe ([FilePath], BIOS.Cradle, BIOS.ComponentOptions)
140+
, currentCradle :: Maybe ([FilePath], Bios.Cradle CabalHelper, Bios.ComponentOptions)
143141
-- ^ The current cradle, it's config,
144142
-- and which FilePath's it is responsible for.
145143
} deriving (Show)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Haskell.Ide.Engine.Logger where
2+
3+
import Control.Monad.IO.Class
4+
import System.Log.Logger
5+
6+
logm :: MonadIO m => String -> m ()
7+
logm s = liftIO $ infoM "hie" s
8+
9+
debugm :: MonadIO m => String -> m ()
10+
debugm s = liftIO $ debugM "hie" s
11+
12+
warningm :: MonadIO m => String -> m ()
13+
warningm s = liftIO $ warningM "hie" s
14+
15+
errorm :: MonadIO m => String -> m ()
16+
errorm s = liftIO $ errorM "hie" s

0 commit comments

Comments
 (0)