Skip to content

Commit 9d7d6cc

Browse files
committed
Purge some more hslogger
At this point we only really need it for `hie-bios`.
1 parent 8a90def commit 9d7d6cc

File tree

7 files changed

+41
-73
lines changed

7 files changed

+41
-73
lines changed

ghcide/exe/Main.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ main = withTelemetryLogger $ \telemetryLogger -> do
9999
liftIO $ (cb1 <> cb2) env
100100
}
101101

102-
let docWithFilteredPriorityRecorder@Recorder{ logger_ } =
102+
let docWithFilteredPriorityRecorder =
103103
(docWithPriorityRecorder & cfilter (\WithPriority{ priority } -> priority >= minPriority)) <>
104104
(lspLogRecorder & cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions)
105105
& cfilter (\WithPriority{ priority } -> priority >= minPriority)) <>
106106
(lspMessageRecorder & cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions)
107107
& cfilter (\WithPriority{ priority } -> priority >= Error))
108108

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

112112
let recorder = docWithFilteredPriorityRecorder
113113
& cmapWithPrio pretty

haskell-language-server.cabal

-2
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

-2
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

-29
This file was deleted.

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

+1
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

+30-25
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

+8-13
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import qualified Development.IDE.Main as IDEMain
2525
import qualified Development.IDE.Session as Session
2626
import Development.IDE.Types.Logger as G
2727
import qualified Development.IDE.Types.Options as Ghcide
28+
import GHC.Stack (emptyCallStack)
2829
import qualified HIE.Bios.Environment as HieBios
2930
import HIE.Bios.Types
3031
import Ide.Arguments
31-
import Ide.Logger
3232
import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig,
3333
pluginsToVSCodeExtensionSchema)
3434
import Ide.Types (IdePlugins, PluginId (PluginId),
@@ -43,6 +43,7 @@ data Log
4343
| LogDirectory !FilePath
4444
| LogLspStart !GhcideArguments ![PluginId]
4545
| LogIDEMain IDEMain.Log
46+
| LogOther T.Text
4647
deriving Show
4748

4849
instance Pretty Log where
@@ -56,6 +57,7 @@ instance Pretty Log where
5657
, viaShow ghcideArgs
5758
, "PluginIds:" <+> pretty (coerce @_ @[Text] pluginIds) ]
5859
LogIDEMain iDEMainLog -> pretty iDEMainLog
60+
LogOther t -> pretty t
5961

6062
defaultMain :: Recorder (WithPriority Log) -> Arguments -> IdePlugins IdeState -> IO ()
6163
defaultMain recorder args idePlugins = do
@@ -108,16 +110,6 @@ defaultMain recorder args idePlugins = do
108110

109111
-- ---------------------------------------------------------------------
110112

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

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

0 commit comments

Comments
 (0)