forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIDE.hs
More file actions
59 lines (52 loc) · 1.95 KB
/
IDE.hs
File metadata and controls
59 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- | Functions for IDEs.
module Stack.IDE
( OutputStream(..)
, ListPackagesCmd(..)
, listPackages
, listTargets
) where
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import Stack.Prelude
import Stack.Types.Config
import Stack.Types.NamedComponent
import Stack.Types.SourceMap
import System.IO (putStrLn)
data OutputStream = OutputLogInfo
| OutputStdout
data ListPackagesCmd = ListPackageNames
| ListPackageCabalFiles
outputFunc :: HasLogFunc env => OutputStream -> String -> RIO env ()
outputFunc OutputLogInfo = logInfo . fromString
outputFunc OutputStdout = liftIO . putStrLn
-- | List the packages inside the current project.
listPackages :: HasBuildConfig env => OutputStream -> ListPackagesCmd -> RIO env ()
listPackages stream flag = do
packages <- view $ buildConfigL.to (smwProject . bcSMWanted)
let strs = case flag of
ListPackageNames ->
map packageNameString (Map.keys packages)
ListPackageCabalFiles ->
map (toFilePath . ppCabalFP) (Map.elems packages)
mapM_ (outputFunc stream) strs
-- | List the targets in the current project.
listTargets :: forall env. HasBuildConfig env => OutputStream -> RIO env ()
listTargets stream = do
packages <- view $ buildConfigL.to (smwProject . bcSMWanted)
pairs <- concat <$> Map.traverseWithKey toNameAndComponent packages
outputFunc stream $ T.unpack $ T.intercalate "\n" $
map renderPkgComponent pairs
where
toNameAndComponent
:: PackageName
-> ProjectPackage
-> RIO env [(PackageName, NamedComponent)]
toNameAndComponent pkgName' =
fmap (map (pkgName', ) . Set.toList) . ppComponents