From 739c0d06b63bed7619b39eb189c5e5a34fd8da49 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Tue, 28 Nov 2023 13:06:48 +0100 Subject: editing issues preserves comment style --- app/Issue.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'app/Issue.hs') diff --git a/app/Issue.hs b/app/Issue.hs index 411e910..73122ef 100644 --- a/app/Issue.hs +++ b/app/Issue.hs @@ -16,6 +16,7 @@ import GHC.Generics (Generic) import GHC.Records (HasField (..)) import Issue.Provenance (Author (..), Commit (..), Provenance (..)) import Issue.Tag (Tag (..)) +import TreeGrepper.Comment qualified as G import TreeGrepper.Match qualified as G import Prelude hiding (id) @@ -28,7 +29,8 @@ data Issue = Issue end :: G.Position, tags :: [Tag], markers :: [T.Text], - rawText :: T.Text + rawText :: T.Text, + commentStyle :: G.CommentStyle } deriving (Show, Binary, Generic, Eq) @@ -58,13 +60,10 @@ toSpinalCase = T.replace " " "-" . T.filter keep . T.toLower where keep = (`elem` (concat [[' ', '-'], ['a' .. 'z'], ['0' .. '9']])) --- TODO `replaceFile` hardcodes comment --- --- @difficulty easy replaceText :: Issue -> T.Text -> IO () replaceText issue s' = T.writeFile issue.file . replace (indent (comment s')) =<< T.readFile issue.file where - comment = T.intercalate "\n" . map T.strip . map ("-- " <>) . T.lines + comment = T.intercalate "\n" . map T.strip . T.lines . G.comment issue.commentStyle indent = T.intercalate "\n" . mapButFirst (T.replicate (issue.start.column - 1) " " <>) . T.lines replace s t = before <> s <> after where -- cgit v1.2.3