Skip to content

Commit daffb97

Browse files
committed
fix: check thrown error (not found)
1 parent 7957387 commit daffb97

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

ghcide/src/Development/IDE/Main.hs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Control.Concurrent.Extra (withNumCapabilities)
1515
import Control.Concurrent.MVar (MVar, newEmptyMVar,
1616
putMVar, tryReadMVar)
1717
import Control.Concurrent.STM.Stats (dumpSTMStats)
18+
import Control.Exception.Safe as Safe
1819
import Control.Monad.Extra (concatMapM, unless,
1920
when)
2021
import Control.Monad.IO.Class (liftIO)
@@ -456,16 +457,23 @@ expandFiles paths = do
456457
recurse y | "." `isPrefixOf` takeFileName y = False -- skip .git etc
457458
recurse y = takeFileName y `notElem` ["dist", "dist-newstyle"] -- cabal directories
458459
in filter (\y -> takeExtension y `elem` [".hs", ".lhs"]) <$> IO.listFilesInside (return . recurse) x
459-
(testGitExitCode, _, _) <- readProcessWithExitCode "git" ["status"] ""
460+
git args = do
461+
mResult <- (Just <$> readProcessWithExitCode "git" args "") `Safe.catchAny`const (pure Nothing)
462+
pure $
463+
case mResult of
464+
Just (ExitSuccess, gitStdout, _) -> Just gitStout
465+
_ -> Nothing
466+
mHasGit <- git ["status"]
460467
let findFiles =
461-
case testGitExitCode of
462-
ExitSuccess -> \path -> do
468+
case mHasGit of
469+
Just _ -> \path -> do
463470
let lookups = [path, path </> "*.hs", path </> "*.lhs"]
464-
(trackedExitCode, trackedStdout, _) <- readProcessWithExitCode "git" ("ls-files":lookups) ""
465-
(untrackedExitCode, untrackedStdout, _) <- readProcessWithExitCode "git" ("ls-files":"-o":lookups) ""
466-
if trackedExitCode == ExitSuccess && untrackedExitCode == ExitSuccess
467-
then pure $ lines trackedStdout <> lines untrackedStdout
468-
else haskellFind path
471+
gitLines args = fmap lines <$> git args
472+
mTracked <- gitlines ("ls-files":lookups)
473+
mUntracked <- gitlines ("ls-files":"-o":lookups)
474+
case mTracked <> mUntracked of
475+
Nothing -> haskellFind path
476+
Just files -> pure files
469477
_ -> haskellFind
470478
flip concatMapM paths $ \x -> do
471479
b <- IO.doesFileExist x

0 commit comments

Comments
 (0)