From 505562126a8551bb20a21e000447013cb826df8d Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 26 Mar 2018 15:15:38 -0700 Subject: [PATCH] Fix toc summary tests now that ruby classes have their own syntax --- src/Analysis/Declaration.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Analysis/Declaration.hs b/src/Analysis/Declaration.hs index 1ac1f98f8..a6ce22980 100644 --- a/src/Analysis/Declaration.hs +++ b/src/Analysis/Declaration.hs @@ -119,6 +119,10 @@ instance CustomHasDeclaration whole Declaration.Class where customToDeclaration blob@Blob{..} ann decl@(Declaration.Class _ (Term (In identifierAnn _), _) _ _) = Just $ ClassDeclaration (getSource blobSource identifierAnn) (getClassSource blob (In ann decl)) blobLanguage +instance CustomHasDeclaration whole Ruby.Syntax.Class where + customToDeclaration blob@Blob{..} ann decl@(Ruby.Syntax.Class (Term (In identifierAnn _), _) _ _) + = Just $ ClassDeclaration (getSource blobSource identifierAnn) (getRubyClassSource blob (In ann decl)) blobLanguage + instance CustomHasDeclaration (Union fs) Declaration.Import where customToDeclaration Blob{..} _ (Declaration.Import (Term (In fromAnn _), _) symbols _) = Just $ ImportDeclaration ((stripQuotes . getSource blobSource) fromAnn) "" (fmap getSymbol symbols) blobLanguage @@ -191,6 +195,7 @@ type family DeclarationStrategy syntax where DeclarationStrategy Declaration.Import = 'Custom DeclarationStrategy Declaration.QualifiedImport = 'Custom DeclarationStrategy Declaration.SideEffectImport = 'Custom + DeclarationStrategy Ruby.Syntax.Class = 'Custom DeclarationStrategy Ruby.Syntax.Require = 'Custom DeclarationStrategy Declaration.Method = 'Custom DeclarationStrategy Markdown.Heading = 'Custom @@ -229,3 +234,10 @@ getClassSource Blob{..} (In a r) bodyRange = getField <$> case r of Declaration.Class _ _ _ (Term (In a' _), _) -> Just a' in maybe mempty (T.stripEnd . toText . flip Source.slice blobSource . subtractRange declRange) bodyRange + +getRubyClassSource :: (HasField fields Range) => Blob -> TermF Ruby.Syntax.Class (Record fields) (Term syntax (Record fields), a) -> T.Text +getRubyClassSource Blob{..} (In a r) + = let declRange = getField a + bodyRange = getField <$> case r of + Ruby.Syntax.Class _ _ (Term (In a' _), _) -> Just a' + in maybe mempty (T.stripEnd . toText . flip Source.slice blobSource . subtractRange declRange) bodyRange