Skip to content

Commit

Permalink
Adjust rendering of error logs and drop unneeded MonadUnliftIO instan…
Browse files Browse the repository at this point in the history
…ce (#2755)

* drop unneeded MonadUnliftIO instance

* Adjust error message

* fixups
  • Loading branch information
pepeiborra authored Mar 6, 2022
1 parent b7f37ad commit 30b3fec
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
12 changes: 6 additions & 6 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module Main(main) where

import Data.Function ((&))
import Data.Text (Text)
import Development.IDE.Plugin.LSPWindowShowMessageRecorder (makeLspShowMessageRecorder)
import Development.IDE.Types.Logger (Priority (Debug, Info, Error),
WithPriority (WithPriority, priority),
cfilter, cmapWithPrio,
Expand All @@ -15,11 +17,9 @@ import Ide.Arguments (Arguments (..),
getArguments)
import Ide.Main (defaultMain)
import qualified Ide.Main as IdeMain
import Ide.PluginUtils (pluginDescToIdePlugins)
import qualified Plugins
import Prettyprinter (Pretty (pretty), vcat)
import Development.IDE.Plugin.LSPWindowShowMessageRecorder (makeLspShowMessageRecorder)
import Data.Text (Text)
import Ide.PluginUtils (pluginDescToIdePlugins)
import Prettyprinter (Pretty (pretty), vsep)

data Log
= LogIdeMain IdeMain.Log
Expand Down Expand Up @@ -59,8 +59,8 @@ main = do
defaultMain (cmapWithPrio LogIdeMain recorder) args (pluginDescToIdePlugins [lspRecorderPlugin] <> plugins)

renderDoc :: Doc a -> Text
renderDoc d = renderStrict $ layoutPretty defaultLayoutOptions $ vcat
["Unhandled exception, please check your setup and/or the [issue tracker](" <> issueTrackerUrl <> "): "
renderDoc d = renderStrict $ layoutPretty defaultLayoutOptions $ vsep
["Error condition, please check your setup and/or the [issue tracker](" <> issueTrackerUrl <> "): "
,d
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Development.IDE.Plugin.LSPWindowShowMessageRecorder (makeLspShowMessageRecorder) where

import Control.Monad.IO.Class
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Data.Foldable (for_)
import Data.IORef
import Data.IORef.Extra (atomicModifyIORef'_)
Expand All @@ -24,8 +23,8 @@ makeLspShowMessageRecorder = do
backLogRef <- newIORef []
let recorder = Recorder $ \it -> do
mbenv <- liftIO $ readIORef envRef
case mbenv of
Nothing -> liftIO $ atomicModifyIORef'_ backLogRef (it :)
liftIO $ case mbenv of
Nothing -> atomicModifyIORef'_ backLogRef (it :)
Just env -> sendMsg env it
-- the plugin captures the language context, so it can be used to send messages
plugin =
Expand All @@ -35,11 +34,11 @@ makeLspShowMessageRecorder = do
liftIO $ writeIORef envRef $ Just env
-- flush the backlog
backLog <- liftIO $ atomicModifyIORef' backLogRef ([],)
for_ (reverse backLog) $ sendMsg env
liftIO $ for_ (reverse backLog) $ sendMsg env
}
return (recorder, plugin)

sendMsg :: MonadUnliftIO m => LanguageContextEnv config -> WithPriority Text -> m ()
sendMsg :: LanguageContextEnv config -> WithPriority Text -> IO ()
sendMsg env WithPriority {..} =
LSP.runLspT env $
LSP.sendNotification
Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Types/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ data WithPriority a = WithPriority { priority :: Priority, callStack_ :: CallSta
-- You shouldn't call warning/error if the user has caused an error, only
-- if our code has gone wrong and is itself erroneous (e.g. we threw an exception).
newtype Recorder msg = Recorder
{ logger_ :: forall m. (MonadUnliftIO m) => msg -> m () }
{ logger_ :: forall m. (MonadIO m) => msg -> m () }

logWith :: (HasCallStack, MonadUnliftIO m) => Recorder (WithPriority msg) -> Priority -> msg -> m ()
logWith :: (HasCallStack, MonadIO m) => Recorder (WithPriority msg) -> Priority -> msg -> m ()
logWith recorder priority msg = withFrozenCallStack $ logger_ recorder (WithPriority priority callStack msg)

instance Semigroup (Recorder msg) where
Expand Down
1 change: 0 additions & 1 deletion hls-graph/hls-graph.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ library
, stm-containers
, time
, transformers
, unliftio
, unordered-containers

if flag(embed-files)
Expand Down
3 changes: 1 addition & 2 deletions hls-graph/src/Development/IDE/Graph/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import qualified ListT
import StmContainers.Map (Map)
import qualified StmContainers.Map as SMap
import System.Time.Extra (Seconds)
import UnliftIO (MonadUnliftIO)


unwrapDynamic :: forall a . Typeable a => Dynamic -> a
Expand All @@ -63,7 +62,7 @@ data SRules = SRules {
-- ACTIONS

newtype Action a = Action {fromAction :: ReaderT SAction IO a}
deriving newtype (Monad, Applicative, Functor, MonadIO, MonadFail, MonadThrow, MonadCatch, MonadMask, MonadUnliftIO)
deriving newtype (Monad, Applicative, Functor, MonadIO, MonadFail, MonadThrow, MonadCatch, MonadMask)

data SAction = SAction {
actionDatabase :: !Database,
Expand Down

0 comments on commit 30b3fec

Please sign in to comment.