Skip to content

Commit ec14879

Browse files
committed
Fix build and use Data.Default consistently
1 parent f32b027 commit ec14879

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

exe/Wrapper.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
module Main where
55

66
import Control.Monad.Extra
7+
import Data.Default
78
import Data.Foldable
89
import Data.List
910
import Data.Void
10-
import Development.IDE.Session (findCradle, defaultLoadingOptions)
11+
import Development.IDE.Session (findCradle)
1112
import HIE.Bios hiding (findCradle)
1213
import HIE.Bios.Environment
1314
import HIE.Bios.Types
@@ -140,7 +141,7 @@ getRuntimeGhcVersion' cradle = do
140141
-- of the project that may or may not be accurate.
141142
findLocalCradle :: FilePath -> IO (Cradle Void)
142143
findLocalCradle fp = do
143-
cradleConf <- findCradle defaultLoadingOptions fp
144+
cradleConf <- findCradle def fp
144145
crdl <- case cradleConf of
145146
Just yaml -> do
146147
hPutStrLn stderr $ "Found \"" ++ yaml ++ "\" for \"" ++ fp ++ "\""

ghcide/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ main = do
6666
DbCmd opts cmd -> do
6767
dir <- IO.getCurrentDirectory
6868
dbLoc <- getHieDbLoc dir
69-
mlibdir <- setInitialDynFlags
69+
mlibdir <- setInitialDynFlags def
7070
case mlibdir of
7171
Nothing -> exitWith $ ExitFailure 1
7272
Just libdir -> runCommand libdir opts{database = dbLoc} cmd

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ The logic for setting up a ghcide session by tapping into hie-bios.
88
module Development.IDE.Session
99
(SessionLoadingOptions(..)
1010
,CacheDirs(..)
11-
,defaultLoadingOptions
1211
,loadSession
1312
,loadSessionWithOptions
1413
,setInitialDynFlags
@@ -34,6 +33,7 @@ import qualified Data.Text as T
3433
import Data.Aeson
3534
import Data.Bifunctor
3635
import qualified Data.ByteString.Base16 as B16
36+
import Data.Default
3737
import Data.Either.Extra
3838
import Data.Function
3939
import Data.Hashable
@@ -102,13 +102,13 @@ data SessionLoadingOptions = SessionLoadingOptions
102102
, getInitialGhcLibDir :: IO (Maybe LibDir)
103103
}
104104

105-
defaultLoadingOptions :: SessionLoadingOptions
106-
defaultLoadingOptions = SessionLoadingOptions
107-
{findCradle = HieBios.findCradle
108-
,loadCradle = HieBios.loadCradle
109-
,getCacheDirs = getCacheDirsDefault
110-
,getInitialGhcLibDir = getInitialGhcLibDirDefault
111-
}
105+
instance Default SessionLoadingOptions where
106+
def = SessionLoadingOptions
107+
{findCradle = HieBios.findCradle
108+
,loadCradle = HieBios.loadCradle
109+
,getCacheDirs = getCacheDirsDefault
110+
,getInitialGhcLibDir = getInitialGhcLibDirDefault
111+
}
112112

113113
getInitialGhcLibDirDefault :: IO (Maybe LibDir)
114114
getInitialGhcLibDirDefault = do
@@ -184,7 +184,7 @@ getHieDbLoc dir = do
184184
-- components mapping to the same hie.yaml file are mapped to the same
185185
-- HscEnv which is updated as new components are discovered.
186186
loadSession :: FilePath -> IO (Action IdeGhcSession)
187-
loadSession = loadSessionWithOptions defaultLoadingOptions
187+
loadSession = loadSessionWithOptions def
188188

189189
loadSessionWithOptions :: SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession)
190190
loadSessionWithOptions SessionLoadingOptions{..} dir = do

ghcide/src/Development/IDE/Main.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Development.IDE.Main (Arguments(..), defArguments, defaultMain) where
1+
module Development.IDE.Main (Arguments(..), defaultMain) where
22
import Control.Concurrent.Extra (readVar)
33
import Control.Exception.Safe (
44
Exception (displayException),
@@ -47,7 +47,7 @@ import Development.IDE.Plugin (
4747
Plugin (pluginHandlers, pluginRules),
4848
)
4949
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
50-
import Development.IDE.Session (SessionLoadingOptions, defaultLoadingOptions, loadSessionWithOptions, setInitialDynFlags, getHieDbLoc, runWithDb)
50+
import Development.IDE.Session (SessionLoadingOptions, loadSessionWithOptions, setInitialDynFlags, getHieDbLoc, runWithDb)
5151
import Development.IDE.Types.Location (toNormalizedFilePath')
5252
import Development.IDE.Types.Logger (Logger)
5353
import Development.IDE.Types.Options (
@@ -85,16 +85,15 @@ data Arguments = Arguments
8585
, argsGetHieDbLoc :: FilePath -> IO FilePath -- ^ Map project roots to the location of the hiedb for the project
8686
}
8787

88-
defArguments :: Arguments
89-
defArguments =
90-
Arguments
88+
instance Default Arguments where
89+
def = Arguments
9190
{ argsOTMemoryProfiling = False
9291
, argFiles = Nothing
9392
, argsLogger = noLogging
9493
, argsRules = mainRule >> action kick
9594
, argsGhcidePlugin = mempty
9695
, argsHlsPlugins = pluginDescToIdePlugins Ghcide.descriptors
97-
, argsSessionLoadingOptions = defaultLoadingOptions
96+
, argsSessionLoadingOptions = def
9897
, argsIdeOptions = const defaultIdeOptions
9998
, argsLspOptions = def {LSP.completionTriggerCharacters = Just "."}
10099
, argsDefaultHlsConfig = def

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ executable haskell-language-server-wrapper
365365
ghc-options: -Werror
366366

367367
build-depends:
368+
, data-default
368369
, ghc
369370
, ghc-paths
370371
, ghcide

src/Ide/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import HieDb.Run
3131
import qualified Development.IDE.Main as Main
3232
import qualified Development.IDE.Types.Options as Ghcide
3333
import Development.Shake (ShakeOptions(shakeThreads))
34+
import Data.Default
3435

3536
defaultMain :: Arguments -> IdePlugins IdeState -> IO ()
3637
defaultMain args idePlugins = do
@@ -55,7 +56,7 @@ defaultMain args idePlugins = do
5556
dir <- IO.getCurrentDirectory
5657
dbLoc <- getHieDbLoc dir
5758
hPutStrLn stderr $ "Using hiedb at: " ++ dbLoc
58-
mlibdir <- setInitialDynFlags
59+
mlibdir <- setInitialDynFlags def
5960
case mlibdir of
6061
Nothing -> exitWith $ ExitFailure 1
6162
Just libdir ->
@@ -93,7 +94,7 @@ runLspMode lspArgs@LspArguments{..} idePlugins = do
9394
hPutStrLn stderr $ " in directory: " <> dir
9495
hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
9596

96-
Main.defaultMain Main.defArguments
97+
Main.defaultMain def
9798
{ Main.argFiles = if argLSP then Nothing else Just []
9899
, Main.argsHlsPlugins = idePlugins
99100
, Main.argsLogger = hlsLogger

0 commit comments

Comments
 (0)