25
25
module Ide.Types
26
26
( PluginDescriptor (.. ), defaultPluginDescriptor, defaultCabalPluginDescriptor
27
27
, defaultPluginPriority, defaultPluginFileExtensions
28
+ , defaultPluginFOIStatus
28
29
, IdeCommand (.. )
29
30
, IdeMethod (.. )
30
31
, IdeNotification (.. )
@@ -34,6 +35,7 @@ module Ide.Types
34
35
, ConfigDescriptor (.. ), defaultConfigDescriptor, configForPlugin, pluginEnabledConfig
35
36
, CustomConfig (.. ), mkCustomConfig
36
37
, FallbackCodeActionParams (.. )
38
+ , FileOfInterestStatus (.. )
37
39
, FormattingType (.. ), FormattingMethod , FormattingHandler , mkFormattingHandlers
38
40
, HasTracing (.. )
39
41
, PluginCommand (.. ), CommandId (.. ), CommandFunction , mkLspCommand, mkLspCmdId
@@ -55,6 +57,7 @@ module Ide.Types
55
57
, lookupCommandProvider
56
58
, ResolveFunction
57
59
, mkResolveHandler
60
+ , filterResponsibleFOI
58
61
)
59
62
where
60
63
@@ -71,6 +74,7 @@ import System.Posix.Signals
71
74
72
75
import Control.Applicative ((<|>) )
73
76
import Control.Arrow ((&&&) )
77
+ import Control.DeepSeq (NFData )
74
78
import Control.Lens (_Just , (.~) , (?~) , (^.) , (^?) )
75
79
import Control.Monad (void )
76
80
import Control.Monad.Error.Class (MonadError (throwError ))
@@ -96,6 +100,7 @@ import Data.Semigroup
96
100
import Data.String
97
101
import qualified Data.Text as T
98
102
import Data.Text.Encoding (encodeUtf8 )
103
+ import Data.Typeable (Typeable )
99
104
import Development.IDE.Graph
100
105
import GHC (DynFlags )
101
106
import GHC.Generics
@@ -286,6 +291,11 @@ data PluginDescriptor (ideState :: Type) =
286
291
-- The plugin is only allowed to handle files with these extensions.
287
292
-- When writing handlers, etc. for this plugin it can be assumed that all handled files are of this type.
288
293
-- 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.
289
299
}
290
300
291
301
-- | A description of the types of files that the plugin
@@ -335,6 +345,22 @@ pluginResponsible uri pluginDesc
335
345
mfp :: Maybe NormalizedFilePath
336
346
mfp = uriToNormalizedFilePath $ toNormalizedUri uri
337
347
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
+
338
364
-- | An existential wrapper of 'Properties'
339
365
data CustomConfig = forall r . CustomConfig (Properties r )
340
366
@@ -905,10 +931,14 @@ defaultPluginDescriptor plId =
905
931
mempty
906
932
Nothing
907
933
(PluginFileType [FromProject ] defaultPluginFileExtensions)
934
+ defaultPluginFOIStatus
908
935
909
936
defaultPluginFileExtensions :: [T. Text ]
910
937
defaultPluginFileExtensions = [" .hs" , " .lhs" , " .hs-boot" ]
911
938
939
+ defaultPluginFOIStatus :: [FileOfInterestStatus ]
940
+ defaultPluginFOIStatus = [OnDisk , Modified True , Modified False ]
941
+
912
942
-- | Set up a plugin descriptor, initialized with default values.
913
943
-- This plugin descriptor is prepared for @.cabal@ files and as such,
914
944
-- will only respond / run when @.cabal@ files are currently in scope.
@@ -928,6 +958,7 @@ defaultCabalPluginDescriptor plId =
928
958
mempty
929
959
Nothing
930
960
(PluginFileType [FromProject ] [" .cabal" ])
961
+ defaultPluginFOIStatus
931
962
932
963
newtype CommandId = CommandId T. Text
933
964
deriving (Show , Read , Eq , Ord )
0 commit comments