@@ -5,28 +5,17 @@ import Control.Monad (void)
5
5
import Control.Monad.IO.Class (liftIO )
6
6
import Control.Monad.Trans.Class (lift )
7
7
import Control.Monad.Trans.Maybe (MaybeT (MaybeT ), runMaybeT )
8
+ import Data.Default
8
9
import Data.Foldable (toList )
9
- import Data.Hashable (Hashable )
10
10
import qualified Data.HashMap.Strict as HM
11
+ import Data.Hashable (Hashable )
11
12
import qualified Data.Map as Map
12
13
import Data.Maybe (fromJust , mapMaybe )
13
14
import qualified Data.Text as T
14
- import Development.IDE (Action , FileDiagnostic ,
15
- GetHieAst (.. ),
16
- GetModSummaryWithoutTimestamps (.. ),
17
- GhcSession (.. ), IdeState ,
18
- NormalizedFilePath ,
19
- Pretty (.. ), Recorder ,
20
- RuleResult , Rules ,
21
- ShowDiagnostic (.. ),
22
- TypeCheck (.. ), WithPriority ,
23
- action , cmapWithPrio , define ,
24
- getFilesOfInterestUntracked ,
25
- hscEnv , msrModSummary ,
26
- tmrTypechecked , use , uses )
15
+ import Development.IDE
16
+ import Development.IDE.Core.RuleTypes (HieAstResult (.. ))
27
17
import Development.IDE.Core.Rules (getHieFile ,
28
18
getSourceFileSource )
29
- import Development.IDE.Core.RuleTypes (HieAstResult (.. ))
30
19
import qualified Development.IDE.Core.Shake as Shake
31
20
import Development.IDE.GHC.Compat (HieASTs (HieASTs ),
32
21
RealSrcSpan (.. ), mkHieFile' ,
@@ -38,9 +27,11 @@ import Development.IDE.GHC.Compat (HieASTs (HieASTs),
38
27
import Development.IDE.GHC.Error (realSrcSpanToRange )
39
28
import GHC.Generics (Generic )
40
29
import HieTypes (HieASTs , HieFile )
30
+ import Ide.Plugin.Config
41
31
import Ide.Types (PluginDescriptor (.. ),
42
32
PluginId ,
43
- defaultPluginDescriptor )
33
+ defaultPluginDescriptor ,
34
+ pluginEnabledConfig )
44
35
import qualified Language.LSP.Types as LSP
45
36
import Stan.Analysis (Analysis (.. ), runAnalysis )
46
37
import Stan.Category (Category (.. ))
@@ -50,7 +41,8 @@ import Stan.Inspection.All (inspectionsIds, inspectionsMap)
50
41
import Stan.Observation (Observation (.. ))
51
42
52
43
descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
53
- descriptor recorder plId = (defaultPluginDescriptor plId) {pluginRules = rules recorder}
44
+ descriptor recorder plId = (defaultPluginDescriptor plId)
45
+ {pluginRules = rules recorder plId}
54
46
55
47
newtype Log = LogShake Shake. Log deriving (Show )
56
48
@@ -67,18 +59,21 @@ instance NFData GetStanDiagnostics
67
59
68
60
type instance RuleResult GetStanDiagnostics = ()
69
61
70
- rules :: Recorder (WithPriority Log ) -> Rules ()
71
- rules recorder = do
62
+ rules :: Recorder (WithPriority Log ) -> PluginId -> Rules ()
63
+ rules recorder plId = do
72
64
define (cmapWithPrio LogShake recorder) $
73
65
\ GetStanDiagnostics file -> do
74
- maybeHie <- getHieFile file
75
- case maybeHie of
76
- Nothing -> return ([] , Nothing )
77
- Just hie -> do
78
- let enabledInspections = HM. fromList [(LSP. fromNormalizedFilePath file, inspectionsIds)]
79
- -- This should use Cabal config for extensions and Stan config for inspection preferences is the future
80
- let analysis = runAnalysis Map. empty enabledInspections [] [hie]
81
- return (analysisToDiagnostics file analysis, Just () )
66
+ config <- getClientConfigAction def
67
+ if pluginEnabledConfig plcDiagnosticsOn plId config then do
68
+ maybeHie <- getHieFile file
69
+ case maybeHie of
70
+ Nothing -> return ([] , Nothing )
71
+ Just hie -> do
72
+ let enabledInspections = HM. fromList [(LSP. fromNormalizedFilePath file, inspectionsIds)]
73
+ -- This should use Cabal config for extensions and Stan config for inspection preferences is the future
74
+ let analysis = runAnalysis Map. empty enabledInspections [] [hie]
75
+ return (analysisToDiagnostics file analysis, Just () )
76
+ else return ([] , Nothing )
82
77
83
78
action $ do
84
79
files <- getFilesOfInterestUntracked
@@ -87,7 +82,7 @@ rules recorder = do
87
82
analysisToDiagnostics :: NormalizedFilePath -> Analysis -> [FileDiagnostic ]
88
83
analysisToDiagnostics file = mapMaybe (observationToDianostic file) . toList . analysisObservations
89
84
observationToDianostic :: NormalizedFilePath -> Observation -> Maybe FileDiagnostic
90
- observationToDianostic file ( Observation {observationSrcSpan, observationInspectionId}) =
85
+ observationToDianostic file Observation {observationSrcSpan, observationInspectionId} =
91
86
do
92
87
inspection <- HM. lookup observationInspectionId inspectionsMap
93
88
let
@@ -109,7 +104,7 @@ rules recorder = do
109
104
return ( file,
110
105
ShowDiag ,
111
106
LSP. Diagnostic
112
- { _range = realSrcSpanToRange $ observationSrcSpan,
107
+ { _range = realSrcSpanToRange observationSrcSpan,
113
108
_severity = Just LSP. DsHint ,
114
109
_code = Just (LSP. InR $ unId (inspectionId inspection)),
115
110
_source = Just " stan" ,
0 commit comments