4
4
module Experiments.Types (module Experiments.Types ) where
5
5
6
6
import Data.Aeson
7
+ import Data.Maybe (fromMaybe )
7
8
import Data.Version
8
9
import Development.Shake.Classes
9
10
import GHC.Generics
10
11
import Numeric.Natural
11
- import System.FilePath (isPathSeparator )
12
12
13
13
data CabalStack = Cabal | Stack
14
14
deriving (Eq , Show )
@@ -31,40 +31,44 @@ data Config = Config
31
31
}
32
32
deriving (Eq , Show )
33
33
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 }
37
35
deriving (Eq , Generic , Show )
38
36
deriving anyclass (Binary , Hashable , NFData )
39
37
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 )
48
45
49
46
instance FromJSON Example where
50
47
parseJSON = withObject " example" $ \ x -> do
48
+ exampleName <- x .: " name"
51
49
exampleModules <- x .: " modules"
50
+ exampleExtraArgs <- fromMaybe [] <$> x .:? " extra-args"
52
51
53
52
path <- x .:? " path"
54
53
case path of
55
- Just examplePath -> return UsePackage {.. }
54
+ Just examplePath -> do
55
+ let exampleDetails = Left examplePath
56
+ return Example {.. }
56
57
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 {.. }
60
62
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
65
68
] ++
66
69
[" --example-module=" <> m | m <- exampleModules]
67
- exampleToOptions UsePackage { .. } =
70
+ exampleToOptions Example {exampleDetails = Left examplePath, .. } extraArgs =
68
71
[" --example-path" , examplePath
72
+ ," --ghcide-options" , unwords $ exampleExtraArgs ++ extraArgs
69
73
] ++
70
74
[" --example-module=" <> m | m <- exampleModules]
0 commit comments