@@ -81,7 +81,7 @@ instance Pretty Log where
81
81
descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
82
82
descriptor recorder plId =
83
83
(defaultCabalPluginDescriptor plId " Provides a variety of IDE features in cabal files" )
84
- { pluginRules = cabalRules recorder
84
+ { pluginRules = cabalRules recorder plId
85
85
, pluginHandlers =
86
86
mconcat
87
87
[ mkPluginHandler LSP. SMethod_TextDocumentCodeAction licenseSuggestCodeAction
@@ -139,31 +139,35 @@ restartCabalShakeSession shakeExtras vfs file actionMsg = do
139
139
-- Plugin Rules
140
140
-- ----------------------------------------------------------------
141
141
142
- cabalRules :: Recorder (WithPriority Log ) -> Rules ()
143
- cabalRules recorder = do
142
+ cabalRules :: Recorder (WithPriority Log ) -> PluginId -> Rules ()
143
+ cabalRules recorder plId = do
144
144
-- Make sure we initialise the cabal files-of-interest.
145
145
ofInterestRules recorder
146
146
-- Rule to produce diagnostics for cabal files.
147
- define (cmapWithPrio LogShake recorder) $ \ Types. ParseCabal file -> do
148
- -- whenever this key is marked as dirty (e.g., when a user writes stuff to it),
149
- -- we rerun this rule because this rule *depends* on GetModificationTime.
150
- (t, mCabalSource) <- use_ GetFileContents file
151
- log' Debug $ LogModificationTime file t
152
- contents <- case mCabalSource of
153
- Just sources ->
154
- pure $ Encoding. encodeUtf8 sources
155
- Nothing -> do
156
- liftIO $ BS. readFile $ fromNormalizedFilePath file
147
+ define (cmapWithPrio LogShake recorder) $ \ Types. GetCabalDiagnostics file -> do
148
+ config <- getPluginConfigAction plId
149
+ if not (plcGlobalOn config && plcDiagnosticsOn config)
150
+ then pure ([] , Nothing )
151
+ else do
152
+ -- whenever this key is marked as dirty (e.g., when a user writes stuff to it),
153
+ -- we rerun this rule because this rule *depends* on GetModificationTime.
154
+ (t, mCabalSource) <- use_ GetFileContents file
155
+ log' Debug $ LogModificationTime file t
156
+ contents <- case mCabalSource of
157
+ Just sources ->
158
+ pure $ Encoding. encodeUtf8 sources
159
+ Nothing -> do
160
+ liftIO $ BS. readFile $ fromNormalizedFilePath file
157
161
158
- (pWarnings, pm) <- liftIO $ Parse. parseCabalFileContents contents
159
- let warningDiags = fmap (Diagnostics. warningDiagnostic file) pWarnings
160
- case pm of
161
- Left (_cabalVersion, pErrorNE) -> do
162
- let errorDiags = NE. toList $ NE. map (Diagnostics. errorDiagnostic file) pErrorNE
163
- allDiags = errorDiags <> warningDiags
164
- pure (allDiags, Nothing )
165
- Right gpd -> do
166
- pure (warningDiags, Just gpd)
162
+ (pWarnings, pm) <- liftIO $ Parse. parseCabalFileContents contents
163
+ let warningDiags = fmap (Diagnostics. warningDiagnostic file) pWarnings
164
+ case pm of
165
+ Left (_cabalVersion, pErrorNE) -> do
166
+ let errorDiags = NE. toList $ NE. map (Diagnostics. errorDiagnostic file) pErrorNE
167
+ allDiags = errorDiags <> warningDiags
168
+ pure (allDiags, Nothing )
169
+ Right gpd -> do
170
+ pure (warningDiags, Just gpd)
167
171
168
172
action $ do
169
173
-- Run the cabal kick. This code always runs when 'shakeRestart' is run.
@@ -183,7 +187,7 @@ function invocation.
183
187
kick :: Action ()
184
188
kick = do
185
189
files <- HashMap. keys <$> getCabalFilesOfInterestUntracked
186
- void $ uses Types. ParseCabal files
190
+ void $ uses Types. GetCabalDiagnostics files
187
191
188
192
-- ----------------------------------------------------------------
189
193
-- Code Actions
@@ -292,7 +296,7 @@ completion recorder ide _ complParams = do
292
296
let completer = Completions. contextToCompleter ctx
293
297
let completerData = CompleterTypes. CompleterData
294
298
{ getLatestGPD = do
295
- mGPD <- runIdeAction " cabal-plugin.modulesCompleter.gpd" (shakeExtras ide) $ useWithStaleFast Types. ParseCabal $ toNormalizedFilePath fp
299
+ mGPD <- runIdeAction " cabal-plugin.modulesCompleter.gpd" (shakeExtras ide) $ useWithStaleFast Types. GetCabalDiagnostics $ toNormalizedFilePath fp
296
300
pure $ fmap fst mGPD
297
301
, cabalPrefixInfo = prefInfo
298
302
, stanzaName =
0 commit comments