Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
29 changes: 22 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 @@ -446,15 +447,29 @@
c ide

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 467 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