Skip to content

Commit

Permalink
All tests pass except AddLocalDecl5
Browse files Browse the repository at this point in the history
And the problem has to do with the indent after the new where clause.
It works fine for no comment.  The LayoutOffset is being used, where
it should not
  • Loading branch information
alanz committed Dec 18, 2024
1 parent c145a7e commit 1ef4d88
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
23 changes: 2 additions & 21 deletions src/Language/Haskell/GHC/ExactPrint/ExactPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ enterAnn !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
let dp = if pos == prior
then (DifferentLine 1 0)
else adjustDeltaForOffset off (origDelta pos prior)
debugM $ "EOF:(pos,posEnd,prior,dp) =" ++ showGhc (ss2pos pos, ss2posEnd pos, ss2pos prior, dp)
debugM $ "EOF:(pos,posend,prior,off,dp) =" ++ show (ss2pos pos, ss2posEnd pos, ss2pos prior, off, dp)
printStringAtLsDelta dp ""
setEofPos Nothing -- Only do this once

Expand Down Expand Up @@ -550,8 +550,8 @@ enterAnn !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
return after
else return []
!trailing' <- markTrailing trailing_anns
-- mapM_ printOneComment (concatMap tokComment $ following)
addCommentsA following
debugM $ "enterAnn:done:(anchor,priorCs,postCs) =" ++ show (showAst anchor', priorCs, postCs)

-- Update original anchor, comments based on the printing process
-- TODO:AZ: probably need to put something appropriate in instead of noSrcSpan
Expand Down Expand Up @@ -1408,28 +1408,9 @@ updateAndApplyComment :: (Monad m, Monoid w) => Comment -> DeltaPos -> EP w m ()
updateAndApplyComment (Comment str anc pp mo) dp = do
applyComment (Comment str anc' pp mo)
where
(r,c) = ss2posEnd pp
dp'' = case anc of
EpaDelta _ dp1 _ -> dp1
EpaSpan (RealSrcSpan la _) ->
if r == 0
then (ss2delta (r,c+0) la)
else (ss2delta (r,c) la)
EpaSpan (UnhelpfulSpan _) -> SameLine 0
dp' = case anc of
EpaSpan (RealSrcSpan r1 _) ->
if pp == r1
then dp
else dp''
_ -> dp''
ss = case anc of
EpaSpan ss' -> ss'
_ -> noSrcSpan
op' = case dp' of
SameLine n -> if n >= 0
then EpaDelta ss dp' NoComments
else EpaDelta ss dp NoComments
_ -> EpaDelta ss dp' NoComments
anc' = EpaDelta ss dp NoComments
-- ---------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions src/Language/Haskell/GHC/ExactPrint/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,17 @@ isPointSrcSpan ss = spanLength ss == 0
-- does not already have one.
commentOrigDelta :: LEpaComment -> LEpaComment
commentOrigDelta (L (EpaSpan ss@(RealSrcSpan la _)) (GHC.EpaComment t pp))
= (L (EpaDelta ss dp NoComments) (GHC.EpaComment t pp))
`debug` ("commentOrigDelta: (la, pp, r,c, dp)=" ++ showAst (la, pp, r,c, dp))
= (L (EpaDelta ss dp' NoComments) (GHC.EpaComment t pp))
`debug` ("commentOrigDelta: (la, pp, r,c, dp, dp')=" ++ showAst (la, pp, r,c, dp, dp'))
where
(r,c) = ss2posEnd pp

dp = if r == 0
then (ss2delta (r,c+1) la)
else (ss2delta (r,c) la)
dp' = case dp of
SameLine _ -> dp
DifferentLine l cc -> DifferentLine l (cc - 1)
commentOrigDelta c = c

origDelta :: RealSrcSpan -> RealSrcSpan -> DeltaPos
Expand Down
5 changes: 2 additions & 3 deletions tests/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ testDirs =
main :: IO ()
main = hSilence [stderr] $ do
print ghcVersion
cwd <- getCurrentDirectory
putStrLn $ "cwd:" ++ show cwd
tests <- mkTests
cnts <- fst <$> runTestText (putTextToHandle stdout True) tests
putStrLn $ show cnts
Expand Down Expand Up @@ -214,7 +212,8 @@ tt' = do

-- mkParserTest libdir "ghc912" "Module.hs"
-- mkParserTest libdir "ghc912" "tests.hs"
mkParserTestMD libdir "ghc912" "Fff.hs"
-- mkParserTestMD libdir "ghc912" "Fff.hs"
mkParserTestMD libdir "transform" "AddLocalDecl5.hs"
-- mkParserTestMD libdir "ghc912" "Module.hs"
-- mkParserTestMD libdir "ghc912" "Operator.hs"
-- Needs GHC changes
Expand Down
4 changes: 2 additions & 2 deletions tests/Test/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ addLocaLDecl4 libdir lp = do
addLocaLDecl5 :: Changer
addLocaLDecl5 _libdir lp = do
let
doAddLocal = replaceDecls lp [s1,de1',d3']
doAddLocal = replaceDecls lp (s1:de1':d3':ds)
where
decls = hsDecls lp
[s1,de1,d2,d3] = balanceCommentsList decls
(s1:de1:d2:d3:ds) = balanceCommentsList decls

d3' = setEntryDP d3 (DifferentLine 2 0)

Expand Down

0 comments on commit 1ef4d88

Please sign in to comment.