1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Replace the indexing renderer with an indexing operation.

This commit is contained in:
Rob Rix 2017-04-27 19:40:54 -04:00
parent 6ed683f9be
commit 4334e24aa4
2 changed files with 6 additions and 6 deletions

View File

@ -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)

View File

@ -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