diff options
Diffstat (limited to 'app/Comment.hs')
-rw-r--r-- | app/Comment.hs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/app/Comment.hs b/app/Comment.hs index 2769c83..123acec 100644 --- a/app/Comment.hs +++ b/app/Comment.hs @@ -9,7 +9,7 @@ module Comment ) where -import Comment.Language +import Comment.Language qualified as L import Control.Applicative (liftA2) import Control.Exception (catch) import Data.Binary (Binary) @@ -32,7 +32,7 @@ import TreeSitter qualified as S data Comment = Comment { text :: T.Text, - language :: Language, + language :: L.Language, startByte :: Int, endByte :: Int, startPoint :: Point, @@ -50,12 +50,20 @@ data Point = Point getComments :: Git.CommitHash -> FilePath -> IO [Comment] getComments commitHash filePath = fmap mergeLineComments - . (extractComments filePath language . LB.toStrict) + . ( extractComments + filePath + ( -- TODO Support amiguous file languages + -- + -- @backlog + N.head language + ) + . LB.toStrict + ) =<< catch (Git.readTextFileOfBS commitHash filePath) (\(_ :: E.CannotReadFile) -> pure "") where - language = fromExtension (takeExtension filePath) + language = L.fromPath (takeExtension filePath) mergeLineComments :: [Comment] -> [Comment] mergeLineComments = @@ -86,13 +94,13 @@ getComments commitHash filePath = | p a x = go ((x N.:| a : as) : rs) xs | otherwise = go (N.singleton x : ass) xs -extractComments :: FilePath -> Language -> B.ByteString -> IO [Comment] +extractComments :: FilePath -> L.Language -> B.ByteString -> IO [Comment] extractComments filePath language str' = alloca $ \nodesPtrPtr -> do alloca $ \numNodesPtr -> do B.useAsCString str' $ \str -> S.extract_comments - (parser language) + (L.parser language) str nodesPtrPtr numNodesPtr @@ -135,11 +143,11 @@ comment :: CommentStyle -> T.Text -> T.Text comment (LineStyle linePrefix) = T.unlines . map ((linePrefix <> " ") <>) . T.lines comment (BlockStyle blockStart blockEnd) = (blockStart <>) . (<> blockEnd) -uncomment :: Language -> T.Text -> (CommentStyle, T.Text) +uncomment :: L.Language -> T.Text -> (CommentStyle, T.Text) uncomment language rawText = maybe - ( ( LineStyle (lineStart language), - stripLineComments (lineStart language) text + ( ( LineStyle (L.lineStart language), + stripLineComments (L.lineStart language) text ) ) ( \(blockStart, blockEnd) -> @@ -148,7 +156,7 @@ uncomment language rawText = ) ) $ do - (blockStarts, blockEnd) <- block language + (blockStarts, blockEnd) <- L.block language (,blockEnd) <$> find (`T.isPrefixOf` text) blockStarts where text = stripLines rawText |