mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
Replace the indexing renderer with an indexing operation.
This commit is contained in:
parent
6ed683f9be
commit
4334e24aa4
@ -10,7 +10,7 @@ module Renderer
|
||||
, File(..)
|
||||
) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.Aeson (Value, object)
|
||||
import Data.Functor.Both
|
||||
import Data.Functor.Classes
|
||||
import Text.Show
|
||||
@ -62,8 +62,8 @@ resolveParseTreeRenderer renderer blob = case renderer of
|
||||
SExpressionParseTreeRenderer format -> R.sExpressionParseTree format blob
|
||||
JSONParseTreeRenderer True -> R.jsonFile blob . decoratorWithAlgebra (fToR identifierAlg) . decoratorWithAlgebra (sourceDecorator (source blob))
|
||||
JSONParseTreeRenderer False -> R.jsonFile blob . decoratorWithAlgebra (fToR identifierAlg)
|
||||
JSONIndexParseTreeRenderer True -> R.jsonIndexParseTree blob . decoratorWithAlgebra (fToR identifierAlg) . decoratorWithAlgebra (sourceDecorator (source blob))
|
||||
JSONIndexParseTreeRenderer False -> R.jsonIndexParseTree blob . decoratorWithAlgebra (fToR identifierAlg)
|
||||
JSONIndexParseTreeRenderer True -> R.jsonFile blob . fmap (object . toJSONFields) . indexTerm . decoratorWithAlgebra (fToR identifierAlg) . decoratorWithAlgebra (sourceDecorator (source blob))
|
||||
JSONIndexParseTreeRenderer False -> R.jsonFile blob . fmap (object . toJSONFields) . indexTerm . decoratorWithAlgebra (fToR identifierAlg)
|
||||
where sourceDecorator source (ann :< _) = Just (SourceText (toText (Source.slice (byteRange ann) source)))
|
||||
identifierAlg = fmap R.Identifier . maybeIdentifier . fmap (fmap unIdentifier)
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
module Renderer.JSON
|
||||
( json
|
||||
, jsonFile
|
||||
, jsonIndexParseTree
|
||||
, indexTerm
|
||||
, ToJSONFields(..)
|
||||
, Identifier(..)
|
||||
) where
|
||||
@ -206,8 +206,8 @@ instance ToJSONFields Identifier where
|
||||
jsonFile :: ToJSON a => SourceBlob -> a -> Value
|
||||
jsonFile SourceBlob{..} = toJSON . File path
|
||||
|
||||
jsonIndexParseTree :: (ToJSONFields (Record fields), HasField fields (Maybe Identifier)) => SourceBlob -> Term (Syntax Text) (Record fields) -> Value
|
||||
jsonIndexParseTree blob = jsonFile blob . fmap (object . toJSONFields) . cata combine
|
||||
indexTerm :: (ToJSONFields (Record fields), HasField fields (Maybe Identifier)) => Term (Syntax Text) (Record fields) -> [Record fields]
|
||||
indexTerm = cata combine
|
||||
where combine (a :< f) | Nothing <- getField a :: Maybe Identifier = Prologue.concat f
|
||||
| Leaf _ <- f = Prologue.concat f
|
||||
| otherwise = a : Prologue.concat f
|
||||
|
Loading…
Reference in New Issue
Block a user