@@ -33,84 +33,45 @@ module Development.IDE.GHC.ExactPrint
33
33
)
34
34
where
35
35
36
- import BasicTypes (appPrec )
37
- import Control.Applicative (Alternative )
38
- import Control.Monad
39
- import qualified Control.Monad.Fail as Fail
40
- import Control.Monad.IO.Class (MonadIO )
41
- import Control.Monad.Trans.Class
42
- import Control.Monad.Trans.Except
43
- import Control.Monad.Zip
44
- import qualified Data.DList as DL
45
- import Data.Either.Extra (mapLeft )
46
- import Data.Functor.Classes
47
- import Data.Functor.Contravariant
48
- import qualified Data.Text as T
49
- import Development.IDE.Core.RuleTypes
50
- import Development.IDE.Core.Service (runAction )
51
- import Development.IDE.Core.Shake
52
- import Development.IDE.GHC.Compat hiding (parseExpr )
53
- import Development.IDE.Types.Location
54
- import Development.Shake (RuleResult , Rules )
55
- import Development.Shake.Classes
56
- import qualified GHC.Generics as GHC
57
- import Generics.SYB
58
- import Ide.PluginUtils
59
- import Language.Haskell.GHC.ExactPrint
60
- import Language.Haskell.GHC.ExactPrint.Parsers
61
- import Language.LSP.Types
62
- import Language.LSP.Types.Capabilities (ClientCapabilities )
63
- import Outputable (Outputable , ppr ,
64
- showSDoc )
65
- -- import Retrie.ExactPrint hiding (parseDecl, parseExpr, parsePattern, parseType)
66
- import Data.Bool (bool )
67
- import Data.Foldable (Foldable (fold ))
68
- import Data.Functor.Compose (Compose (Compose ))
69
- import Data.Monoid (All (All ), Any (Any ))
70
- import Data.Traversable (for )
71
- import Language.Haskell.GHC.ExactPrint.Annotate (Annotate )
72
- import Parser (parseIdentifier )
36
+ import BasicTypes (appPrec )
37
+ import Control.Applicative (Alternative )
38
+ import Control.Monad
39
+ import qualified Control.Monad.Fail as Fail
40
+ import Control.Monad.IO.Class (MonadIO )
41
+ import Control.Monad.Trans.Class
42
+ import Control.Monad.Trans.Except
43
+ import Control.Monad.Zip
44
+ import qualified Data.DList as DL
45
+ import Data.Either.Extra (mapLeft )
46
+ import Data.Functor.Classes
47
+ import Data.Functor.Contravariant
48
+ import qualified Data.Text as T
49
+ import Development.IDE.Core.RuleTypes
50
+ import Development.IDE.Core.Service (runAction )
51
+ import Development.IDE.Core.Shake
52
+ import Development.IDE.GHC.Compat hiding (parseExpr )
53
+ import Development.IDE.Types.Location
54
+ import Development.Shake (RuleResult , Rules )
55
+ import Development.Shake.Classes
56
+ import qualified GHC.Generics as GHC
57
+ import Generics.SYB
58
+ import Ide.PluginUtils
59
+ import Language.Haskell.GHC.ExactPrint
60
+ import Language.Haskell.GHC.ExactPrint.Parsers
61
+ import Language.LSP.Types
62
+ import Language.LSP.Types.Capabilities (ClientCapabilities )
63
+ import Outputable (Outputable , ppr , showSDoc )
64
+ import Retrie.ExactPrint hiding (parseDecl , parseExpr , parsePattern , parseType )
65
+ import Parser (parseIdentifier )
66
+ import Data.Traversable (for )
67
+ import Data.Foldable (Foldable (fold ))
68
+ import Data.Bool (bool )
69
+ import Data.Monoid (All (All ), Any (Any ))
70
+ import Data.Functor.Compose (Compose (Compose ))
73
71
#if __GLASGOW_HASKELL__ == 808
74
- import Control.Arrow
72
+ import Control.Arrow
75
73
#endif
76
74
77
- import Control.DeepSeq (rwhnf )
78
-
79
- -- Start stolen from retrie and not compatible with retrie
80
-
81
- -- | 'Annotated' packages an AST fragment with the annotations necessary to
82
- -- 'exactPrint' or 'transform' that AST.
83
- data Annotated ast = Annotated
84
- { astA :: ast
85
- -- ^ Examine the actual AST.
86
- , annsA :: Anns
87
- -- ^ Annotations generated/consumed by ghc-exactprint
88
- , seedA :: Int
89
- -- ^ Name supply used by ghc-exactprint to generate unique locations.
90
- }
91
- deriving (Show )
92
-
93
- -- | Construct an 'Annotated'.
94
- -- This should really only be used in the parsing functions, hence the scary name.
95
- -- Don't use this unless you know what you are doing.
96
- unsafeMkA :: ast -> Anns -> Int -> Annotated ast
97
- unsafeMkA = Annotated
98
-
99
- -- | Exactprint an 'Annotated' thing.
100
- printA :: Annotate ast => Annotated (Located ast ) -> String
101
- printA (Annotated ast anns _) = exactPrint ast anns
102
-
103
- -- | Transform an 'Annotated' thing.
104
- transformA
105
- :: Monad m => Annotated ast1 -> (ast1 -> TransformT m ast2 ) -> m (Annotated ast2 )
106
- transformA (Annotated ast anns seed) f = do
107
- (ast',(anns',seed'),_) <- runTransformFromT seed anns (f ast)
108
- return $ Annotated ast' anns' seed'
109
-
110
- instance NFData (Annotated a ) where
111
- rnf = rwhnf
112
-
113
- -- End stolen from retrie and not compatible with retrie
114
75
115
76
------------------------------------------------------------------------------
116
77
@@ -272,7 +233,7 @@ graft' needs_space dst val = Graft $ \dflags a -> do
272
233
( mkT $
273
234
\ case
274
235
(L src _ :: Located ast ) | src == dst -> val'
275
- l -> l
236
+ l -> l
276
237
)
277
238
a
278
239
@@ -578,7 +539,7 @@ smallestM q f = fmap snd . go
578
539
Just True -> do
579
540
it@ (r, x') <- gmapMQ go x
580
541
case r of
581
- Any True -> pure it
542
+ Any True -> pure it
582
543
Any False -> fmap (Any True ,) $ f x'
583
544
Just False -> pure (mempty , x)
584
545
@@ -598,9 +559,9 @@ largestM q f = go
598
559
go :: GenericM m
599
560
go x = do
600
561
case q x of
601
- Just True -> f x
562
+ Just True -> f x
602
563
Just False -> pure x
603
- Nothing -> gmapM go x
564
+ Nothing -> gmapM go x
604
565
605
566
newtype MonadicQuery r m a = MonadicQuery
606
567
{ runMonadicQuery :: m (r , a )
0 commit comments