diff --git a/semantic-diff.cabal b/semantic-diff.cabal index 6c35afea2..a646db0b4 100644 --- a/semantic-diff.cabal +++ b/semantic-diff.cabal @@ -47,7 +47,6 @@ library , Diffing.Algorithm.RWS.FeatureVector , Diffing.Algorithm.SES , Diffing.Interpreter - , Files , Info , Language , Language.Markdown.Assignment @@ -75,6 +74,7 @@ library , Renderer.TOC , Semantic , Semantic.CLI + , Semantic.IO , Semantic.Log , Semantic.Stat , Semantic.Task diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index 1fd32cd23..c0daba137 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -7,7 +7,6 @@ module Semantic.CLI ) where import Control.Monad ((<=<)) -import Files (languageForFilePath) import Data.ByteString (ByteString) import Data.Foldable (find) import Data.Functor.Both hiding (fst, snd) @@ -20,8 +19,9 @@ import Language import Options.Applicative hiding (action) import Renderer import qualified Paths_semantic_diff as Library (version) -import qualified Semantic.Task as Task +import Semantic.IO (languageForFilePath) import qualified Semantic.Log as Log +import qualified Semantic.Task as Task import System.IO (Handle, stdin, stdout) import qualified Semantic (parseBlobs, diffBlobPairs) import Text.Read diff --git a/src/Files.hs b/src/Semantic/IO.hs similarity index 97% rename from src/Files.hs rename to src/Semantic/IO.hs index 63ff04e5f..003e0a040 100644 --- a/src/Files.hs +++ b/src/Semantic/IO.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings, TypeSynonymInstances, DeriveAnyClass, DuplicateRecordFields, ScopedTypeVariables, TupleSections #-} -module Files +module Semantic.IO ( readFile , isDirectory , readBlobPairsFromHandle @@ -60,7 +60,7 @@ readBlobsFromHandle = fmap toBlobs . readFromHandle where toBlobs BlobParse{..} = fmap toBlob blobs readBlobsFromPaths :: MonadIO m => [(FilePath, Maybe Language)] -> m [Blob.Blob] -readBlobsFromPaths = traverse (uncurry Files.readFile) +readBlobsFromPaths = traverse (uncurry Semantic.IO.readFile) readBlobsFromDir :: MonadIO m => FilePath -> m [Blob.Blob] readBlobsFromDir path = do diff --git a/src/Semantic/Task.hs b/src/Semantic/Task.hs index e03d6e9ce..ea4d082f3 100644 --- a/src/Semantic/Task.hs +++ b/src/Semantic/Task.hs @@ -46,13 +46,13 @@ import Data.Term import Data.Union import Decorator (RAlgebra, decoratorWithAlgebra) import Info hiding (Category(..)) -import qualified Files import Language import Parser import Parser.CMark import Parser.TreeSitter import System.Exit (die) import System.IO (Handle, stderr) +import qualified Semantic.IO as IO import Semantic.Log import Semantic.Stat as Stat import Semantic.Queue @@ -176,10 +176,10 @@ runTaskWithOptions options task = do where go :: Task a -> IO (Either SomeException a) go = iterFreerA (\ task yield -> case task of - ReadBlobs (Left handle) -> (Files.readBlobsFromHandle handle >>= yield) `catchError` (pure . Left . toException) - ReadBlobs (Right paths@[(path, Nothing)]) -> (Files.isDirectory path >>= bool (Files.readBlobsFromPaths paths) (Files.readBlobsFromDir path) >>= yield) `catchError` (pure . Left . toException) - ReadBlobs (Right paths) -> (Files.readBlobsFromPaths paths >>= yield) `catchError` (pure . Left . toException) - ReadBlobPairs source -> (either Files.readBlobPairsFromHandle (traverse (traverse (uncurry Files.readFile))) source >>= yield) `catchError` (pure . Left . toException) + ReadBlobs (Left handle) -> (IO.readBlobsFromHandle handle >>= yield) `catchError` (pure . Left . toException) + ReadBlobs (Right paths@[(path, Nothing)]) -> (IO.isDirectory path >>= bool (IO.readBlobsFromPaths paths) (IO.readBlobsFromDir path) >>= yield) `catchError` (pure . Left . toException) + ReadBlobs (Right paths) -> (IO.readBlobsFromPaths paths >>= yield) `catchError` (pure . Left . toException) + ReadBlobPairs source -> (either IO.readBlobPairsFromHandle (traverse (traverse (uncurry IO.readFile))) source >>= yield) `catchError` (pure . Left . toException) WriteToOutput destination contents -> either B.hPutStr B.writeFile destination contents >>= yield WriteLog level message pairs -> queueLogMessage logger level message pairs >>= yield WriteStat stat -> queue statter stat >>= yield diff --git a/src/Semantic/Util.hs b/src/Semantic/Util.hs index 66fd9888e..7c7b862f7 100644 --- a/src/Semantic/Util.hs +++ b/src/Semantic/Util.hs @@ -3,25 +3,25 @@ module Semantic.Util where import Control.Monad.IO.Class -import Data.Blob -import Files -import Data.Record -import Data.Functor.Classes -import Diffing.Algorithm import Data.Align.Generic +import Data.Blob +import Data.Diff +import Data.Functor.Both +import Data.Functor.Classes +import Data.Range +import Data.Record +import Data.Span +import Data.Term +import Diffing.Algorithm import Diffing.Interpreter import Parser -import Data.Functor.Both -import Data.Term -import Data.Diff -import Semantic -import Semantic.Task import Renderer.TOC -import Data.Range -import Data.Span +import Semantic +import Semantic.IO as IO +import Semantic.Task file :: MonadIO m => FilePath -> m Blob -file path = Files.readFile path (languageForFilePath path) +file path = IO.readFile path (languageForFilePath path) diffWithParser :: (HasField fields Data.Span.Span, HasField fields Range, diff --git a/test/CommandSpec.hs b/test/CommandSpec.hs index 597e7037b..78456da81 100644 --- a/test/CommandSpec.hs +++ b/test/CommandSpec.hs @@ -1,12 +1,12 @@ module CommandSpec where -import Files import Data.Blob import Data.Functor.Both as Both import Data.Maybe import Data.String import Language import Prelude hiding (readFile) +import Semantic.IO import System.Exit (ExitCode(..)) import System.IO (IOMode(..), openFile) import Test.Hspec hiding (shouldBe, shouldNotBe, shouldThrow, errorCall)