Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ library
, optparse-applicative
, os-string
, parallel
, process
, prettyprinter >=1.7
, prettyprinter-ansi-terminal
, random
Expand Down
32 changes: 25 additions & 7 deletions ghcide/src/Development/IDE/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@
import Numeric.Natural (Natural)
import Options.Applicative hiding (action)
import qualified System.Directory.Extra as IO
import System.Exit (ExitCode (ExitFailure),
import System.Exit (ExitCode (ExitFailure, ExitSuccess),
exitWith)
import System.FilePath (takeExtension,
takeFileName)
takeFileName, (</>))
import System.IO (BufferMode (LineBuffering, NoBuffering),
Handle, hFlush,
hPutStrLn,
hSetBuffering,
hSetEncoding, stderr,
stdin, stdout, utf8)
import System.Process (readProcessWithExitCode)
import System.Random (newStdGen)
import System.Time.Extra (Seconds, offsetTime,
showDuration)
Expand Down Expand Up @@ -445,16 +446,33 @@
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)
c ide

-- | List the haskell files given some paths
--
-- It will rely on git if possible to filter-out ignored files.
expandFiles :: [FilePath] -> IO [FilePath]
expandFiles = concatMapM $ \x -> do
expandFiles paths = do
let haskellFind x =
let recurse "." = True
recurse y | "." `isPrefixOf` takeFileName y = False -- skip .git etc
recurse y = takeFileName y `notElem` ["dist", "dist-newstyle"] -- cabal directories
in filter (\y -> takeExtension y `elem` [".hs", ".lhs"]) <$> IO.listFilesInside (return . recurse) x
(testGitExitCode, _, _) <- readProcessWithExitCode "git" ["status"] ""
let findFiles =
case testGitExitCode of
ExitSuccess -> \path -> do
let lookups = [path, path </> "*.hs", path </> "*.lhs"]
(trackedExitCode, trackedStdout, _) <- readProcessWithExitCode "git" ("ls-files":lookups) ""
(untrackedExitCode, untrackedStdout, _) <- readProcessWithExitCode "git" ("ls-files":"-o":lookups) ""
if trackedExitCode == ExitSuccess && untrackedExitCode == ExitSuccess
then pure $ lines trackedStdout <> lines untrackedStdout
else haskellFind path
_ -> haskellFind
flip concatMapM paths $ \x -> do

Check warning on line 470 in ghcide/src/Development/IDE/Main.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in expandFiles in module Development.IDE.Main: Use concatForM ▫︎ Found: "flip concatMapM" ▫︎ Perhaps: "concatForM"
b <- IO.doesFileExist x
if b
then return [x]
else do
let recurse "." = True
recurse y | "." `isPrefixOf` takeFileName y = False -- skip .git etc
recurse y = takeFileName y `notElem` ["dist", "dist-newstyle"] -- cabal directories
files <- filter (\y -> takeExtension y `elem` [".hs", ".lhs"]) <$> IO.listFilesInside (return . recurse) x
files <- findFiles x
when (null files) $
fail $ "Couldn't find any .hs/.lhs files inside directory: " ++ x
return files
Loading