Skip to content

Commit fbb3b57

Browse files
committed
Filter hlint FOIs
1 parent d61b290 commit fbb3b57

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

ghcide/src/Development/IDE/Core/RuleTypes.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
-- using the "Shaker" abstraction layer for in-memory use.
1313
--
1414
module Development.IDE.Core.RuleTypes(
15+
FileOfInterestStatus(..),
1516
GhcSessionDeps(.., GhcSessionDeps),
1617
module Development.IDE.Core.RuleTypes
1718
) where
@@ -42,6 +43,7 @@ import Development.IDE.Spans.Common
4243
import Development.IDE.Spans.LocalBindings
4344
import Development.IDE.Types.Diagnostics
4445
import GHC.Serialized (Serialized)
46+
import Ide.Types (FileOfInterestStatus (..))
4547
import Language.LSP.Protocol.Types (Int32,
4648
NormalizedFilePath)
4749

@@ -333,15 +335,6 @@ data GetFileExists = GetFileExists
333335
instance NFData GetFileExists
334336
instance Hashable GetFileExists
335337

336-
data FileOfInterestStatus
337-
= OnDisk
338-
| ReadOnly
339-
| Modified { firstOpen :: !Bool -- ^ was this file just opened
340-
}
341-
deriving (Eq, Show, Typeable, Generic)
342-
instance Hashable FileOfInterestStatus
343-
instance NFData FileOfInterestStatus
344-
345338
data IsFileOfInterestResult = NotFOI | IsFOI FileOfInterestStatus
346339
deriving (Eq, Show, Typeable, Generic)
347340
instance Hashable IsFileOfInterestResult

ghcide/src/Development/IDE/LSP/Notifications.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ descriptor recorder plId = (defaultPluginDescriptor plId) { pluginNotificationHa
154154
-- (which restart the Shake build) run after everything else
155155
pluginPriority = ghcideNotificationsPluginPriority
156156
, pluginFileType = PluginFileType [FromProject, FromDependency] defaultPluginFileExtensions
157+
, pluginFOIStatus = ReadOnly : defaultPluginFOIStatus
157158
}
158159

159160
ghcideNotificationsPluginPriority :: Natural

ghcide/src/Development/IDE/Plugin/HLS/GhcIde.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ descriptor plId = (defaultPluginDescriptor plId)
5656

5757
, pluginConfigDescriptor = defaultConfigDescriptor
5858
, pluginFileType = PluginFileType [FromProject, FromDependency] defaultPluginFileExtensions
59+
, pluginFOIStatus = ReadOnly : defaultPluginFOIStatus
5960
}
6061

6162
-- ---------------------------------------------------------------------

hls-plugin-api/hls-plugin-api.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ library
5151
, co-log-core
5252
, containers
5353
, data-default
54+
, deepseq
5455
, dependent-map
5556
, dependent-sum >=0.7
5657
, Diff ^>=0.4.0

hls-plugin-api/src/Ide/Types.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
module Ide.Types
2626
( PluginDescriptor(..), defaultPluginDescriptor, defaultCabalPluginDescriptor
2727
, defaultPluginPriority, defaultPluginFileExtensions
28+
, defaultPluginFOIStatus
2829
, IdeCommand(..)
2930
, IdeMethod(..)
3031
, IdeNotification(..)
@@ -34,6 +35,7 @@ module Ide.Types
3435
, ConfigDescriptor(..), defaultConfigDescriptor, configForPlugin, pluginEnabledConfig
3536
, CustomConfig(..), mkCustomConfig
3637
, FallbackCodeActionParams(..)
38+
, FileOfInterestStatus(..)
3739
, FormattingType(..), FormattingMethod, FormattingHandler, mkFormattingHandlers
3840
, HasTracing(..)
3941
, PluginCommand(..), CommandId(..), CommandFunction, mkLspCommand, mkLspCmdId
@@ -55,6 +57,7 @@ module Ide.Types
5557
, lookupCommandProvider
5658
, ResolveFunction
5759
, mkResolveHandler
60+
, filterResponsibleFOI
5861
)
5962
where
6063

@@ -71,6 +74,7 @@ import System.Posix.Signals
7174

7275
import Control.Applicative ((<|>))
7376
import Control.Arrow ((&&&))
77+
import Control.DeepSeq (NFData)
7478
import Control.Lens (_Just, (.~), (?~), (^.), (^?))
7579
import Control.Monad (void)
7680
import Control.Monad.Error.Class (MonadError (throwError))
@@ -96,6 +100,7 @@ import Data.Semigroup
96100
import Data.String
97101
import qualified Data.Text as T
98102
import Data.Text.Encoding (encodeUtf8)
103+
import Data.Typeable (Typeable)
99104
import Development.IDE.Graph
100105
import GHC (DynFlags)
101106
import GHC.Generics
@@ -286,6 +291,11 @@ data PluginDescriptor (ideState :: Type) =
286291
-- The plugin is only allowed to handle files with these extensions.
287292
-- When writing handlers, etc. for this plugin it can be assumed that all handled files are of this type.
288293
-- The file extension must have a leading '.'.
294+
, pluginFOIStatus :: [FileOfInterestStatus]
295+
-- ^ For plugins that have rules that run on files of interest,
296+
-- we specify which FileOfInterestStatus are relevant for the
297+
-- plugin. By default, ReadOnly files of interest are
298+
-- excluded.
289299
}
290300

291301
-- | A description of the types of files that the plugin
@@ -335,6 +345,22 @@ pluginResponsible uri pluginDesc
335345
mfp :: Maybe NormalizedFilePath
336346
mfp = uriToNormalizedFilePath $ toNormalizedUri uri
337347

348+
data FileOfInterestStatus
349+
= OnDisk
350+
| ReadOnly
351+
| Modified { firstOpen :: !Bool -- ^ was this file just opened
352+
}
353+
deriving (Eq, Show, Typeable, Generic)
354+
instance Hashable FileOfInterestStatus
355+
instance NFData FileOfInterestStatus
356+
357+
filterResponsibleFOI
358+
:: PluginDescriptor c
359+
-> HashMap NormalizedFilePath FileOfInterestStatus
360+
-> HashMap NormalizedFilePath FileOfInterestStatus
361+
filterResponsibleFOI pluginDesc =
362+
HashMap.filter (\foiStatus -> foiStatus `elem` pluginFOIStatus pluginDesc)
363+
338364
-- | An existential wrapper of 'Properties'
339365
data CustomConfig = forall r. CustomConfig (Properties r)
340366

@@ -905,10 +931,14 @@ defaultPluginDescriptor plId =
905931
mempty
906932
Nothing
907933
(PluginFileType [FromProject] defaultPluginFileExtensions)
934+
defaultPluginFOIStatus
908935

909936
defaultPluginFileExtensions :: [T.Text]
910937
defaultPluginFileExtensions = [".hs", ".lhs", ".hs-boot"]
911938

939+
defaultPluginFOIStatus :: [FileOfInterestStatus]
940+
defaultPluginFOIStatus = [OnDisk, Modified True, Modified False]
941+
912942
-- | Set up a plugin descriptor, initialized with default values.
913943
-- This plugin descriptor is prepared for @.cabal@ files and as such,
914944
-- will only respond / run when @.cabal@ files are currently in scope.
@@ -928,6 +958,7 @@ defaultCabalPluginDescriptor plId =
928958
mempty
929959
Nothing
930960
(PluginFileType [FromProject] [".cabal"])
961+
defaultPluginFOIStatus
931962

932963
newtype CommandId = CommandId T.Text
933964
deriving (Show, Read, Eq, Ord)

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ rules recorder plugin = do
234234
liftIO $ argsSettings flags
235235

236236
action $ do
237-
files <- getFilesOfInterestUntracked
237+
files <- filterResponsibleFOI (descriptor recorder plugin) <$> getFilesOfInterestUntracked
238238
void $ uses GetHlintDiagnostics $ Map.keys files
239239

240240
where

0 commit comments

Comments
 (0)