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
48 lines (44 loc) · 1.66 KB
/
IDE.hs
File metadata and controls
48 lines (44 loc) · 1.66 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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
-- | Functions for IDEs.
module Stack.IDE
( listPackages
, listTargets
) where
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import Stack.Config (getLocalPackages)
import Stack.Package (readPackageUnresolvedDir, gpdPackageName)
import Stack.Prelude
import Stack.Types.Config
import Stack.Types.Package
import Stack.Types.PackageName
-- | List the packages inside the current project.
listPackages :: HasEnvConfig env => RIO env ()
listPackages = do
-- TODO: Instead of setting up an entire EnvConfig only to look up the package directories,
-- make do with a Config (and the Project inside) and use resolvePackageEntry to get
-- the directory.
packageDirs <- liftM (map lpvRoot . Map.elems . lpProject) getLocalPackages
forM_ packageDirs $ \dir -> do
(gpd, _) <- readPackageUnresolvedDir dir False
(logInfo . packageNameText) (gpdPackageName gpd)
-- | List the targets in the current project.
listTargets :: HasEnvConfig env => RIO env ()
listTargets =
do rawLocals <- lpProject <$> getLocalPackages
logInfo
(T.intercalate
"\n"
(map
renderPkgComponent
(concatMap
toNameAndComponent
(Map.toList rawLocals))))
where
toNameAndComponent (pkgName,view') =
map (pkgName, ) (Set.toList (lpvComponents view'))