Skip to content

Commit 855a882

Browse files
andys8pepeiborra
andauthored
Allows disabling stan plugin (#3179)
Respects globalOn in stan plugin configuration and won't show hints anymore if the plugin is disabled. Co-authored-by: Pepe Iborra <[email protected]>
1 parent 5d6a688 commit 855a882

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

plugins/hls-stan-plugin/hls-stan-plugin.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ library
3232
build-depends:
3333
base
3434
, containers
35+
, data-default
3536
, deepseq
3637
, hashable
3738
, hls-plugin-api

plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs

+24-29
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,17 @@ import Control.Monad (void)
55
import Control.Monad.IO.Class (liftIO)
66
import Control.Monad.Trans.Class (lift)
77
import Control.Monad.Trans.Maybe (MaybeT (MaybeT), runMaybeT)
8+
import Data.Default
89
import Data.Foldable (toList)
9-
import Data.Hashable (Hashable)
1010
import qualified Data.HashMap.Strict as HM
11+
import Data.Hashable (Hashable)
1112
import qualified Data.Map as Map
1213
import Data.Maybe (fromJust, mapMaybe)
1314
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 (..))
2717
import Development.IDE.Core.Rules (getHieFile,
2818
getSourceFileSource)
29-
import Development.IDE.Core.RuleTypes (HieAstResult (..))
3019
import qualified Development.IDE.Core.Shake as Shake
3120
import Development.IDE.GHC.Compat (HieASTs (HieASTs),
3221
RealSrcSpan (..), mkHieFile',
@@ -38,9 +27,11 @@ import Development.IDE.GHC.Compat (HieASTs (HieASTs),
3827
import Development.IDE.GHC.Error (realSrcSpanToRange)
3928
import GHC.Generics (Generic)
4029
import HieTypes (HieASTs, HieFile)
30+
import Ide.Plugin.Config
4131
import Ide.Types (PluginDescriptor (..),
4232
PluginId,
43-
defaultPluginDescriptor)
33+
defaultPluginDescriptor,
34+
pluginEnabledConfig)
4435
import qualified Language.LSP.Types as LSP
4536
import Stan.Analysis (Analysis (..), runAnalysis)
4637
import Stan.Category (Category (..))
@@ -50,7 +41,8 @@ import Stan.Inspection.All (inspectionsIds, inspectionsMap)
5041
import Stan.Observation (Observation (..))
5142

5243
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}
5446

5547
newtype Log = LogShake Shake.Log deriving (Show)
5648

@@ -67,18 +59,21 @@ instance NFData GetStanDiagnostics
6759

6860
type instance RuleResult GetStanDiagnostics = ()
6961

70-
rules :: Recorder (WithPriority Log) -> Rules ()
71-
rules recorder = do
62+
rules :: Recorder (WithPriority Log) -> PluginId -> Rules ()
63+
rules recorder plId = do
7264
define (cmapWithPrio LogShake recorder) $
7365
\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)
8277

8378
action $ do
8479
files <- getFilesOfInterestUntracked
@@ -87,7 +82,7 @@ rules recorder = do
8782
analysisToDiagnostics :: NormalizedFilePath -> Analysis -> [FileDiagnostic]
8883
analysisToDiagnostics file = mapMaybe (observationToDianostic file) . toList . analysisObservations
8984
observationToDianostic :: NormalizedFilePath -> Observation -> Maybe FileDiagnostic
90-
observationToDianostic file (Observation {observationSrcSpan, observationInspectionId}) =
85+
observationToDianostic file Observation {observationSrcSpan, observationInspectionId} =
9186
do
9287
inspection <- HM.lookup observationInspectionId inspectionsMap
9388
let
@@ -109,7 +104,7 @@ rules recorder = do
109104
return ( file,
110105
ShowDiag,
111106
LSP.Diagnostic
112-
{ _range = realSrcSpanToRange $ observationSrcSpan,
107+
{ _range = realSrcSpanToRange observationSrcSpan,
113108
_severity = Just LSP.DsHint,
114109
_code = Just (LSP.InR $ unId (inspectionId inspection)),
115110
_source = Just "stan",

0 commit comments

Comments
 (0)