mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Define a convenience to throw NoLanguageForBlob exceptions.
This commit is contained in:
parent
d3fa821425
commit
3b77af069d
@ -15,7 +15,7 @@ import Parsing.Parser
|
||||
import Prologue hiding (MonadError(..))
|
||||
import Rendering.Graph
|
||||
import Rendering.Renderer
|
||||
import Semantic.IO (NoLanguageForBlob(..))
|
||||
import Semantic.IO (noLanguageForBlob)
|
||||
import Semantic.Stat as Stat
|
||||
import Semantic.Task as Task
|
||||
import Serializing.Format
|
||||
@ -32,7 +32,7 @@ diffBlobPair renderer blobs
|
||||
JSONDiffRenderer -> run (WrapTask . ( parse parser >=> decorate constructorLabel >=> decorate identifierLabel)) diffTerms renderJSONDiff
|
||||
SExpressionDiffRenderer -> run (WrapTask . ( parse parser >=> decorate constructorLabel . (Nil <$))) diffTerms (const id) >>= serialize SExpression
|
||||
DOTDiffRenderer -> run (WrapTask . parse parser) diffTerms (const renderTreeGraph) >>= serialize (DOT (diffStyle (pathKeyForBlobPair blobs)))
|
||||
| otherwise = throwError (SomeException (NoLanguageForBlob effectivePath))
|
||||
| otherwise = noLanguageForBlob effectivePath
|
||||
where effectivePath = pathForBlobPair blobs
|
||||
effectiveLanguage = languageForBlobPair blobs
|
||||
|
||||
|
@ -11,6 +11,7 @@ module Semantic.IO
|
||||
, findFiles
|
||||
, languageForFilePath
|
||||
, NoLanguageForBlob(..)
|
||||
, noLanguageForBlob
|
||||
, FormatNotSupported(..)
|
||||
, readBlob
|
||||
, readProject
|
||||
@ -179,6 +180,10 @@ instance FromJSON BlobPair where
|
||||
newtype NoLanguageForBlob = NoLanguageForBlob FilePath
|
||||
deriving (Eq, Exception, Ord, Show, Typeable)
|
||||
|
||||
noLanguageForBlob :: Member (Exc SomeException) effs => FilePath -> Eff effs a
|
||||
noLanguageForBlob blobPath = throwError (SomeException (NoLanguageForBlob blobPath))
|
||||
|
||||
|
||||
-- | An exception indicating that the output format is not supported
|
||||
newtype FormatNotSupported = FormatNotSupported String
|
||||
deriving (Eq, Exception, Ord, Show, Typeable)
|
||||
|
@ -11,7 +11,7 @@ import Parsing.Parser
|
||||
import Prologue hiding (MonadError(..))
|
||||
import Rendering.Graph
|
||||
import Rendering.Renderer
|
||||
import Semantic.IO (NoLanguageForBlob(..), FormatNotSupported(..))
|
||||
import Semantic.IO (noLanguageForBlob, FormatNotSupported(..))
|
||||
import Semantic.Task
|
||||
import Serializing.Format
|
||||
|
||||
@ -29,7 +29,7 @@ parseBlob renderer blob@Blob{..}
|
||||
ImportsTermRenderer -> decorate (declarationAlgebra blob) >=> decorate (packageDefAlgebra blob) >=> render (renderToImports blob)
|
||||
SymbolsTermRenderer fields -> decorate (declarationAlgebra blob) >=> render (renderSymbolTerms . renderToSymbols fields blob)
|
||||
DOTTermRenderer -> render renderTreeGraph >=> serialize (DOT (termStyle blobPath))
|
||||
| otherwise = throwError (SomeException (NoLanguageForBlob blobPath))
|
||||
| otherwise = noLanguageForBlob blobPath
|
||||
|
||||
|
||||
astParseBlobs :: (Members '[Distribute WrappedTask, Task, Exc SomeException] effs, Monoid output) => TermRenderer output -> [Blob] -> Eff effs output
|
||||
@ -42,4 +42,4 @@ astParseBlobs renderer blobs = distributeFoldMap (WrapTask . astParseBlob render
|
||||
SExpressionTermRenderer -> serialize SExpression
|
||||
JSONTermRenderer -> render (renderJSONTerm' blob)
|
||||
_ -> pure $ throwError (SomeException (FormatNotSupported "Only SExpression and JSON output supported for tree-sitter ASTs."))
|
||||
| otherwise = throwError (SomeException (NoLanguageForBlob blobPath))
|
||||
| otherwise = noLanguageForBlob blobPath
|
||||
|
Loading…
Reference in New Issue
Block a user