1
1
{-# LANGUAGE CPP #-}
2
2
{-# LANGUAGE LambdaCase #-}
3
3
{-# LANGUAGE PatternSynonyms #-}
4
- {-# LANGUAGE RecordWildCards #-}
5
4
6
- -- To avoid warning "Pattern match has inaccessible right hand side"
7
- {-# OPTIONS_GHC -Wno-overlapping -patterns #-}
8
5
module Ide.Plugin.Eval.Rules (GetEvalComments (.. ), rules ,queueForEvaluation , unqueueForEvaluation , Log ) where
9
6
7
+ import Control.Lens (toListOf )
10
8
import Control.Monad.IO.Class (MonadIO (liftIO ))
9
+ import qualified Data.ByteString as BS
10
+ import Data.Data.Lens (biplate )
11
11
import Data.HashSet (HashSet )
12
12
import qualified Data.HashSet as Set
13
13
import Data.IORef
@@ -24,8 +24,7 @@ import Development.IDE (GetModSummaryWithoutTimes
24
24
fromNormalizedFilePath ,
25
25
msrModSummary ,
26
26
realSrcSpanToRange ,
27
- useWithStale_ ,
28
- use_ )
27
+ useWithStale_ , use_ )
29
28
import Development.IDE.Core.PositionMapping (toCurrentRange )
30
29
import Development.IDE.Core.Rules (computeLinkableTypeForDynFlags ,
31
30
needsCompilationRule )
@@ -39,14 +38,12 @@ import Development.IDE.GHC.Compat
39
38
import qualified Development.IDE.GHC.Compat as SrcLoc
40
39
import qualified Development.IDE.GHC.Compat.Util as FastString
41
40
import Development.IDE.Graph (alwaysRerun )
42
- import Ide.Logger (Pretty (pretty ),
41
+ import GHC.Parser.Annotation
42
+ import Ide.Logger (Pretty (pretty ),
43
43
Recorder , WithPriority ,
44
44
cmapWithPrio )
45
- import GHC.Parser.Annotation
46
45
import Ide.Plugin.Eval.Types
47
46
48
- import qualified Data.ByteString as BS
49
-
50
47
newtype Log = LogShake Shake. Log deriving Show
51
48
52
49
instance Pretty Log where
@@ -74,28 +71,17 @@ unqueueForEvaluation ide nfp = do
74
71
-- remove the module from the Evaluating state, so that next time it won't evaluate to True
75
72
atomicModifyIORef' var $ \ fs -> (Set. delete nfp fs, () )
76
73
77
- #if MIN_VERSION_ghc(9,5,0)
78
- getAnnotations :: Development.IDE.GHC.Compat. Located (HsModule GhcPs ) -> [LEpaComment ]
79
- getAnnotations (L _ m@ (HsModule { hsmodExt = XModulePs {hsmodAnn = anns'}})) =
80
- #else
81
- getAnnotations :: Development.IDE.GHC.Compat. Located HsModule -> [LEpaComment ]
82
- getAnnotations (L _ m@ (HsModule { hsmodAnn = anns'})) =
83
- #endif
84
- priorComments annComments <> getFollowingComments annComments
85
- <> concatMap getCommentsForDecl (hsmodImports m)
86
- <> concatMap getCommentsForDecl (hsmodDecls m)
87
- where
88
- annComments = epAnnComments anns'
89
-
90
- getCommentsForDecl :: GenLocated (SrcSpanAnn' (EpAnn ann )) e
91
- -> [LEpaComment ]
92
- getCommentsForDecl (L (SrcSpanAnn (EpAnn _ _ cs) _) _) = priorComments cs <> getFollowingComments cs
93
- getCommentsForDecl (L (SrcSpanAnn (EpAnnNotUsed ) _) _) = []
94
-
95
74
apiAnnComments' :: ParsedModule -> [SrcLoc. RealLocated EpaCommentTok ]
96
75
apiAnnComments' pm = do
97
- L span (EpaComment c _) <- getAnnotations $ pm_parsed_source pm
76
+ L span (EpaComment c _) <- getEpaComments $ pm_parsed_source pm
98
77
pure (L (anchor span ) c)
78
+ where
79
+ #if MIN_VERSION_ghc(9,5,0)
80
+ getEpaComments :: Development.IDE.GHC.Compat. Located (HsModule GhcPs ) -> [LEpaComment ]
81
+ #else
82
+ getEpaComments :: Development.IDE.GHC.Compat. Located HsModule -> [LEpaComment ]
83
+ #endif
84
+ getEpaComments = toListOf biplate
99
85
100
86
pattern RealSrcSpanAlready :: SrcLoc. RealSrcSpan -> SrcLoc. RealSrcSpan
101
87
pattern RealSrcSpanAlready x = x
0 commit comments