Skip to content

Commit 1fbc2d8

Browse files
committed
Purge some more hslogger
At this point we only really need it for `hie-bios`.
1 parent 82c1535 commit 1fbc2d8

File tree

7 files changed

+41
-73
lines changed

7 files changed

+41
-73
lines changed

ghcide/exe/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ main = withTelemetryLogger $ \telemetryLogger -> do
9090

9191
(lspRecorder, lspRecorderPlugin) <- makeLspShowMessageRecorder
9292

93-
let docWithFilteredPriorityRecorder@Recorder{ logger_ } =
93+
let docWithFilteredPriorityRecorder =
9494
(docWithPriorityRecorder & cfilter (\WithPriority{ priority } -> priority >= minPriority)) <>
9595
(lspRecorder & cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions)
9696
& cfilter (\WithPriority{ priority } -> priority >= Error)
9797
)
9898

9999
-- exists so old-style logging works. intended to be phased out
100-
let logger = Logger $ \p m -> logger_ (WithPriority p emptyCallStack (pretty m))
100+
let logger = Logger $ \p m -> Logger.logger_ docWithFilteredPriorityRecorder (WithPriority p emptyCallStack (pretty m))
101101

102102
let recorder = docWithFilteredPriorityRecorder
103103
& cmapWithPrio pretty

haskell-language-server.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ library
7777
, hie-bios
7878
, hiedb
7979
, hls-plugin-api ^>=1.3
80-
, hslogger
8180
, optparse-applicative
8281
, optparse-simple
8382
, process
@@ -410,7 +409,6 @@ executable haskell-language-server
410409
, hiedb
411410
, lens
412411
, regex-tdfa
413-
, hslogger
414412
, optparse-applicative
415413
, hls-plugin-api
416414
, lens

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ source-repository head
2626

2727
library
2828
exposed-modules:
29-
Ide.Logger
3029
Ide.Plugin.Config
3130
Ide.Plugin.ConfigUtils
3231
Ide.Plugin.Properties
@@ -47,7 +46,6 @@ library
4746
, ghc
4847
, hashable
4948
, hls-graph ^>= 1.6
50-
, hslogger
5149
, lens
5250
, lens-aeson
5351
, lsp >=1.4.0.0 && < 1.6

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

plugins/hls-hlint-plugin/hls-hlint-plugin.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ library
6262
, hslogger
6363
, lens
6464
, lsp
65+
, refact
6566
, regex-tdfa
6667
, stm
6768
, temporary

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

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Development.IDE.Core.Rules (defineNoFil
5555
usePropertyAction)
5656
import Development.IDE.Core.Shake (getDiagnostics)
5757
import qualified Refact.Apply as Refact
58+
import qualified Refact.Types as Refact
5859

5960
#ifdef HLINT_ON_GHC_LIB
6061
import Development.IDE.GHC.Compat (BufSpan,
@@ -84,7 +85,7 @@ import System.IO (IOMode (Wri
8485
import System.IO.Temp
8586
#else
8687
import Development.IDE.GHC.Compat hiding
87-
(setEnv)
88+
(setEnv, (<+>))
8889
import GHC.Generics (Associativity (LeftAssociative, NotAssociative, RightAssociative))
8990
import Language.Haskell.GHC.ExactPrint.Delta (deltaOptions)
9091
import Language.Haskell.GHC.ExactPrint.Parsers (postParseTransform)
@@ -93,7 +94,6 @@ import Language.Haskell.GhclibParserEx.Fixity as GhclibPar
9394
import qualified Refact.Fixity as Refact
9495
#endif
9596

96-
import Ide.Logger
9797
import Ide.Plugin.Config hiding
9898
(Config)
9999
import Ide.Plugin.Properties
@@ -125,13 +125,21 @@ import System.Environment (setEnv,
125125
import Text.Regex.TDFA.Text ()
126126
-- ---------------------------------------------------------------------
127127

128-
newtype Log
128+
data Log
129129
= LogShake Shake.Log
130+
| LogApplying NormalizedFilePath (Either String WorkspaceEdit)
131+
| LogGeneratedIdeas NormalizedFilePath [[Refact.Refactoring Refact.SrcSpan]]
132+
| LogGetIdeas NormalizedFilePath
133+
| LogUsingExtensions NormalizedFilePath [String] -- Extension is only imported conditionally, so we just stringify them
130134
deriving Show
131135

132136
instance Pretty Log where
133137
pretty = \case
134138
LogShake log -> pretty log
139+
LogApplying fp res -> "Applying hint(s) for" <+> viaShow fp <> ":" <+> viaShow res
140+
LogGeneratedIdeas fp ideas -> "Generated hlint ideas for for" <+> viaShow fp <> ":" <+> viaShow ideas
141+
LogUsingExtensions fp exts -> "Using extensions for " <+> viaShow fp <> ":" <+> pretty exts
142+
LogGetIdeas fp -> "Getting hlint ideas for " <+> viaShow fp
135143

136144
#ifdef HLINT_ON_GHC_LIB
137145
-- Reimplementing this, since the one in Development.IDE.GHC.Compat isn't for ghc-lib
@@ -148,8 +156,8 @@ descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeSta
148156
descriptor recorder plId = (defaultPluginDescriptor plId)
149157
{ pluginRules = rules recorder plId
150158
, pluginCommands =
151-
[ PluginCommand "applyOne" "Apply a single hint" applyOneCmd
152-
, PluginCommand "applyAll" "Apply all hints to the file" applyAllCmd
159+
[ PluginCommand "applyOne" "Apply a single hint" (applyOneCmd recorder)
160+
, PluginCommand "applyAll" "Apply all hints to the file" (applyAllCmd recorder)
153161
]
154162
, pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionProvider
155163
, pluginConfigDescriptor = defaultConfigDescriptor
@@ -179,7 +187,7 @@ rules recorder plugin = do
179187
define (cmapWithPrio LogShake recorder) $ \GetHlintDiagnostics file -> do
180188
config <- getClientConfigAction def
181189
let hlintOn = pluginEnabledConfig plcDiagnosticsOn plugin config
182-
ideas <- if hlintOn then getIdeas file else return (Right [])
190+
ideas <- if hlintOn then getIdeas recorder file else return (Right [])
183191
return (diagnostics file ideas, Just ())
184192

185193
defineNoFile (cmapWithPrio LogShake recorder) $ \GetHlintSettings -> do
@@ -247,9 +255,9 @@ rules recorder plugin = do
247255
}
248256
srcSpanToRange (UnhelpfulSpan _) = noRange
249257

250-
getIdeas :: NormalizedFilePath -> Action (Either ParseError [Idea])
251-
getIdeas nfp = do
252-
debugm $ "hlint:getIdeas:file:" ++ show nfp
258+
getIdeas :: Recorder (WithPriority Log) -> NormalizedFilePath -> Action (Either ParseError [Idea])
259+
getIdeas recorder nfp = do
260+
logWith recorder Debug $ LogGetIdeas nfp
253261
(flags, classify, hint) <- useNoFile_ GetHlintSettings
254262

255263
let applyHints' (Just (Right modEx)) = Right $ applyHints classify hint [modEx]
@@ -295,7 +303,7 @@ getIdeas nfp = do
295303

296304
setExtensions flags = do
297305
hlintExts <- getExtensions nfp
298-
debugm $ "hlint:getIdeas:setExtensions:" ++ show hlintExts
306+
logWith recorder Debug $ LogUsingExtensions $ nfp (fmap show hlintExts)
299307
return $ flags { enabledExtensions = hlintExts }
300308

301309
-- Gets extensions from ModSummary dynflags for the file.
@@ -469,15 +477,14 @@ mkSuppressHintTextEdits dynFlags fileContents hint =
469477
combinedTextEdit : lineSplitTextEditList
470478
-- ---------------------------------------------------------------------
471479

472-
applyAllCmd :: CommandFunction IdeState Uri
473-
applyAllCmd ide uri = do
480+
applyAllCmd :: Recorder (WithPriority Log) -> CommandFunction IdeState Uri
481+
applyAllCmd recorder ide uri = do
474482
let file = maybe (error $ show uri ++ " is not a file.")
475483
toNormalizedFilePath'
476484
(uriToFilePath' uri)
477485
withIndefiniteProgress "Applying all hints" Cancellable $ do
478-
logm $ "hlint:applyAllCmd:file=" ++ show file
479-
res <- liftIO $ applyHint ide file Nothing
480-
logm $ "hlint:applyAllCmd:res=" ++ show res
486+
res <- liftIO $ applyHint recorder ide file Nothing
487+
logWith recorder Debug $ LogApplying file res
481488
case res of
482489
Left err -> pure $ Left (responseError (T.pack $ "hlint:applyAll: " ++ show err))
483490
Right fs -> do
@@ -500,34 +507,33 @@ data OneHint = OneHint
500507
, oneHintTitle :: HintTitle
501508
} deriving (Eq, Show)
502509

503-
applyOneCmd :: CommandFunction IdeState ApplyOneParams
504-
applyOneCmd ide (AOP uri pos title) = do
510+
applyOneCmd :: Recorder (WithPriority Log) -> CommandFunction IdeState ApplyOneParams
511+
applyOneCmd recorder ide (AOP uri pos title) = do
505512
let oneHint = OneHint pos title
506513
let file = maybe (error $ show uri ++ " is not a file.") toNormalizedFilePath'
507514
(uriToFilePath' uri)
508515
let progTitle = "Applying hint: " <> title
509516
withIndefiniteProgress progTitle Cancellable $ do
510-
logm $ "hlint:applyOneCmd:file=" ++ show file
511-
res <- liftIO $ applyHint ide file (Just oneHint)
512-
logm $ "hlint:applyOneCmd:res=" ++ show res
517+
res <- liftIO $ applyHint recorder ide file (Just oneHint)
518+
logWith recorder Debug $ LogApplying file res
513519
case res of
514520
Left err -> pure $ Left (responseError (T.pack $ "hlint:applyOne: " ++ show err))
515521
Right fs -> do
516522
_ <- sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing fs) (\_ -> pure ())
517523
pure $ Right Null
518524

519-
applyHint :: IdeState -> NormalizedFilePath -> Maybe OneHint -> IO (Either String WorkspaceEdit)
520-
applyHint ide nfp mhint =
525+
applyHint :: Recorder (WithPriority Log) -> IdeState -> NormalizedFilePath -> Maybe OneHint -> IO (Either String WorkspaceEdit)
526+
applyHint recorder ide nfp mhint =
521527
runExceptT $ do
522528
let runAction' :: Action a -> IO a
523529
runAction' = runAction "applyHint" ide
524530
let errorHandlers = [ Handler $ \e -> return (Left (show (e :: IOException)))
525531
, Handler $ \e -> return (Left (show (e :: ErrorCall)))
526532
]
527-
ideas <- bimapExceptT showParseError id $ ExceptT $ runAction' $ getIdeas nfp
533+
ideas <- bimapExceptT showParseError id $ ExceptT $ runAction' $ getIdeas recorder nfp
528534
let ideas' = maybe ideas (`filterIdeas` ideas) mhint
529535
let commands = map ideaRefactoring ideas'
530-
liftIO $ logm $ "applyHint:apply=" ++ show commands
536+
logWith recorder Debug $ LogGeneratedIdeas nfp commands
531537
let fp = fromNormalizedFilePath nfp
532538
(_, mbOldContent) <- liftIO $ runAction' $ getFileContents nfp
533539
oldContent <- maybe (liftIO $ fmap T.decodeUtf8 (BS.readFile fp)) return mbOldContent
@@ -584,7 +590,6 @@ applyHint ide nfp mhint =
584590
Right appliedFile -> do
585591
let uri = fromNormalizedUri (filePathToUri' nfp)
586592
let wsEdit = diffText' True (uri, oldContent) (T.pack appliedFile) IncludeDeletions
587-
liftIO $ logm $ "hlint:applyHint:diff=" ++ show wsEdit
588593
ExceptT $ return (Right wsEdit)
589594
Left err ->
590595
throwE err

src/Ide/Main.hs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import qualified Development.IDE.Main as IDEMain
2626
import qualified Development.IDE.Session as Session
2727
import Development.IDE.Types.Logger as G
2828
import qualified Development.IDE.Types.Options as Ghcide
29+
import GHC.Stack (emptyCallStack)
2930
import qualified HIE.Bios.Environment as HieBios
3031
import HIE.Bios.Types
3132
import Ide.Arguments
32-
import Ide.Logger
3333
import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig,
3434
pluginsToVSCodeExtensionSchema)
3535
import Ide.Types (IdePlugins, PluginId (PluginId),
@@ -44,6 +44,7 @@ data Log
4444
| LogDirectory !FilePath
4545
| LogLspStart !GhcideArguments ![PluginId]
4646
| LogIDEMain IDEMain.Log
47+
| LogOther T.Text
4748
deriving Show
4849

4950
instance Pretty Log where
@@ -57,6 +58,7 @@ instance Pretty Log where
5758
, viaShow ghcideArgs
5859
, "PluginIds:" <+> pretty (coerce @_ @[Text] pluginIds) ]
5960
LogIDEMain iDEMainLog -> pretty iDEMainLog
61+
LogOther t -> pretty t
6062

6163
defaultMain :: Recorder (WithPriority Log) -> Arguments -> IdePlugins IdeState -> IO ()
6264
defaultMain recorder args idePlugins = do
@@ -109,16 +111,6 @@ defaultMain recorder args idePlugins = do
109111

110112
-- ---------------------------------------------------------------------
111113

112-
hlsLogger :: G.Logger
113-
hlsLogger = G.Logger $ \pri txt ->
114-
case pri of
115-
G.Debug -> debugm (T.unpack txt)
116-
G.Info -> logm (T.unpack txt)
117-
G.Warning -> warningm (T.unpack txt)
118-
G.Error -> errorm (T.unpack txt)
119-
120-
-- ---------------------------------------------------------------------
121-
122114
runLspMode :: Recorder (WithPriority Log) -> GhcideArguments -> IdePlugins IdeState -> IO ()
123115
runLspMode recorder ghcideArgs@GhcideArguments{..} idePlugins = withTelemetryLogger $ \telemetryLogger -> do
124116
let log = logWith recorder
@@ -129,10 +121,13 @@ runLspMode recorder ghcideArgs@GhcideArguments{..} idePlugins = withTelemetryLog
129121
when (isLSP argsCommand) $ do
130122
log Info $ LogLspStart ghcideArgs (map fst $ ipMap idePlugins)
131123

132-
IDEMain.defaultMain (cmapWithPrio LogIDEMain recorder) (IDEMain.defaultArguments (cmapWithPrio LogIDEMain recorder) hlsLogger)
124+
-- exists so old-style logging works. intended to be phased out
125+
let logger = Logger $ \p m -> logger_ recorder (WithPriority p emptyCallStack $ LogOther m)
126+
127+
IDEMain.defaultMain (cmapWithPrio LogIDEMain recorder) (IDEMain.defaultArguments (cmapWithPrio LogIDEMain recorder) logger)
133128
{ IDEMain.argCommand = argsCommand
134129
, IDEMain.argsHlsPlugins = idePlugins
135-
, IDEMain.argsLogger = pure hlsLogger <> pure telemetryLogger
130+
, IDEMain.argsLogger = pure logger <> pure telemetryLogger
136131
, IDEMain.argsThreads = if argsThreads == 0 then Nothing else Just $ fromIntegral argsThreads
137132
, IDEMain.argsIdeOptions = \_config sessionLoader ->
138133
let defOptions = Ghcide.defaultIdeOptions sessionLoader

0 commit comments

Comments
 (0)