diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-12-13 03:47:14 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-12-13 04:50:01 +0100 |
commit | 2bbd2f8b692dd952903a9f1527f2779a916118ab (patch) | |
tree | 0ab292e196327f719a2e953bdaac70cf3be9abb5 /app/Comment.hs | |
parent | 4426863f07901f626a537f2f0bb717b1bd1b0f6d (diff) |
chore: uncache large issue fields
Diffstat (limited to 'app/Comment.hs')
-rw-r--r-- | app/Comment.hs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/app/Comment.hs b/app/Comment.hs index 5d1c1ef..c834509 100644 --- a/app/Comment.hs +++ b/app/Comment.hs @@ -15,13 +15,13 @@ import Control.Exception (catch) import Control.Monad import Data.Binary (Binary) import Data.ByteString qualified as B +import Data.ByteString.Lazy qualified as LB import Data.List (find, sortBy) import Data.List.NonEmpty qualified as N import Data.Maybe (fromMaybe) import Data.Ord (comparing) import Data.Text qualified as T import Data.Text.Encoding qualified as T -import Data.Text.Lazy qualified as LT import Exception qualified as E import Foreign.C.String import Foreign.Marshal.Alloc (malloc) @@ -29,6 +29,7 @@ import Foreign.Marshal.Array (mallocArray, peekArray) import Foreign.Ptr (nullPtr) import Foreign.Storable import GHC.Generics (Generic) +import GHC.Int (Int64) import Git qualified import System.FilePath (takeExtension) import TreeSitter.Node qualified as S @@ -38,8 +39,8 @@ import TreeSitter.Tree qualified as S data Comment = Comment { text :: T.Text, language :: Language, - start :: Int, - end :: Int, + startByte :: Int64, + endByte :: Int64, startPoint :: Point, endPoint :: Point, filePath :: FilePath @@ -55,10 +56,9 @@ data Point = Point getComments :: Git.CommitHash -> FilePath -> IO [Comment] getComments commitHash filePath = fmap mergeLineComments - . extractComments filePath language - . (T.encodeUtf8 . LT.toStrict) + . (extractComments filePath language . LB.toStrict) =<< catch - (Git.readTextFileOf commitHash filePath) + (Git.readTextFileOfBS commitHash filePath) (\(_ :: E.CannotReadFile) -> pure "") where language = fromExtension (takeExtension filePath) @@ -67,14 +67,14 @@ getComments commitHash filePath = mergeLineComments = map mergeGroup . chainsBy (\a b -> a.endPoint.row + 1 == b.startPoint.row) - . sortBy (comparing (liftA2 (,) (.start) (.end))) + . sortBy (comparing (liftA2 (,) (.startByte) (.endByte))) mergeGroup :: N.NonEmpty Comment -> Comment mergeGroup css@(c N.:| cs) = c { text = T.unlines (map (.text) (c : cs)), - start = first.start, - end = last.end, + startByte = first.startByte, + endByte = last.endByte, startPoint = first.startPoint, endPoint = last.endPoint } @@ -100,9 +100,13 @@ extractComments filePath language str' = do S.withRootNode tree $ \node -> do map ( \n' -> - let start = fromIntegral $ S.nodeStartByte n' - end = fromIntegral $ S.nodeEndByte n' - text = T.decodeUtf8 . B.take (end - start) . B.drop start $ str' + let startByte = fromIntegral $ S.nodeStartByte n' + endByte = fromIntegral $ S.nodeEndByte n' + text = + T.decodeUtf8 + . B.take (fromIntegral endByte - fromIntegral startByte) + . B.drop (fromIntegral startByte) + $ str' startPoint = fromTSPoint (S.nodeStartPoint n') endPoint = fromTSPoint (S.nodeEndPoint n') |