@@ -52,6 +52,7 @@ import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (rea
52
52
import Ide.Logger
53
53
import Ide.Types
54
54
import Ide.Plugin
55
+ import Ide.Plugin.Config
55
56
import Ide.PluginUtils
56
57
import Language.Haskell.HLint as Hlint
57
58
import Language.Haskell.LSP.Types
@@ -83,8 +84,10 @@ type instance RuleResult GetHlintDiagnostics = ()
83
84
rules :: Rules ()
84
85
rules = do
85
86
define $ \ GetHlintDiagnostics file -> do
86
- ideas <- getIdeas file
87
- return $ (diagnostics file ideas, Just () )
87
+ hlintOn' <- hlintOn <$> getClientConfigAction
88
+ logm $ " hlint:rules:hlintOn=" <> show hlintOn'
89
+ ideas <- if hlintOn' then getIdeas file else return (Right [] )
90
+ return (diagnostics file ideas, Just () )
88
91
89
92
getHlintSettingsRule (HlintEnabled [] )
90
93
@@ -138,7 +141,7 @@ rules = do
138
141
139
142
getIdeas :: NormalizedFilePath -> Action (Either ParseError [Idea ])
140
143
getIdeas nfp = do
141
- logm $ " getIdeas:file:" ++ show nfp
144
+ logm $ " hlint: getIdeas:file:" ++ show nfp
142
145
(flags, classify, hint) <- useNoFile_ GetHlintSettings
143
146
144
147
let applyHints' (Just (Right modEx)) = Right $ applyHints classify hint [modEx]
@@ -157,9 +160,9 @@ getIdeas nfp = do
157
160
hsc <- hscEnv <$> use_ GhcSession nfp
158
161
let dflags = hsc_dflags hsc
159
162
let hscExts = EnumSet. toList (extensionFlags dflags)
160
- logm $ " getIdeas:setExtensions:hscExtensions:" ++ show hscExts
163
+ logm $ " hlint: getIdeas:setExtensions:hscExtensions:" ++ show hscExts
161
164
let hlintExts = mapMaybe (GhclibParserEx. readExtension . show ) hscExts
162
- logm $ " getIdeas:setExtensions:hlintExtensions:" ++ show hlintExts
165
+ logm $ " hlint: getIdeas:setExtensions:hlintExtensions:" ++ show hlintExts
163
166
return $ flags { enabledExtensions = hlintExts }
164
167
#else
165
168
moduleEx _flags = do
@@ -232,12 +235,12 @@ applyAllCmd _lf ide uri = do
232
235
let file = maybe (error $ show uri ++ " is not a file." )
233
236
toNormalizedFilePath'
234
237
(uriToFilePath' uri)
235
- logm $ " applyAllCmd:file=" ++ show file
238
+ logm $ " hlint: applyAllCmd:file=" ++ show file
236
239
res <- applyHint ide file Nothing
237
- logm $ " applyAllCmd:res=" ++ show res
240
+ logm $ " hlint: applyAllCmd:res=" ++ show res
238
241
return $
239
242
case res of
240
- Left err -> (Left (responseError (T. pack $ " applyAll: " ++ show err)), Nothing )
243
+ Left err -> (Left (responseError (T. pack $ " hlint: applyAll: " ++ show err)), Nothing )
241
244
Right fs -> (Right Null , Just (WorkspaceApplyEdit , ApplyWorkspaceEditParams fs))
242
245
243
246
-- ---------------------------------------------------------------------
@@ -262,11 +265,11 @@ applyOneCmd _lf ide (AOP uri pos title) = do
262
265
let file = maybe (error $ show uri ++ " is not a file." ) toNormalizedFilePath'
263
266
(uriToFilePath' uri)
264
267
res <- applyHint ide file (Just oneHint)
265
- logm $ " applyOneCmd:file=" ++ show file
266
- logm $ " applyOneCmd:res=" ++ show res
268
+ logm $ " hlint: applyOneCmd:file=" ++ show file
269
+ logm $ " hlint: applyOneCmd:res=" ++ show res
267
270
return $
268
271
case res of
269
- Left err -> (Left (responseError (T. pack $ " applyOne: " ++ show err)), Nothing )
272
+ Left err -> (Left (responseError (T. pack $ " hlint: applyOne: " ++ show err)), Nothing )
270
273
Right fs -> (Right Null , Just (WorkspaceApplyEdit , ApplyWorkspaceEditParams fs))
271
274
272
275
applyHint :: IdeState -> NormalizedFilePath -> Maybe OneHint -> IO (Either String WorkspaceEdit )
@@ -301,7 +304,7 @@ applyHint ide nfp mhint =
301
304
let uri = fromNormalizedUri (filePathToUri' nfp)
302
305
oldContent <- liftIO $ T. readFile fp
303
306
let wsEdit = diffText' True (uri, oldContent) (T. pack appliedFile) IncludeDeletions
304
- liftIO $ logm $ " applyHint:diff=" ++ show wsEdit
307
+ liftIO $ logm $ " hlint: applyHint:diff=" ++ show wsEdit
305
308
ExceptT $ Right <$> (return wsEdit)
306
309
Left err ->
307
310
throwE (show err)
0 commit comments