mirror of
https://github.com/Avi-D-coder/implicit-hie.git
synced 2024-11-23 02:06:17 +03:00
Get packages from cabal.project and stack.yaml
This commit is contained in:
parent
895fc55d12
commit
8219c06896
@ -4,7 +4,7 @@ cabal-version: 1.12
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
--
|
||||
-- hash: 62b7d90b1ed53933a4c7c61b6392cf2f7ce368607095d9255b80154c6997e755
|
||||
-- hash: 18f92037a7863d121ac45e847f7dc6177adf0ebc7951dfa1588340f86e64456b
|
||||
|
||||
name: implicit-hie
|
||||
version: 0.1.0.0
|
||||
@ -40,7 +40,9 @@ library
|
||||
, base >=4.7 && <5
|
||||
, directory
|
||||
, filepath
|
||||
, filepattern
|
||||
, text
|
||||
, transformers
|
||||
, yaml
|
||||
default-language: Haskell2010
|
||||
|
||||
@ -56,8 +58,10 @@ executable gen-hie
|
||||
, base >=4.7 && <5
|
||||
, directory
|
||||
, filepath
|
||||
, filepattern
|
||||
, implicit-hie
|
||||
, text
|
||||
, transformers
|
||||
, yaml
|
||||
default-language: Haskell2010
|
||||
|
||||
@ -74,9 +78,11 @@ test-suite implicit-hie-test
|
||||
, base >=4.7 && <5
|
||||
, directory
|
||||
, filepath
|
||||
, filepattern
|
||||
, hspec
|
||||
, hspec-attoparsec
|
||||
, implicit-hie
|
||||
, text
|
||||
, transformers
|
||||
, yaml
|
||||
default-language: Haskell2010
|
||||
|
@ -22,9 +22,11 @@ description: "Auto generate a stack or cabal multi component hie.yaml file"
|
||||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- text
|
||||
- transformers
|
||||
- attoparsec
|
||||
- yaml
|
||||
- directory
|
||||
- filepattern
|
||||
- filepath
|
||||
|
||||
ghc-options:
|
||||
|
@ -6,6 +6,7 @@ import Control.Applicative
|
||||
import Control.Monad
|
||||
import Data.Attoparsec.Text
|
||||
import Data.Char
|
||||
import Data.Maybe
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
|
||||
@ -86,7 +87,7 @@ parseString :: Parser Name
|
||||
parseString = parseQuoted <|> unqualName
|
||||
|
||||
unqualName :: Parser Text
|
||||
unqualName = takeWhile1 (\c -> isAlphaNum c || c `elem` ("-_./" :: String))
|
||||
unqualName = takeWhile1 (not . (\c -> isSpace c || c == ','))
|
||||
|
||||
parseList :: Indent -> Parser [Text]
|
||||
parseList i = items <|> (emptyOrComLine >> indent i >> items)
|
||||
@ -166,3 +167,6 @@ indent :: Indent -> Parser Int
|
||||
indent i = do
|
||||
c <- length <$> many' tabOrSpace
|
||||
if c >= i then pure c else fail "insufficient indent"
|
||||
|
||||
extractPkgs :: Parser [T.Text]
|
||||
extractPkgs = join . catMaybes <$> many' (Just <$> field 0 "packages" parseList <|> (skipToNextLine >> pure Nothing))
|
||||
|
@ -1,21 +1,51 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Hie.Locate
|
||||
( nestedPkg,
|
||||
nestedCabalFiles,
|
||||
stackYamlPkgs,
|
||||
cabalProjectPkgs,
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Monad.Trans.Maybe
|
||||
import Data.Attoparsec.Text
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as T
|
||||
import Data.Yaml
|
||||
import GHC.Generics
|
||||
import Hie.Cabal.Parser
|
||||
import Hie.Yaml
|
||||
import System.Directory
|
||||
import System.Directory.Internal
|
||||
import System.FilePath.Posix
|
||||
|
||||
newtype Pkgs = Pkgs [FilePath]
|
||||
deriving (Eq, Ord)
|
||||
|
||||
instance FromJSON Pkgs where
|
||||
parseJSON (Object v) = Pkgs <$> v .: "packages"
|
||||
parseJSON _ = fail "could not read packages from stack.yaml"
|
||||
|
||||
stackYamlPkgs :: FilePath -> MaybeT IO [FilePath]
|
||||
stackYamlPkgs p = liftIO $
|
||||
decodeFileEither (p </> "stack.yaml") >>= \case
|
||||
Right (Pkgs f) -> pure f
|
||||
Left e -> fail $ show e
|
||||
|
||||
cabalProjectPkgs :: FilePath -> MaybeT IO [FilePath]
|
||||
cabalProjectPkgs p = do
|
||||
cp <- liftIO $ T.readFile $ p </> "cabal.project"
|
||||
case parseOnly extractPkgs cp of
|
||||
Right f -> pure $ map T.unpack f
|
||||
_ -> fail "No packages found"
|
||||
|
||||
nestedCabalFiles :: FilePath -> IO [FilePath]
|
||||
nestedCabalFiles f = do
|
||||
fs <- listDirectory f
|
||||
|
Loading…
Reference in New Issue
Block a user