44module Experiments.Types (module Experiments.Types ) where
55
66import Data.Aeson
7+ import Data.Maybe (fromMaybe )
78import Data.Version
89import Development.Shake.Classes
910import GHC.Generics
1011import Numeric.Natural
11- import System.FilePath (isPathSeparator )
1212
1313data CabalStack = Cabal | Stack
1414 deriving (Eq , Show )
@@ -31,40 +31,44 @@ data Config = Config
3131 }
3232 deriving (Eq , Show )
3333
34- data Example
35- = GetPackage { exampleName :: ! String , exampleModules :: [FilePath ], exampleVersion :: Version }
36- | UsePackage { examplePath :: FilePath , exampleModules :: [FilePath ]}
34+ data ExamplePackage = ExamplePackage { packageName :: ! String , packageVersion :: ! Version }
3735 deriving (Eq , Generic , Show )
3836 deriving anyclass (Binary , Hashable , NFData )
3937
40- getExampleName :: Example -> String
41- getExampleName UsePackage {examplePath} = map replaceSeparator examplePath
42- where
43- replaceSeparator x
44- | isPathSeparator x = ' _'
45- | otherwise = x
46- getExampleName GetPackage {exampleName, exampleVersion} =
47- exampleName <> " -" <> showVersion exampleVersion
38+ data Example = Example
39+ { exampleName :: ! String
40+ , exampleDetails :: Either FilePath ExamplePackage
41+ , exampleModules :: [FilePath ]
42+ , exampleExtraArgs :: [String ]}
43+ deriving (Eq , Generic , Show )
44+ deriving anyclass (Binary , Hashable , NFData )
4845
4946instance FromJSON Example where
5047 parseJSON = withObject " example" $ \ x -> do
48+ exampleName <- x .: " name"
5149 exampleModules <- x .: " modules"
50+ exampleExtraArgs <- fromMaybe [] <$> x .:? " extra-args"
5251
5352 path <- x .:? " path"
5453 case path of
55- Just examplePath -> return UsePackage {.. }
54+ Just examplePath -> do
55+ let exampleDetails = Left examplePath
56+ return Example {.. }
5657 Nothing -> do
57- exampleName <- x .: " name"
58- exampleVersion <- x .: " version"
59- return GetPackage {.. }
58+ packageName <- x .: " package"
59+ packageVersion <- x .: " version"
60+ let exampleDetails = Right ExamplePackage {.. }
61+ return Example {.. }
6062
61- exampleToOptions :: Example -> [String ]
62- exampleToOptions GetPackage {.. } =
63- [" --example-package-name" , exampleName
64- ," --example-package-version" , showVersion exampleVersion
63+ exampleToOptions :: Example -> [String ] -> [String ]
64+ exampleToOptions Example {exampleDetails = Right ExamplePackage {.. }, .. } extraArgs =
65+ [" --example-package-name" , packageName
66+ ," --example-package-version" , showVersion packageVersion
67+ ," --ghcide-options" , unwords $ exampleExtraArgs ++ extraArgs
6568 ] ++
6669 [" --example-module=" <> m | m <- exampleModules]
67- exampleToOptions UsePackage { .. } =
70+ exampleToOptions Example {exampleDetails = Left examplePath, .. } extraArgs =
6871 [" --example-path" , examplePath
72+ ," --ghcide-options" , unwords $ exampleExtraArgs ++ extraArgs
6973 ] ++
7074 [" --example-module=" <> m | m <- exampleModules]
0 commit comments