1
1
mirror of https://github.com/github/semantic.git synced 2024-12-11 08:45:48 +03:00

Don’t prefix the Dedupe fields.

This commit is contained in:
Rob Rix 2019-10-16 18:29:47 -04:00
parent c94e53adf9
commit 94099aad8f
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -12,7 +12,7 @@ module Rendering.TOC
, toCategoryName
) where
import Prologue
import Prologue hiding (index)
import Analysis.TOCSummary
import Data.Align (bicrosswalk)
import Data.Aeson
@ -83,9 +83,9 @@ tableOfContentsBy selector = fromMaybe [] . cata (\ r -> case r of
newtype DedupeKey = DedupeKey (T.Text, T.Text) deriving (Eq, Ord)
data Dedupe = Dedupe
{ dedupeIndex :: {-# UNPACK #-} !Int
, dedupeEntry :: {-# UNPACK #-} !Entry
, dedupeDecl :: {-# UNPACK #-} !Declaration
{ index :: {-# UNPACK #-} !Int
, entry :: {-# UNPACK #-} !Entry
, decl :: {-# UNPACK #-} !Declaration
}
-- Dedupe entries in a final pass. This catches two specific scenarios with
@ -96,12 +96,12 @@ data Dedupe = Dedupe
-- identifiers) are in the list.
-- Action: Combine them into a single Replaced entry.
dedupe :: [(Entry, Declaration)] -> [(Entry, Declaration)]
dedupe = map (dedupeEntry &&& dedupeDecl) . sortOn dedupeIndex . Map.elems . foldl' go Map.empty . zipWith (uncurry . Dedupe) [0..]
dedupe = map (entry &&& decl) . sortOn index . Map.elems . foldl' go Map.empty . zipWith (uncurry . Dedupe) [0..]
where
go m d@(Dedupe _ _ decl) = case findSimilar decl m of
Just (Dedupe _ _ similar)
| similar == decl -> m
| otherwise -> Map.insert (dedupeKey similar) (d { dedupeEntry = Replaced, dedupeDecl = similar }) m
| otherwise -> Map.insert (dedupeKey similar) (d { entry = Replaced, decl = similar }) m
_ -> Map.insert (dedupeKey decl) d m
findSimilar decl = Map.lookup (dedupeKey decl)