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

Combine Declaration/DeclarationType.

This commit is contained in:
Rob Rix 2017-05-10 12:39:12 -04:00
parent f20d0464ee
commit f7e52a2934

View File

@ -6,7 +6,6 @@ module Renderer.TOC
, Summarizable(..) , Summarizable(..)
, isErrorSummary , isErrorSummary
, Declaration(..) , Declaration(..)
, DeclarationType(..)
, declaration , declaration
, declarationAlgebra , declarationAlgebra
, Entry(..) , Entry(..)
@ -66,11 +65,9 @@ data Summarizable
deriving (Eq, Show) deriving (Eq, Show)
-- | A declarations identifier and type. -- | A declarations identifier and type.
data Declaration = Declaration { declarationIdentifier :: Text, declarationType :: DeclarationType } data Declaration
deriving (Eq, Show) = MethodDeclaration { declarationIdentifier :: Text }
| FunctionDeclaration { declarationIdentifier :: Text }
-- | The type of a declaration.
data DeclarationType = MethodDeclaration | FunctionDeclaration
deriving (Eq, Show) deriving (Eq, Show)
-- | Produce the annotations of nodes representing declarations. -- | Produce the annotations of nodes representing declarations.
@ -81,12 +78,12 @@ declaration (annotation :< _) = annotation <$ (getField annotation :: Maybe Decl
-- | Compute 'Declaration's for methods and functions. -- | Compute 'Declaration's for methods and functions.
declarationAlgebra :: HasField fields Range => Source -> TermF (Syntax Text) (Record fields) (Term (Syntax Text) (Record fields), Maybe Declaration) -> Maybe Declaration declarationAlgebra :: HasField fields Range => Source -> TermF (Syntax Text) (Record fields) (Term (Syntax Text) (Record fields), Maybe Declaration) -> Maybe Declaration
declarationAlgebra source r = case tailF r of declarationAlgebra source r = case tailF r of
S.Function (identifier, _) _ _ -> Just $ Declaration (getSource identifier) FunctionDeclaration S.Function (identifier, _) _ _ -> Just $ FunctionDeclaration (getSource identifier)
S.Method _ (identifier, _) Nothing _ _ -> Just $ Declaration (getSource identifier) MethodDeclaration S.Method _ (identifier, _) Nothing _ _ -> Just $ MethodDeclaration (getSource identifier)
S.Method _ (identifier, _) (Just (receiver, _)) _ _ S.Method _ (identifier, _) (Just (receiver, _)) _ _
| S.Indexed [receiverParams] <- unwrap receiver | S.Indexed [receiverParams] <- unwrap receiver
, S.ParameterDecl (Just ty) _ <- unwrap receiverParams -> Just $ Declaration ("(" <> getSource ty <> ") " <> getSource identifier) MethodDeclaration , S.ParameterDecl (Just ty) _ <- unwrap receiverParams -> Just $ MethodDeclaration ("(" <> getSource ty <> ") " <> getSource identifier)
| otherwise -> Just $ Declaration (getSource receiver <> "." <> getSource identifier) MethodDeclaration | otherwise -> Just $ MethodDeclaration (getSource receiver <> "." <> getSource identifier)
_ -> Nothing _ -> Nothing
where getSource = toText . flip Source.slice source . byteRange . extract where getSource = toText . flip Source.slice source . byteRange . extract