@@ -20,7 +20,12 @@ import CabalDocspec.Trace
2020import CabalDocspec.Warning
2121
2222-- | Handle to GHCi process.
23- newtype GHCi = GHCi Proci. IPH
23+ data GHCi = GHCi ! Proci. IPH ! MarkerType
24+
25+ data MarkerType
26+ = MT_DSS -- ^ @Data.String.String@
27+ | MT_Char -- ^ @[Char]@
28+ -- | MT_None -- this an option too, not configurable atm.
2429
2530-- | Run interactive GHCi
2631withInteractiveGhc
@@ -34,7 +39,14 @@ withInteractiveGhc tracer ghcInfo cwd args kont = do
3439 traceApp tracer $ TraceGHCi (ghcPath ghcInfo) args'
3540
3641 Proci. withInteractiveProcess pc1 $ \ iph -> do
37- let ghci = GHCi iph
42+ let mt :: MarkerType
43+ mt | ghcVersion ghcInfo >= mkVersion [7 ,2 ]
44+ = MT_DSS
45+
46+ | otherwise
47+ = MT_Char
48+
49+ let ghci = GHCi iph mt
3850 setupGhci tracer ghcInfo ghci
3951 kont ghci
4052 where
@@ -43,15 +55,19 @@ withInteractiveGhc tracer ghcInfo cwd args kont = do
4355 { Proc. cwd = Just (toFilePath cwd)
4456 }
4557
46- args' = [" --interactive" , " -ignore-dot-ghci" ] ++ args
58+ args' = [" --interactive" , " -ignore-dot-ghci" , " -v0 " ] ++ args
4759
4860setupGhci :: TracerPeu r Tr -> GhcInfo -> GHCi -> Peu r ()
49- setupGhci tracer _ghcInfo ghci@ (GHCi iph) = do
61+ setupGhci tracer _ghcInfo ghci@ (GHCi iph _mt ) = do
5062 -- turn off prompt
5163 -- it is fine to send these, even if they may not work.
52- Proci. sendTo iph " :set prompt \"\"\n "
53- Proci. sendTo iph " :set prompt2 \"\"\n " -- GHC-7.8+
54- Proci. sendTo iph " :set prompt-cont \"\"\n " -- GHC-8.2+
64+
65+ -- Proci.sendTo iph ":set prompt \"\"\n"
66+ -- Proci.sendTo iph ":set prompt2 \"\"\n" -- GHC-7.8+
67+ -- Proci.sendTo iph ":set prompt-cont \"\"\n" -- GHC-8.2+
68+
69+ -- We don't actually need these, as -v0 argument suppresses prompt echo when terminal is not tty!
70+ -- https://gitlab.haskell.org/ghc/ghc/-/blob/cbc7c3dda6bdf4acb760ca9eb545faeb98ab0dbe/ghc/GHCi/UI.hs#L688-691
5571
5672 -- wait a little. I'm not sure if we need this delay
5773 liftIO $ threadDelay 10000
@@ -80,10 +96,15 @@ data Result
8096 | Timeout
8197
8298waitGhci :: TracerPeu r Tr -> GHCi -> Maybe String -> Int -> Peu r Result
83- waitGhci _tracer (GHCi iph) mitVar microsecs = do
99+ waitGhci _tracer (GHCi iph mt) mitVar microsecs = do
100+ let mt' :: String
101+ mt' = case mt of
102+ MT_DSS -> " Data.String.String" -- works for most
103+ MT_Char -> " [Char]" -- works for GHC-7.0
104+
84105 -- send separator
85106 separator <- show <$> genString
86- Proci. sendTo iph $ fromString $ separator ++ " :: Data.String.String \n "
107+ Proci. sendTo iph $ fromString $ separator ++ " :: " ++ mt' ++ " \n "
87108
88109 for_ mitVar $ \ itVar -> do
89110 Proci. sendTo iph $ fromString $ " let it = " ++ itVar ++ " \n "
@@ -120,7 +141,7 @@ waitGhci _tracer (GHCi iph) mitVar microsecs = do
120141-- | Send expressions (individual lines)
121142-- wait for combined response.
122143sendExpressions :: TracerPeu r Tr -> GHCi -> Bool -> Int -> [String ] -> Peu r Result
123- sendExpressions tracer ghci@ (GHCi iph) preserveIt timeout exprs = do
144+ sendExpressions tracer ghci@ (GHCi iph _mt ) preserveIt timeout exprs = do
124145 -- send expressions
125146 for_ exprs $ \ expr -> do
126147 Proci. sendTo iph (toUTF8BS expr <> " \n " )
0 commit comments