Fix endOfFile placement bug when there are multiline comments

pull/3/head
Lennart Spitzner 2016-08-12 12:32:01 +02:00
parent 39e565c182
commit bc09b21473
1 changed files with 7 additions and 1 deletions

View File

@ -41,6 +41,7 @@ import ApiAnnotation ( AnnKeywordId(..) )
import RdrName ( RdrName(..) ) import RdrName ( RdrName(..) )
import GHC ( runGhc, GenLocated(L), moduleNameString ) import GHC ( runGhc, GenLocated(L), moduleNameString )
import SrcLoc ( SrcSpan ) import SrcLoc ( SrcSpan )
import qualified SrcLoc as GHC
import HsSyn import HsSyn
import Data.HList.HList import Data.HList.HList
@ -170,7 +171,12 @@ ppModule lmod@(L loc m@(HsModule _name _exports _imports decls _ _)) = do
ppmMoveToExactLoc l ppmMoveToExactLoc l
mTell $ Text.Builder.fromString cmStr mTell $ Text.Builder.fromString cmStr
(ExactPrint.Types.G AnnEofPos, (ExactPrint.Types.DP (eofX,eofY))) -> (ExactPrint.Types.G AnnEofPos, (ExactPrint.Types.DP (eofX,eofY))) ->
let cmX = foldl' (\acc (_, ExactPrint.Types.DP (x, _)) -> acc+x) 0 finalComments let folder acc (kw, ExactPrint.Types.DP (x, _)) = case kw of
ExactPrint.Types.AnnComment cm
| GHC.RealSrcSpan span <- ExactPrint.Types.commentIdentifier cm
-> acc + x + GHC.srcSpanEndLine span - GHC.srcSpanStartLine span
_ -> acc + x
cmX = foldl' folder 0 finalComments
in ppmMoveToExactLoc $ ExactPrint.Types.DP (eofX - cmX, eofY) in ppmMoveToExactLoc $ ExactPrint.Types.DP (eofX - cmX, eofY)
_ -> return () _ -> return ()