1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE RankNTypes #-}
3{-# LANGUAGE RecordWildCards #-}
5-- | Diffing GHC ASTs modulo span positions.
13import BasicTypes (SourceText)
16import Ormolu.Imports (sortImports)
17import Ormolu.Parser.Result
19-- | Result of comparing two 'ParseResult's.
22 = Same -- ^ Two parse results are the same
23 | Different [SrcSpan] -- ^ Two parse results differ
25instance Semigroup Diff where
28 Different xs <> Different ys = Different (xs ++ ys)
30instance Monoid Diff where
33-- | Return 'False' if two annotated ASTs are the same modulo span
36diff :: ParseResult -> ParseResult -> Diff
37diff ParseResult { prCommentStream = cstream0
38 , prParsedSource = ps0
40 ParseResult { prCommentStream = cstream1
41 , prParsedSource = ps1
43 matchIgnoringSrcSpans cstream0 cstream1 <>
44 matchIgnoringSrcSpans ps0 ps1
46-- | Compare two values for equality disregarding differences in 'SrcSpan's
47-- and the ordering of import lists.
49matchIgnoringSrcSpans :: Data a => a -> a -> Diff
50matchIgnoringSrcSpans = genericQuery
52 genericQuery :: GenericQ (GenericQ Diff)
54 | typeOf x == typeOf y, toConstr x == toConstr y =
62 | otherwise = Different []
64 srcSpanEq :: SrcSpan -> GenericQ Diff
67 hsModuleEq :: HsModule GhcPs -> GenericQ Diff
69 case cast hs1' :: Maybe (HsModule GhcPs) of
70 Nothing -> Different []
73 hs0 { hsmodImports = sortImports (hsmodImports hs0) }
74 hs1 { hsmodImports = sortImports (hsmodImports hs1) }
76 sourceTextEq :: SourceText -> GenericQ Diff
77 sourceTextEq _ _ = Same
83 forLocated x@(L mspn _) y =
84 maybe id appendSpan (cast mspn) (genericQuery x y)
86 appendSpan :: SrcSpan -> Diff -> Diff
87 appendSpan s (Different ss) | fresh && helpful = Different (s:ss)
89 fresh = not $ any (flip isSubspanOf s) ss
90 helpful = isGoodSrcSpan s
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list