Skip to content

Commit

Permalink
Sync back from GHC
Browse files Browse the repository at this point in the history
  • Loading branch information
alanz committed Sep 10, 2024
1 parent f76ac82 commit 877c4e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Language/Haskell/GHC/ExactPrint/ExactPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ addComments sortNeeded csNew = do
cs <- getUnallocatedComments
debugM $ "addComments:cs" ++ show cs
-- We can only sort the comments if we are in the first phase,
-- were all comments have locations. If any have EpaDelta the
-- where all comments have locations. If any have EpaDelta the
-- sort will fail, so we do not try.
if sortNeeded && all noDelta (csNew ++ cs)
then putUnallocatedComments (sort (cs ++ csNew))
Expand Down Expand Up @@ -1729,7 +1729,7 @@ data HsModuleImpDecls
} deriving Data

instance ExactPrint HsModuleImpDecls where
-- Use an UnHelpfulSpan for the anchor, we are only interested in the comments
-- Use an UnhelpfulSpan for the anchor, we are only interested in the comments
getAnnotationEntry mid = mkEntry (EpaSpan (UnhelpfulSpan UnhelpfulNoLocationInfo)) [] (EpaComments (id_cs mid))
setAnnotationAnchor mid _anc _ cs = mid { id_cs = priorComments cs ++ getFollowingComments cs }
`debug` ("HsModuleImpDecls.setAnnotationAnchor:cs=" ++ showAst cs)
Expand Down
11 changes: 8 additions & 3 deletions src/Language/Haskell/GHC/ExactPrint/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,14 @@ pushDeclDP d _dp = d

-- ---------------------------------------------------------------------

-- | If we compile in haddock mode we get DocDecls, which we strip out
-- while exact printing. Make sure we do not balance any comments on
-- to them be stripping them out here already.
-- | If we compile in haddock mode, the haddock processing inserts
-- DocDecls to carry the Haddock Documentation. We ignore these in
-- exact printing, as all the comments are also available in their
-- normal location, and the haddock processing is lossy, in that it
-- does not preserve all haddock-like comments. When we balance
-- comments in a list, we migrate some to preceding or following
-- declarations in the list. We must make sure we do not move any to
-- these DocDecls, which are not printed.
balanceCommentsList :: [LHsDecl GhcPs] -> [LHsDecl GhcPs]
balanceCommentsList decls = balanceCommentsList' (filter notDocDecl decls)

Expand Down

0 comments on commit 877c4e3

Please sign in to comment.