-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Cabal helper loader #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,7 @@ tags | |
TAGS | ||
codex.tags | ||
.vim | ||
|
||
|
||
## test specific ignores | ||
test/testdata/**/stack.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE MultiWayIf #-} | ||
|
||
module Main where | ||
|
@@ -14,24 +15,38 @@ import Hie.Locate | |
import Hie.Yaml | ||
import System.Directory | ||
import System.Directory.Internal | ||
import System.FilePath.Posix | ||
import System.FilePath | ||
import Hie.CabalHelper | ||
import Distribution.Helper (Ex (..)) | ||
|
||
main :: IO () | ||
main = do | ||
pwd <- getCurrentDirectory | ||
files <- listDirectory pwd | ||
let name = | ||
if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal" | ||
| any ((".stack-work" ==) . takeFileName) files -> "stack" | ||
| any (("cabal.project" ==) . takeFileName) files -> "cabal" | ||
| any (("stack.yaml" ==) . takeFileName) files -> "stack" | ||
| otherwise -> "cabal" | ||
cfs <- runMaybeT $ case name of | ||
"cabal" -> cabalPkgs pwd | ||
_ -> stackYamlPkgs pwd | ||
when (null cfs) $ error $ | ||
"No .cabal files found under" | ||
<> pwd | ||
<> "\n You may need to run stack build." | ||
pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs) | ||
putStr <$> hieYaml name $ fmtPkgs name pkgs | ||
projM <- findCabalHelperEntryPoint $ pwd </> "Foo.hs" | ||
case projM of | ||
Nothing -> error "could not find project context" | ||
Just proj@(Ex p) -> do | ||
env <- initialiseEnvironment p | ||
packages <- loadPackages env | ||
pkgs <- toHieYaml env packages | ||
let name = if | isCabalProject proj -> "cabal" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the logic of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is something to worry about for later. In this case, the project is decided based on the found files, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point, we should take build directory into account first so the cabal-helper implicit logic marches the default logic and builds with the users preferred tool. |
||
| isStackProject proj -> "stack" | ||
| otherwise -> error "Neither stack nor cabal project" | ||
putStr $ hieYaml name $ fmtPkgs name pkgs | ||
|
||
-- files <- listDirectory pwd | ||
-- let name = | ||
-- if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal" | ||
-- | any ((".stack-work" ==) . takeFileName) files -> "stack" | ||
-- | any (("cabal.project" ==) . takeFileName) files -> "cabal" | ||
-- | any (("stack.yaml" ==) . takeFileName) files -> "stack" | ||
-- | otherwise -> "cabal" | ||
-- cfs <- runMaybeT $ case name of | ||
-- "cabal" -> cabalPkgs pwd | ||
-- _ -> stackYamlPkgs pwd | ||
-- when (null cfs) $ error $ | ||
-- "No .cabal files found under" | ||
-- <> pwd | ||
-- <> "\n You may need to run stack build." | ||
-- pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs) | ||
-- putStr <$> hieYaml name $ fmtPkgs name pkgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay, but should be optional and behind the cabal-helper and command line flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it is a show-case, it should also not remove the old behaviour as it is waaaaaaaaayyy faster and should be the default mode. So, adding a cli would be sensible, imo, via optparse-applicative