-
-
Notifications
You must be signed in to change notification settings - Fork 410
Rely on gitignore to exclude listed files in ghcide (#4665) #4736
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import Control.Concurrent.MVar (MVar, newEmptyMVar, | ||
| putMVar, tryReadMVar) | ||
| import Control.Concurrent.STM.Stats (dumpSTMStats) | ||
| import Control.Exception.Safe as Safe | ||
| import Control.Monad.Extra (concatMapM, unless, | ||
| when) | ||
| import Control.Monad.IO.Class (liftIO) | ||
|
|
@@ -114,16 +115,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) | ||
|
|
@@ -445,16 +447,43 @@ | |
| 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 | ||
| git args = do | ||
| mResult <- (Just <$> readProcessWithExitCode "git" args "") `Safe.catchAny`const (pure Nothing) | ||
| pure $ | ||
| case mResult of | ||
| Just (ExitSuccess, gitStdout, _) -> Just gitStdout | ||
| _ -> Nothing | ||
| mHasGit <- git ["status"] | ||
| let findFiles = | ||
| case mHasGit of | ||
| Just _ -> \path -> do | ||
| let lookups = | ||
| if takeExtension path `elem` [".hs", ".lhs"] | ||
| then [path] | ||
|
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. Question, what should happen if a user explicitly asks for a file to load, but the file is Should we perhaps still load it? I feel like, that might be more natural behaviour, but I am admittedly not sure. 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. We could add an option in the CLI to by-pass gitignore, but I guess it'll be more complex. Any idea which form the warning would take? 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. The warning should probably just be printed via the |
||
| else [path </> "*.hs", path </> "*.lhs"] | ||
| gitLines args = fmap lines <$> git args | ||
| mTracked <- gitLines ("ls-files":lookups) | ||
| mUntracked <- gitLines ("ls-files":"-o":lookups) | ||
| case mTracked <> mUntracked of | ||
| Nothing -> haskellFind path | ||
| Just files -> pure files | ||
| _ -> haskellFind | ||
| flip concatMapM paths $ \x -> do | ||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.