From bdec99c48e19614625765ec2f1500c6519463305 Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Sun, 12 May 2024 16:25:10 +0300 Subject: [PATCH] wip, kinda fixme cat --- .fixme-new/config | 2 ++ fixme-new/lib/Fixme/Run.hs | 16 ++++++++++++++-- fixme-new/lib/Fixme/State.hs | 19 +++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.fixme-new/config b/.fixme-new/config index 468696ee..1fae3725 100644 --- a/.fixme-new/config +++ b/.fixme-new/config @@ -27,4 +27,6 @@ fixme-file-comments "*.scm" ";" fixme-comments ";" "--" +update + diff --git a/fixme-new/lib/Fixme/Run.hs b/fixme-new/lib/Fixme/Run.hs index 77f23c0b..2f3fd06d 100644 --- a/fixme-new/lib/Fixme/Run.hs +++ b/fixme-new/lib/Fixme/Run.hs @@ -42,6 +42,7 @@ import Data.Generics.Product.Fields (field) import Lens.Micro.Platform import System.Process.Typed import Control.Monad.Trans.Cont +import Control.Monad.Trans.Maybe import System.IO qualified as IO import Streaming.Prelude qualified as S @@ -414,6 +415,18 @@ list_ a = do fixmies <- selectFixmeThin a liftIO $ LBS.putStr $ Aeson.encodePretty fixmies +cat_ :: FixmePerks m => Text -> FixmeM m () +cat_ hash = void $ flip runContT pure do + callCC \exit -> do + + mha <- lift $ selectFixmeHash hash + + ha <- ContT $ maybe1 mha (pure ()) + + fme <- lift $ selectFixme ha + + notice $ pretty fme + printEnv :: FixmePerks m => FixmeM m () printEnv = do g <- asks fixmeEnvGitDir @@ -529,8 +542,7 @@ run what = do list_ whatever ListVal [SymbolVal "cat", FixmeHashLike hash] -> do - ha <- selectFixmeHash hash - notice $ pretty ha + cat_ hash ReadFixmeStdin -> readFixmeStdin diff --git a/fixme-new/lib/Fixme/State.hs b/fixme-new/lib/Fixme/State.hs index 9a3a42d1..96cbcc6f 100644 --- a/fixme-new/lib/Fixme/State.hs +++ b/fixme-new/lib/Fixme/State.hs @@ -20,7 +20,7 @@ import Fixme.Config import HBS2.System.Dir import Data.Config.Suckless import Data.Config.Suckless.Syntax -import DBPipe.SQLite +import DBPipe.SQLite hiding (field) import Data.Aeson as Aeson import Data.HashMap.Strict qualified as HM @@ -31,6 +31,7 @@ import Data.Either import Data.List (sortBy,sortOn) import Data.Ord import Lens.Micro.Platform +import Data.Generics.Product.Fields (field) import Control.Monad.Trans.Maybe import Data.Coerce @@ -265,17 +266,19 @@ selectFixmeHash what = withState do selectFixme :: FixmePerks m => Text -> FixmeM m (Maybe Fixme) selectFixme txt = do + attrs <- selectFixmeThin (FixmeHashExactly txt) + <&> fmap coerce . headMay + <&> fromMaybe mempty runMaybeT do - self <- lift (withState $ select [qc|select blob from fixme where id = ? limit 1|] (Only txt)) - <&> listToMaybe . fmap fromOnly - >>= toMPlus - <&> (deserialiseOrFail @Fixme) - >>= toMPlus - - error "what" + lift (withState $ select [qc|select fixme from fixme where id = ? limit 1|] (Only txt)) + <&> listToMaybe . fmap fromOnly + >>= toMPlus + <&> (deserialiseOrFail @Fixme) + >>= toMPlus + <&> over (field @"fixmeAttr") (<> attrs) data Bound = forall a . (ToField a, Show a) => Bound a