A peer-to-peer stack for code collaboration
Show call example in doc function (#610)
Merle Breitkreuz67165d6c951e
diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hsindex 008e108..6855c04 100644--- a/exe/ReferenceDoc.hs+++ b/exe/ReferenceDoc.hs@@ -102,23 +102,11 @@ lPanic (Left e) m = panic $ m <> ": " <> show elPanic (Right r) _ = rvalueDoc :: Text -> Text -> Value -> [Block]-valueDoc name docString value = case value of- Lambda args _ _ -> lambdaDoc args- LambdaRec _ args _ _ -> lambdaDoc args- _ ->- [ Header 3 nullAttr [Code nullAttr (toS name) ] ]- <> parseMarkdownBlocks docString+valueDoc name docString value =+ [ Header 3 nullAttr [Code nullAttr (toS title) ] ]+ <> parseMarkdownBlocks docStringwhere- lambdaDoc args =- let callExample = "(" <> T.intercalate " " (name : lambdaArgsDoc args) <> ")"- in [ Header 3 nullAttr [Code nullAttr (toS callExample) ] ]- <> parseMarkdownBlocks docString- lambdaArgsDoc args =- case args of- PosArgs argNames ->- map fromIdent argNames- VarArgs _ ->- pure "arg1 ..."+ title = fromMaybe name $ callExample name value-- | Generate documentation for primitive functions defined by 'replBindings'docForPrimFns :: Content -> [Block]diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex ddc3fee..bc53edb 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -18,6 +18,7 @@ import Data.Scientific (Scientific)import Data.Semigroup ((<>))import Data.Sequence (Seq(..))import qualified Data.Sequence as Seq+import qualified Data.Text as Timport Generics.Eotimport qualified GHC.Exts as GhcExtsimport qualified GHC.IO.Handle as Handle@@ -542,10 +543,26 @@ addBinding :: Ident -> Maybe Text -> Value -> Bindings m -> Bindings maddBinding i d v b = b{ bindingsEnv = Env . Map.insert i (Doc.Docd d v) . fromEnv $ bindingsEnv b }+callExample :: Text -> Value -> Maybe Text+callExample name value = case value of+ Lambda args _ _ -> Just $ lambdaDoc args+ LambdaRec _ args _ _ -> Just $ lambdaDoc args+ _ -> Nothing+ where+ lambdaDoc args = "(" <> T.intercalate " " (name : lambdaArgsDoc args) <> ")"+ lambdaArgsDoc args =+ case args of+ PosArgs argNames ->+ map fromIdent argNames+ VarArgs _ ->+ pure "arg1 ..."+lookupAtomWithDoc :: Monad m => Ident -> Lang m (Doc.Docd Value)-lookupAtomWithDoc i = get >>= \e -> case Map.lookup i . fromEnv $ bindingsEnv e of- Nothing -> throwErrorHere $ UnknownIdentifier i- Just x -> pure x+lookupAtomWithDoc i@(Ident name) = get >>= \e -> case Map.lookup i . fromEnv $ bindingsEnv e of+ Nothing -> throwErrorHere $ UnknownIdentifier i+ Just x@(Doc.Docd d_ v) -> pure (maybe x (doc d_ v) $ callExample name v)+ where+ doc d_ v t = Doc.Docd (Just (t <> maybe "" ("\n\n" <>) d_)) v-- | Lookup an atom in the environmentlookupAtom :: Monad m => Ident -> Lang m Value@@ -554,6 +571,9 @@ lookupAtom = fmap copoint . lookupAtomWithDoclookupAtomDoc :: Monad m => Ident -> Lang m (Maybe Text)lookupAtomDoc = fmap Doc.doc . lookupAtomWithDoc+missingDocMsg :: Ident -> Text+missingDocMsg i = "No documentation found for " <> fromIdent i <> "."+-- | Lookup a primop.lookupPrimop :: Monad m => Ident -> Lang m ([Value] -> Lang m Value)lookupPrimop i = get >>= \e -> case Map.lookup i $ getPrimFns $ bindingsPrimFns e ofdiff --git a/src/Radicle/Internal/Effects.hs b/src/Radicle/Internal/Effects.hsindex db632aa..a9489d7 100644--- a/src/Radicle/Internal/Effects.hs+++ b/src/Radicle/Internal/Effects.hs@@ -108,7 +108,7 @@ replPrimFns sysArgs = fromList $ allDocs $, oneArg "doc!" $ \caseAtom i -> dod <- lookupAtomDoc i- putStrS $ fromMaybe "No docs." d+ putStrS $ fromMaybe (missingDocMsg i) dpure nilv -> throwErrorHere $ TypeError "doc!" 0 TAtom v)diff --git a/src/Radicle/Internal/PrimFns.hs b/src/Radicle/Internal/PrimFns.hsindex 4249565..5aff7ab 100644--- a/src/Radicle/Internal/PrimFns.hs+++ b/src/Radicle/Internal/PrimFns.hs@@ -613,7 +613,7 @@ purePrimFns = fromList $ allDocs $, oneArg "doc" $ \caseAtom i -> do d <- lookupAtomDoc ipure . String $- fromMaybe ("No documentation found for " <> fromIdent i <> ".") d+ fromMaybe (missingDocMsg i) d_ -> throwErrorHere $ OtherError "doc: expects an atom"), ( "match-pat"