Skip to content

Commit a3bc949

Browse files
committed
Make hlint depend on client setting
1 parent 9b09829 commit a3bc949

File tree

1 file changed

+15
-12
lines changed
  • plugins/hlint-hls-plugin/src/Ide/Plugin

1 file changed

+15
-12
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (rea
5252
import Ide.Logger
5353
import Ide.Types
5454
import Ide.Plugin
55+
import Ide.Plugin.Config
5556
import Ide.PluginUtils
5657
import Language.Haskell.HLint as Hlint
5758
import Language.Haskell.LSP.Types
@@ -83,8 +84,10 @@ type instance RuleResult GetHlintDiagnostics = ()
8384
rules :: Rules ()
8485
rules = do
8586
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 ())
8891

8992
getHlintSettingsRule (HlintEnabled [])
9093

@@ -138,7 +141,7 @@ rules = do
138141

139142
getIdeas :: NormalizedFilePath -> Action (Either ParseError [Idea])
140143
getIdeas nfp = do
141-
logm $ "getIdeas:file:" ++ show nfp
144+
logm $ "hlint:getIdeas:file:" ++ show nfp
142145
(flags, classify, hint) <- useNoFile_ GetHlintSettings
143146

144147
let applyHints' (Just (Right modEx)) = Right $ applyHints classify hint [modEx]
@@ -157,9 +160,9 @@ getIdeas nfp = do
157160
hsc <- hscEnv <$> use_ GhcSession nfp
158161
let dflags = hsc_dflags hsc
159162
let hscExts = EnumSet.toList (extensionFlags dflags)
160-
logm $ "getIdeas:setExtensions:hscExtensions:" ++ show hscExts
163+
logm $ "hlint:getIdeas:setExtensions:hscExtensions:" ++ show hscExts
161164
let hlintExts = mapMaybe (GhclibParserEx.readExtension . show) hscExts
162-
logm $ "getIdeas:setExtensions:hlintExtensions:" ++ show hlintExts
165+
logm $ "hlint:getIdeas:setExtensions:hlintExtensions:" ++ show hlintExts
163166
return $ flags { enabledExtensions = hlintExts }
164167
#else
165168
moduleEx _flags = do
@@ -232,12 +235,12 @@ applyAllCmd _lf ide uri = do
232235
let file = maybe (error $ show uri ++ " is not a file.")
233236
toNormalizedFilePath'
234237
(uriToFilePath' uri)
235-
logm $ "applyAllCmd:file=" ++ show file
238+
logm $ "hlint:applyAllCmd:file=" ++ show file
236239
res <- applyHint ide file Nothing
237-
logm $ "applyAllCmd:res=" ++ show res
240+
logm $ "hlint:applyAllCmd:res=" ++ show res
238241
return $
239242
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)
241244
Right fs -> (Right Null, Just (WorkspaceApplyEdit, ApplyWorkspaceEditParams fs))
242245

243246
-- ---------------------------------------------------------------------
@@ -262,11 +265,11 @@ applyOneCmd _lf ide (AOP uri pos title) = do
262265
let file = maybe (error $ show uri ++ " is not a file.") toNormalizedFilePath'
263266
(uriToFilePath' uri)
264267
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
267270
return $
268271
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)
270273
Right fs -> (Right Null, Just (WorkspaceApplyEdit, ApplyWorkspaceEditParams fs))
271274

272275
applyHint :: IdeState -> NormalizedFilePath -> Maybe OneHint -> IO (Either String WorkspaceEdit)
@@ -301,7 +304,7 @@ applyHint ide nfp mhint =
301304
let uri = fromNormalizedUri (filePathToUri' nfp)
302305
oldContent <- liftIO $ T.readFile fp
303306
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
305308
ExceptT $ Right <$> (return wsEdit)
306309
Left err ->
307310
throwE (show err)

0 commit comments

Comments
 (0)