1
1
mirror of https://github.com/github/semantic.git synced 2025-01-01 11:46:14 +03:00

Nuke the File type alias.

This commit is contained in:
Patrick Thomson 2020-01-24 16:49:00 -05:00
parent 262b21be91
commit 82c8555daa
7 changed files with 13 additions and 16 deletions

View File

@ -6,11 +6,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Data.Blob
( File
, Analysis.File.fileBody
, Analysis.File.filePath
, Analysis.File.fromPath
, Blob(..)
( Blob(..)
, Blobs(..)
, blobLanguage
, NoLanguageForBlob (..)

View File

@ -9,7 +9,7 @@ module Data.Project
import Prelude hiding (readFile)
import Prologue
import qualified Analysis.File
import Analysis.File
import Data.Blob
import Data.Blob.IO
import Data.Language
@ -33,7 +33,7 @@ projectName = T.pack . dropExtensions . takeFileName . projectRootDir
projectExtensions :: Project -> [String]
projectExtensions = extensionsForLanguage . projectLanguage
projectFiles :: Project -> [File]
projectFiles :: Project -> [File Language]
projectFiles = fmap blobFile . projectBlobs
readProjectFromPaths :: MonadIO m

View File

@ -15,7 +15,7 @@ module Semantic.Api.LegacyTypes
) where
import Data.Aeson
import Data.Blob hiding (File)
import Data.Blob
import Prologue
newtype DiffTreeRequest = DiffTreeRequest { blobs :: [BlobPair] }

View File

@ -22,7 +22,7 @@ import Control.Effect.Reader
import Control.Exception
import Control.Lens
import Data.Abstract.Declarations
import Data.Blob hiding (File)
import Data.Blob
import Data.ByteString.Builder
import Data.Language
import Data.ProtoLens (defMessage)

View File

@ -5,7 +5,6 @@ module Semantic.CLI (main) where
import qualified Analysis.File as File
import qualified Control.Carrier.Parse.Measured as Parse
import Control.Carrier.Reader
import Data.Blob
import Data.Blob.IO
import Data.Either
import qualified Data.Flag as Flag
@ -186,7 +185,7 @@ languageModes = Language.PerLanguageModes
<> value Language.ALaCarte
<> showDefault)
filePathReader :: ReadM File
filePathReader :: ReadM (File.File Language.Language)
filePathReader = File.fromPath <$> path
path :: (Path.PartClass.FileDir fd) => ReadM (Path.AbsRel fd)

View File

@ -43,6 +43,7 @@ import Prelude hiding (readFile)
import Analysis.Abstract.Caching.FlowInsensitive
import Analysis.Abstract.Collecting
import Analysis.Abstract.Graph as Graph
import Analysis.File
import Control.Abstract hiding (String)
import Control.Abstract.PythonPackage as PythonPackage
import Control.Algebra

View File

@ -27,6 +27,7 @@ module Semantic.Task.Files
, FilesArg(..)
) where
import Analysis.File
import Control.Algebra
import Control.Effect.Error
import Data.Blob
@ -43,10 +44,10 @@ import qualified System.Path as Path
import qualified System.Path.IO as IO (withBinaryFile)
data Source blob where
FromPath :: File -> Source Blob
FromPath :: File Language -> Source Blob
FromHandle :: Handle 'IO.ReadMode -> Source [Blob]
FromDir :: Path.AbsRelDir -> Source [Blob]
FromPathPair :: File -> File -> Source BlobPair
FromPathPair :: File Language -> File Language -> Source BlobPair
FromPairHandle :: Handle 'IO.ReadMode -> Source [BlobPair]
data Destination = ToPath Path.AbsRelFile | ToHandle (Handle 'IO.WriteMode)
@ -92,13 +93,13 @@ instance (Has (Error SomeException) sig m, MonadFail m, MonadIO m) => Algebra (F
Write (ToPath path) builder k -> liftIO (IO.withBinaryFile path IO.WriteMode (`B.hPutBuilder` builder)) >> k
Write (ToHandle (WriteHandle handle)) builder k -> liftIO (B.hPutBuilder handle builder) >> k
readBlob :: Has Files sig m => File -> m Blob
readBlob :: Has Files sig m => File Language -> m Blob
readBlob file = send (Read (FromPath file) pure)
-- Various ways to read in files
data FilesArg
= FilesFromHandle (Handle 'IO.ReadMode)
| FilesFromPaths [File]
| FilesFromPaths [File Language]
-- | A task which reads a list of 'Blob's from a 'Handle' or a list of 'FilePath's optionally paired with 'Language's.
readBlobs :: Has Files sig m => FilesArg -> m [Blob]
@ -106,7 +107,7 @@ readBlobs (FilesFromHandle handle) = send (Read (FromHandle handle) pure)
readBlobs (FilesFromPaths paths) = traverse (send . flip Read pure . FromPath) paths
-- | A task which reads a list of pairs of 'Blob's from a 'Handle' or a list of pairs of 'FilePath's optionally paired with 'Language's.
readBlobPairs :: Has Files sig m => Either (Handle 'IO.ReadMode) [(File, File)] -> m [BlobPair]
readBlobPairs :: Has Files sig m => Either (Handle 'IO.ReadMode) [(File Language, File Language)] -> m [BlobPair]
readBlobPairs (Left handle) = send (Read (FromPairHandle handle) pure)
readBlobPairs (Right paths) = traverse (send . flip Read pure . uncurry FromPathPair) paths