diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-05 09:46:55 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-05 09:46:55 +0200 |
commit | 1890844c731b4c5c648b1871193947144aefa3dd (patch) | |
tree | d4d44e7369d039d3b18e91b9696004a51a01ea87 /app/Issue.hs | |
parent | ed2a9d64f07656956b76442ed91b41981b912a60 (diff) |
refactor issue text extraction
Diffstat (limited to 'app/Issue.hs')
-rw-r--r-- | app/Issue.hs | 55 |
1 files changed, 10 insertions, 45 deletions
diff --git a/app/Issue.hs b/app/Issue.hs index 0d9f6ad..249ce92 100644 --- a/app/Issue.hs +++ b/app/Issue.hs @@ -5,13 +5,11 @@ module Issue (Issue (..), fromMatch) where -import Data.List (find) -import Data.Maybe (fromMaybe) import Data.Text (Text) import Data.Text qualified as T import Issue.Tag (Tag) import Issue.Tag qualified as I -import TreeGrepper.FileType qualified as G +import Issue.Text qualified as I import TreeGrepper.Match (Match (..)) import TreeGrepper.Match qualified as G import TreeGrepper.Result (Result (..)) @@ -19,7 +17,7 @@ import TreeGrepper.Result qualified as G data Issue = Issue { title :: Text, - description :: Text, + description :: Maybe Text, start :: G.Position, end :: G.Position, tags :: [Tag] @@ -27,59 +25,26 @@ data Issue = Issue fromMatch :: G.Result -> G.Match -> Maybe Issue fromMatch result match = - if T.isPrefixOf marker (T.unlines (take 1 lns)) + if T.isPrefixOf marker title then Just Issue - { title = stripMarker (T.strip (T.unlines title)), - description = stripTags (T.strip (T.unlines description)), + { title = stripMarker title, + description = stripTags <$> description, start = match.start, end = match.end, - tags = I.extract text + tags = maybe [] I.extract description } else Nothing where - text = stripComments result.file_type (T.strip match.text) - lns = T.lines text - title = takeWhile (not . isEmpty) lns - description = drop (length title + 1) lns - isEmpty = T.null . T.strip + (title, description) = I.extractText result.file_type match.text marker :: Text marker = "TODO" -stripTags :: Text -> Text -stripTags text = - T.strip (T.unlines (filter (not . T.isPrefixOf "@") (T.lines text))) - stripMarker :: Text -> Text stripMarker text = maybe text T.stripStart (T.stripPrefix marker text) -stripComments :: G.FileType -> Text -> Text -stripComments fileType text = - maybe - (stripLineComments (G.info fileType).lineStart text) - ( \(blockInfo, blockStart) -> - stripBlockComment blockStart blockInfo.blockEnd text - ) - $ do - blockInfo <- (G.info fileType).block - (,) blockInfo <$> find (`T.isPrefixOf` text) blockInfo.blockStart - -stripLineComments :: Text -> Text -> Text -stripLineComments lineStart text = - onLines - ( \line -> - fromMaybe line . fmap T.stripStart $ - T.stripPrefix lineStart line - ) - text - where - onLines f = T.unlines . map f . T.lines - -stripBlockComment :: Text -> Text -> Text -> Text -stripBlockComment blockStart blockEnd text = - T.strip - . (fromMaybe text . T.stripSuffix blockEnd) - . (fromMaybe text . T.stripPrefix blockStart) - $ text +stripTags :: Text -> Text +stripTags text = + T.strip (T.unlines (filter (not . T.isPrefixOf "@") (T.lines text))) |