4
4
{-# LANGUAGE DuplicateRecordFields #-}
5
5
{-# LANGUAGE FlexibleContexts #-}
6
6
{-# LANGUAGE FlexibleInstances #-}
7
+ {-# LANGUAGE OverloadedLabels #-}
7
8
{-# LANGUAGE OverloadedStrings #-}
8
9
{-# LANGUAGE PackageImports #-}
9
10
{-# LANGUAGE ScopedTypeVariables #-}
@@ -33,9 +34,11 @@ import Data.Maybe
33
34
import qualified Data.Text as T
34
35
import qualified Data.Text.IO as T
35
36
import Data.Typeable
36
- import Development.IDE
37
+ import Development.IDE hiding
38
+ (Error )
37
39
import Development.IDE.Core.Rules (defineNoFile ,
38
- getParsedModuleWithComments )
40
+ getParsedModuleWithComments ,
41
+ usePropertyAction )
39
42
import Development.IDE.Core.Shake (getDiagnostics )
40
43
import Refact.Apply
41
44
@@ -70,10 +73,13 @@ import Language.Haskell.GHC.ExactPrint.Types (Rigidity (.
70
73
#endif
71
74
72
75
import Ide.Logger
73
- import Ide.Plugin.Config
76
+ import Ide.Plugin.Config hiding
77
+ (Config )
78
+ import Ide.Plugin.Properties
74
79
import Ide.PluginUtils
75
80
import Ide.Types
76
- import Language.Haskell.HLint as Hlint
81
+ import Language.Haskell.HLint as Hlint hiding
82
+ (Error )
77
83
import Language.LSP.Server (ProgressCancellable (Cancellable ),
78
84
sendRequest ,
79
85
withIndefiniteProgress )
@@ -95,8 +101,11 @@ descriptor plId = (defaultPluginDescriptor plId)
95
101
[ PluginCommand " applyOne" " Apply a single hint" applyOneCmd
96
102
, PluginCommand " applyAll" " Apply all hints to the file" applyAllCmd
97
103
]
98
- , pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionProvider
99
- , pluginConfigDescriptor = defaultConfigDescriptor {configHasDiagnostics = True }
104
+ , pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionProvider
105
+ , pluginConfigDescriptor = defaultConfigDescriptor
106
+ { configHasDiagnostics = True
107
+ , configCustomConfig = mkCustomConfig properties
108
+ }
100
109
}
101
110
102
111
-- This rule only exists for generating file diagnostics
@@ -126,7 +135,9 @@ rules plugin = do
126
135
ideas <- if hlintOn' then getIdeas file else return (Right [] )
127
136
return (diagnostics file ideas, Just () )
128
137
129
- getHlintSettingsRule (HlintEnabled [] )
138
+ defineNoFile $ \ GetHlintSettings -> do
139
+ (Config flags) <- getHlintConfig plugin
140
+ liftIO $ argsSettings flags
130
141
131
142
action $ do
132
143
files <- getFilesOfInterest
@@ -241,11 +252,6 @@ getExtensions pflags nfp = do
241
252
242
253
-- ---------------------------------------------------------------------
243
254
244
- data HlintUsage
245
- = HlintEnabled { cmdArgs :: [String ] }
246
- | HlintDisabled
247
- deriving Show
248
-
249
255
data GetHlintSettings = GetHlintSettings
250
256
deriving (Eq , Show , Typeable , Generic )
251
257
instance Hashable GetHlintSettings
@@ -259,15 +265,22 @@ instance Binary GetHlintSettings
259
265
260
266
type instance RuleResult GetHlintSettings = (ParseFlags , [Classify ], Hint )
261
267
262
- getHlintSettingsRule :: HlintUsage -> Rules ()
263
- getHlintSettingsRule usage =
264
- defineNoFile $ \ GetHlintSettings ->
265
- liftIO $ case usage of
266
- HlintEnabled cmdArgs -> argsSettings cmdArgs
267
- HlintDisabled -> fail " hlint configuration unspecified"
268
-
269
268
-- ---------------------------------------------------------------------
270
269
270
+ newtype Config = Config [String ]
271
+
272
+ properties :: Properties '[ 'PropertyKey " flags" ('TArray String )]
273
+ properties = emptyProperties
274
+ & defineArrayProperty # flags
275
+ " Flags used by hlint" []
276
+
277
+ -- | Get the plugin config
278
+ getHlintConfig :: PluginId -> Action Config
279
+ getHlintConfig pId =
280
+ Config
281
+ <$> usePropertyAction # flags pId properties
282
+
283
+ -- ---------------------------------------------------------------------
271
284
codeActionProvider :: PluginMethodHandler IdeState TextDocumentCodeAction
272
285
codeActionProvider ideState plId (CodeActionParams _ _ docId _ context) = Right . LSP. List . map InR <$> liftIO getCodeActions
273
286
where
0 commit comments