mirror of
https://github.com/Avi-D-coder/implicit-hie.git
synced 2024-11-22 17:55:51 +03:00
Fix cabal + named libraries
This commit is contained in:
parent
6ae40b0dc6
commit
0026002cba
6
hie.yaml
6
hie.yaml
@ -1,8 +1,8 @@
|
||||
cradle:
|
||||
stack:
|
||||
cabal:
|
||||
- path: "src"
|
||||
component: "implicit-hie:lib"
|
||||
- path: "app"
|
||||
component: "lib:implicit-hie"
|
||||
- path: "app/Main.hs"
|
||||
component: "implicit-hie:exe:gen-hie"
|
||||
- path: "test"
|
||||
component: "implicit-hie:test:implicit-hie-test"
|
||||
|
@ -18,16 +18,13 @@ type Indent = Int
|
||||
data Package = Package Name [Component]
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
data Component = Lib Path | Exe Name Path | Test Name Path
|
||||
data Component = Lib Name Path | Exe Name Path | Test Name Path
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
parseName :: Parser Text
|
||||
parseName = "name" >> skipSpace >> char ':' >> parseString
|
||||
|
||||
parsePackage :: Parser Package
|
||||
parsePackage =
|
||||
( do
|
||||
n <- parseName
|
||||
n <- field 0 "name"
|
||||
(Package _ t) <- parsePackage
|
||||
pure $ Package n t
|
||||
)
|
||||
@ -39,6 +36,15 @@ parsePackage =
|
||||
<|> (skipToNextLine >> parsePackage)
|
||||
<|> pure (Package "" [])
|
||||
|
||||
component :: Indent -> Text -> Parser Name
|
||||
component i t = do
|
||||
indent i
|
||||
_ <- asciiCI t
|
||||
skipMany tabOrSpace
|
||||
n <- parseString <|> pure ""
|
||||
skipToNextLine
|
||||
pure n
|
||||
|
||||
parseComponent :: Indent -> Parser Component
|
||||
parseComponent i =
|
||||
parseLib i
|
||||
@ -46,11 +52,9 @@ parseComponent i =
|
||||
<|> parseNamed i "test-suite" Test
|
||||
|
||||
parseLib :: Indent -> Parser Component
|
||||
parseLib i =
|
||||
indent i
|
||||
>> asciiCI "library"
|
||||
>> skipToNextLine
|
||||
>> Lib <$> extractPath (i + 1)
|
||||
parseLib i = do
|
||||
n <- component i "library"
|
||||
Lib n <$> extractPath (i + 1)
|
||||
|
||||
parseQuoted :: Parser Text
|
||||
parseQuoted = do
|
||||
@ -58,20 +62,12 @@ parseQuoted = do
|
||||
takeTill (== q)
|
||||
|
||||
parseString :: Parser Name
|
||||
parseString = do
|
||||
skipSpace
|
||||
parseQuoted <|> takeWhile1 (not . (\c -> isSpace c || c == ','))
|
||||
parseString = parseQuoted <|> takeWhile1 (not . (\c -> isSpace c || c == ','))
|
||||
|
||||
parseExe :: Indent -> Parser Component
|
||||
parseExe i =
|
||||
do
|
||||
indent i
|
||||
_ <- asciiCI "executable"
|
||||
_ <- skipSpace
|
||||
n <- parseString <?> "Exe Name"
|
||||
skipToNextLine
|
||||
Exe n <$> pathMain (i + 1) "." ""
|
||||
<?> T.unpack "parseExe"
|
||||
parseExe i = do
|
||||
n <- component i "executable"
|
||||
Exe n <$> pathMain (i + 1) "." ""
|
||||
|
||||
pathMain :: Indent -> Text -> Text -> Parser Text
|
||||
pathMain i p m =
|
||||
@ -85,7 +81,7 @@ parseNamed i compType compCon =
|
||||
do
|
||||
indent i
|
||||
_ <- asciiCI compType <?> "asciiCI " <> T.unpack compType
|
||||
_ <- skipSpace <?> "skipSpace"
|
||||
skipMany tabOrSpace
|
||||
n <- parseString <?> "N"
|
||||
skipToNextLine
|
||||
compCon n <$> extractPath (i + 1)
|
||||
@ -113,6 +109,7 @@ field i f =
|
||||
_ <- asciiCI f
|
||||
skipSpace
|
||||
_ <- char ':'
|
||||
skipSpace
|
||||
p <- parseString
|
||||
skipToNextLine
|
||||
pure p
|
||||
|
@ -23,17 +23,19 @@ indentT :: T.Text -> T.Text
|
||||
indentT = T.unlines . map (" " <>) . T.lines
|
||||
|
||||
cabalComponent :: Name -> Component -> T.Text
|
||||
cabalComponent n (Lib p) = component p $ "lib:" <> n
|
||||
cabalComponent _ (Exe p cn) = component p $ "exe:" <> cn
|
||||
cabalComponent _ (Test p cn) = component p $ "test:" <> cn
|
||||
cabalComponent n (Lib "" p) = comp p $ "lib:" <> n
|
||||
cabalComponent n (Lib cn p) = comp p $ "lib:" <> n <> ":" <> cn
|
||||
cabalComponent n (Exe cn p) = comp p $ n <> ":exe:" <> cn
|
||||
cabalComponent n (Test cn p) = comp p $ n <> ":test:" <> cn
|
||||
|
||||
stackComponent :: Name -> Component -> T.Text
|
||||
stackComponent n (Lib p) = component p $ n <> ":lib"
|
||||
stackComponent n (Exe cn p) = component p $ n <> ":exe:" <> cn
|
||||
stackComponent n (Test cn p) = component p $ n <> ":test:" <> cn
|
||||
stackComponent n (Lib "" p) = comp p $ n <> ":lib"
|
||||
stackComponent n (Lib cn p) = comp p $ n <> ":lib:" <> cn
|
||||
stackComponent n (Exe cn p) = comp p $ n <> ":exe:" <> cn
|
||||
stackComponent n (Test cn p) = comp p $ n <> ":test:" <> cn
|
||||
|
||||
component :: T.Text -> T.Text -> T.Text
|
||||
component p c =
|
||||
comp :: T.Text -> T.Text -> T.Text
|
||||
comp p c =
|
||||
"- path: "
|
||||
<> dQuote p
|
||||
<> "\n "
|
||||
|
13
test/Spec.hs
13
test/Spec.hs
@ -3,6 +3,7 @@
|
||||
import Data.Attoparsec.Text
|
||||
import qualified Data.Text as T
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.IO as T
|
||||
import Hie.Cabal.Parser
|
||||
import Hie.Yaml
|
||||
import Test.Hspec
|
||||
@ -24,13 +25,13 @@ spec = do
|
||||
describe "Should Succeed"
|
||||
$ it "successfully parses library section"
|
||||
$ libSection ~> parseLib 0
|
||||
`shouldParse` Lib "src"
|
||||
`shouldParse` Lib "" "src"
|
||||
describe "Should Succeed"
|
||||
$ it "successfully parses package"
|
||||
$ fullFile ~> parsePackage
|
||||
`shouldParse` Package
|
||||
"implicit-hie"
|
||||
[ Lib "src",
|
||||
[ Lib "" "src",
|
||||
Exe "implicit-hie-exe" "app/Main.hs",
|
||||
Test "implicit-hie-test" "test"
|
||||
]
|
||||
@ -43,6 +44,12 @@ spec = do
|
||||
describe "Should Succeed"
|
||||
$ it "successfully generates stack hie.yaml"
|
||||
$ (stackHieYaml <$> parseOnly parsePackage fullFile) `shouldBe` Right stackHie
|
||||
describe "Should Succeed"
|
||||
$ it "successfully generates stack hie.yaml"
|
||||
$ do
|
||||
f <- T.readFile "test/haskell-language-server-cabal"
|
||||
o <- T.readFile "test/hie.yaml.cbl"
|
||||
(cabalHieYaml <$> parseOnly parsePackage f) `shouldBe` Right o
|
||||
|
||||
fullFile :: Text
|
||||
fullFile = "name: implicit-hie\n" <> libSection <> exeSection <> testSection
|
||||
@ -78,7 +85,7 @@ testSection =
|
||||
|
||||
libSection :: Text
|
||||
libSection =
|
||||
"library\
|
||||
"library\n\
|
||||
\ exposed-modules:\n\
|
||||
\ Lib\n\
|
||||
\ other-modules:\n\
|
||||
|
Loading…
Reference in New Issue
Block a user