@@ -81,7 +81,7 @@ instance Pretty Log where
8181descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
8282descriptor recorder plId =
8383 (defaultCabalPluginDescriptor plId " Provides a variety of IDE features in cabal files" )
84- { pluginRules = cabalRules recorder
84+ { pluginRules = cabalRules recorder plId
8585 , pluginHandlers =
8686 mconcat
8787 [ mkPluginHandler LSP. SMethod_TextDocumentCodeAction licenseSuggestCodeAction
@@ -139,31 +139,35 @@ restartCabalShakeSession shakeExtras vfs file actionMsg = do
139139-- Plugin Rules
140140-- ----------------------------------------------------------------
141141
142- cabalRules :: Recorder (WithPriority Log ) -> Rules ()
143- cabalRules recorder = do
142+ cabalRules :: Recorder (WithPriority Log ) -> PluginId -> Rules ()
143+ cabalRules recorder plId = do
144144 -- Make sure we initialise the cabal files-of-interest.
145145 ofInterestRules recorder
146146 -- 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
157161
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)
167171
168172 action $ do
169173 -- Run the cabal kick. This code always runs when 'shakeRestart' is run.
@@ -183,7 +187,7 @@ function invocation.
183187kick :: Action ()
184188kick = do
185189 files <- HashMap. keys <$> getCabalFilesOfInterestUntracked
186- void $ uses Types. ParseCabal files
190+ void $ uses Types. GetCabalDiagnostics files
187191
188192-- ----------------------------------------------------------------
189193-- Code Actions
@@ -292,7 +296,7 @@ completion recorder ide _ complParams = do
292296 let completer = Completions. contextToCompleter ctx
293297 let completerData = CompleterTypes. CompleterData
294298 { 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
296300 pure $ fmap fst mGPD
297301 , cabalPrefixInfo = prefInfo
298302 , stanzaName =
0 commit comments