mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Remove fileForPath hack. More typed paths = good.
This commit is contained in:
parent
5a328dbf58
commit
cac106240b
@ -3,7 +3,6 @@ module Analysis.File
|
||||
( File(..)
|
||||
, fileLanguage
|
||||
, fromBody
|
||||
, fileForPath
|
||||
, fileForTypedPath
|
||||
) where
|
||||
|
||||
@ -29,10 +28,5 @@ fromBody body = File (Path.absRel (srcLocFile srcLoc)) (spanFromSrcLoc srcLoc) b
|
||||
fileLanguage :: File a -> Language
|
||||
fileLanguage = languageForTypedPath . filePath
|
||||
|
||||
-- | DEPRECATED: prefer 'fileForTypedPath' if at all possible.
|
||||
fileForPath :: FilePath -> File Language
|
||||
fileForPath p = File (Path.absRel p) lowerBound (languageForFilePath p)
|
||||
|
||||
-- | DEPRECATED
|
||||
fileForTypedPath :: Path.PartClass.AbsRel ar => Path.File ar -> File Language
|
||||
fileForTypedPath p = File (Path.absRel (Path.toString p)) lowerBound (languageForTypedPath p)
|
||||
|
@ -9,7 +9,6 @@ module Data.Blob
|
||||
( File
|
||||
, Analysis.File.fileBody
|
||||
, Analysis.File.filePath
|
||||
, Analysis.File.fileForPath
|
||||
, Analysis.File.fileForTypedPath
|
||||
, Blob(..)
|
||||
, Blobs(..)
|
||||
|
@ -4,6 +4,7 @@
|
||||
module Data.Blob.IO
|
||||
( readBlobFromFile
|
||||
, readBlobFromFile'
|
||||
, readBlobFromPath
|
||||
, readBlobsFromDir
|
||||
, readFilePair
|
||||
) where
|
||||
@ -27,12 +28,15 @@ readBlobFromFile file@(File path _ _language) = do
|
||||
let newblob = Blob (Source.fromUTF8 raw) file
|
||||
pure . Just $ newblob
|
||||
|
||||
-- | Read a utf8-encoded file to a 'Blob', raising an IOError if it can't be found.
|
||||
-- | Read a utf8-encoded file to a 'Blob', failing if it can't be found.
|
||||
readBlobFromFile' :: (MonadFail m, MonadIO m) => File Language -> m Blob
|
||||
readBlobFromFile' file = do
|
||||
maybeFile <- readBlobFromFile file
|
||||
maybeM (fail ("cannot read '" <> show file <> "', file not found or language not supported.")) maybeFile
|
||||
|
||||
readBlobFromPath :: (MonadFail m, MonadIO m) => Path.AbsRelFile -> m Blob
|
||||
readBlobFromPath = readBlobFromFile' . fileForTypedPath
|
||||
|
||||
-- | Read all blobs in the directory with Language.supportedExts.
|
||||
readBlobsFromDir :: MonadIO m => Path.AbsRelDir -> m [Blob]
|
||||
readBlobsFromDir path = liftIO . fmap catMaybes $
|
||||
|
@ -1,10 +1,12 @@
|
||||
{-# LANGUAGE ApplicativeDo, FlexibleContexts #-}
|
||||
{-# LANGUAGE ApplicativeDo #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
module Semantic.CLI (main) where
|
||||
|
||||
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
|
||||
import Data.Handle
|
||||
import qualified Data.Language as Language
|
||||
@ -151,10 +153,11 @@ graphCommand = command "graph" (info graphArgumentsParser (progDesc "Compute a g
|
||||
<$> ( Just <$> some (strArgument (metavar "FILES..."))
|
||||
<|> flag' Nothing (long "stdin" <> help "Read a list of newline-separated paths to analyze from stdin."))
|
||||
makeReadProjectFromPathsTask maybePaths = do
|
||||
paths <- maybeM (liftIO (many getLine)) maybePaths
|
||||
blobs <- traverse readBlobFromFile' (fileForPath <$> paths)
|
||||
ePaths <- maybeM (liftIO (many getLine)) maybePaths
|
||||
let paths = rights (Path.parse <$> ePaths)
|
||||
blobs <- traverse readBlobFromPath paths
|
||||
case paths of
|
||||
(x:_) -> pure $! Project (takeDirectory x) blobs (Language.languageForFilePath x) mempty
|
||||
(x:_) -> pure $! Project (Path.toString (Path.takeDirectory x)) blobs (Language.languageForTypedPath x) mempty
|
||||
_ -> pure $! Project "/" mempty Language.Unknown mempty
|
||||
|
||||
allLanguages = intercalate "|" . fmap show $ [Language.Go .. maxBound]
|
||||
@ -184,7 +187,7 @@ languageModes = Language.PerLanguageModes
|
||||
<> showDefault)
|
||||
|
||||
filePathReader :: ReadM File
|
||||
filePathReader = fileForPath <$> str
|
||||
filePathReader = fileForTypedPath <$> path
|
||||
|
||||
path :: (Path.PartClass.FileDir fd) => ReadM (Path.AbsRel fd)
|
||||
path = eitherReader Path.parse
|
||||
|
@ -16,6 +16,7 @@ module Semantic.Util
|
||||
|
||||
import Prelude hiding (readFile)
|
||||
|
||||
import Analysis.File
|
||||
import Control.Abstract
|
||||
import Control.Carrier.Fresh.Strict
|
||||
import Control.Carrier.Lift
|
||||
@ -31,7 +32,6 @@ import Data.Abstract.Module
|
||||
import qualified Data.Abstract.ModuleTable as ModuleTable
|
||||
import Data.Abstract.Package
|
||||
import Data.Abstract.Value.Concrete as Concrete
|
||||
import Data.Blob
|
||||
import Data.Blob.IO
|
||||
import Data.Graph (topologicalSort)
|
||||
import qualified Data.Language as Language
|
||||
@ -47,6 +47,7 @@ import Semantic.Task
|
||||
import Source.Span (HasSpan (..))
|
||||
import System.Exit (die)
|
||||
import System.FilePath.Posix (takeDirectory)
|
||||
import qualified System.Path as Path
|
||||
|
||||
justEvaluating :: Evaluator term Precise (Value term Precise) _ result
|
||||
-> IO ( Heap Precise Precise (Value term Precise),
|
||||
@ -91,6 +92,9 @@ parseFile, parseFileQuiet :: Parser term -> FilePath -> IO term
|
||||
parseFile parser = runTask' . (parse parser <=< readBlob . fileForPath)
|
||||
parseFileQuiet parser = runTaskQuiet . (parse parser <=< readBlob . fileForPath)
|
||||
|
||||
fileForPath :: FilePath -> File Language.Language
|
||||
fileForPath p = File (Path.absRel p) lowerBound (Language.languageForFilePath p)
|
||||
|
||||
runTask', runTaskQuiet :: ParseC TaskC a -> IO a
|
||||
runTask' task = runTaskWithOptions debugOptions (asks configTreeSitterParseTimeout >>= \ timeout -> runParse timeout task) >>= either (die . displayException) pure
|
||||
runTaskQuiet task = runTaskWithOptions defaultOptions (asks configTreeSitterParseTimeout >>= \ timeout -> runParse timeout task) >>= either (die . displayException) pure
|
||||
|
@ -1,12 +1,12 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Tags.Spec (spec) where
|
||||
|
||||
import Control.Carrier.Reader
|
||||
import Semantic.Api.Symbols
|
||||
import Source.Loc
|
||||
import SpecHelpers
|
||||
import Control.Carrier.Reader
|
||||
import Semantic.Api.Symbols
|
||||
import Source.Loc
|
||||
import SpecHelpers
|
||||
import qualified System.Path as Path
|
||||
import Tags.Tagging as Tags
|
||||
import Tags.Tagging as Tags
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
@ -90,4 +90,4 @@ spec = do
|
||||
]
|
||||
|
||||
parseTestFile :: Foldable t => t Tags.Kind -> Path.RelFile -> IO [Tag]
|
||||
parseTestFile include path = runTaskOrDie $ readBlob (fileForPath (Path.toString path)) >>= runReader defaultLanguageModes . fmap (filter ((`elem` include) . kind)) . tagsForBlob
|
||||
parseTestFile include path = runTaskOrDie $ readBlob (fileForTypedPath path) >>= runReader defaultLanguageModes . fmap (filter ((`elem` include) . kind)) . tagsForBlob
|
||||
|
Loading…
Reference in New Issue
Block a user