Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data structures related to logging and notifying the user
Synopsis
- newtype ReportContext = ReportContext {
- unReportContext :: [Text]
- reportContext' :: ReportContext -> Maybe Text
- prefixReportContext' :: ReportContext -> Maybe Text
- reportContext :: ReportContext -> Text
- prefixReportContext :: ReportContext -> Text
- data Report where
- Report :: HasCallStack => {..} -> Report
- data LogReport = LogReport {}
- simple :: HasCallStack => Text -> LogReport
- basicReport :: Member (Stop Report) r => HasCallStack => Text -> [Text] -> Sem r a
- class Reportable e where
- mapReport :: forall e r a. Reportable e => Member (Stop Report) r => Sem (Stop e ': r) a -> Sem r a
- type Stops errs = FMap (Pure1 Stop) @@ errs
- class MapReports (errs :: [Type]) (r :: EffectRow) where
- mapReports :: InterpretersFor (Stops errs) r
- resumeReport :: forall eff e r a. Reportable e => Members [eff !! e, Stop Report] r => Sem (eff ': r) a -> Sem r a
- class ResumeReports (effs :: EffectRow) (errs :: [Type]) (r :: EffectRow) where
- resumeReports :: InterpretersFor effs r
- reportMessages :: Report -> Text
- userReport :: forall e. Reportable e => e -> Text
- resumeHoistUserMessage :: forall err eff err' r. Reportable err => Members [eff !! err, Stop err'] r => (Text -> err') -> InterpreterFor eff r
- mapUserMessage :: forall err err' r. Reportable err => Member (Stop err') r => (Text -> err') -> InterpreterFor (Stop err) r
- stopReportToFail :: forall e r. Member Fail r => Reportable e => InterpreterFor (Stop e) r
- resumeReportFail :: forall eff err r. Members [Fail, eff !! err] r => Reportable err => InterpreterFor eff r
Documentation
newtype ReportContext Source #
The provenance of a report, for use in logs.
Instances
reportContext' :: ReportContext -> Maybe Text Source #
Render a ReportContext
by interspersing it with dots, returning Nothing
if it is empty.
prefixReportContext' :: ReportContext -> Maybe Text Source #
Render a ReportContext
by interspersing it with dots, followed by a colon, returning Nothing
if it is empty.
reportContext :: ReportContext -> Text Source #
Render a ReportContext
by interspersing it with dots, using global
if it is empty.
prefixReportContext :: ReportContext -> Text Source #
Render a ReportContext
by interspersing it with dots, followed by a colon, using global
if it is empty.
An report with different messages intended to be sent to Neovim and the log, respectively.
Used by request handlers and expected by the RPC dispatcher.
Also contains the Severity
of the report, or minimum log level, which determines whether the report should be
logged and echoed in Neovim, and what kind of highlighting should be used in Neovim (red for errors, orange for
warnings, none for infomrational errors).
The log message may span multiple lines.
Instances
IsString Report Source # | |
Defined in Ribosome.Host.Data.Report fromString :: String -> Report # | |
Show Report Source # | |
Reportable Report Source # | |
MsgpackEncode a => HandlerCodec (Handler r a) r Source # | |
Defined in Ribosome.Host.Handler.Codec handlerCodec :: Handler r a -> RpcHandlerFun r Source # |
The type used by request handlers and expected by the RPC dispatcher.
Instances
IsString LogReport Source # | |
Defined in Ribosome.Host.Data.Report fromString :: String -> LogReport # | |
Generic LogReport Source # | |
Show LogReport Source # | |
type Rep LogReport Source # | |
Defined in Ribosome.Host.Data.Report type Rep LogReport = D1 ('MetaData "LogReport" "Ribosome.Host.Data.Report" "ribosome-host-0.9.9.9-5mVeOZw909e7nfaEBEbC5r" 'False) (C1 ('MetaCons "LogReport" 'PrefixI 'True) ((S1 ('MetaSel ('Just "report") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Report) :*: S1 ('MetaSel ('Just "echo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :*: (S1 ('MetaSel ('Just "store") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "context") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ReportContext)))) |
basicReport :: Member (Stop Report) r => HasCallStack => Text -> [Text] -> Sem r a Source #
Stop with a LogReport
.
class Reportable e where Source #
The class of types that are convertible to a Report
.
This is used to create a uniform format for handlers, since control flow is passed on to the internal machinery when
they return.
If an error would be thrown that is not caught by the request dispatcher, the entire plugin would stop, so all Stop
and Resumable
effects need to be converted to Report
before returning (see Errors).
The combinators associated with this class make this task a little less arduous:
data NumbersError = InvalidNumber instance Reportable NumbersError where toReport InvalidNumber = Report "Invalid number!" ["The user entered an invalid number"] Warn count :: Int -> Sem r Int count i = resumeReport @Rpc $ mapReport @NumbersError do when (i == 0) (stop InvalidNumber) nvimGetVar ("number_" <> show i)
Here resumeReport
converts a potential RpcError
from nvimGetVar
to Report
(e.g. if the variable
is not set), while mapReport
uses the instance
to convert the call to Reportable
NumbersError
stop
.
Instances
mapReport :: forall e r a. Reportable e => Member (Stop Report) r => Sem (Stop e ': r) a -> Sem r a Source #
Reinterpret
to Stop
err
if Stop
Report
err
is an instance of Reportable
.
class MapReports (errs :: [Type]) (r :: EffectRow) where Source #
Map multiple errors to Report
.
mapReports :: InterpretersFor (Stops errs) r Source #
Map multiple errors to Report
.
This needs the errors specified as type applications.
mapReports @[RpcError, SettingError]
Instances
MapReports ('[] :: [Type]) r Source # | |
Defined in Ribosome.Host.Data.Report mapReports :: InterpretersFor (Stops '[]) r Source # | |
(Reportable err, MapReports errs r, Member (Stop Report) (Stops errs ++ r)) => MapReports (err ': errs) r Source # | |
Defined in Ribosome.Host.Data.Report mapReports :: InterpretersFor (Stops (err ': errs)) r Source # |
resumeReport :: forall eff e r a. Reportable e => Members [eff !! e, Stop Report] r => Sem (eff ': r) a -> Sem r a Source #
Convert the effect eff
to
and Resumable
err eff
if Stop
Report
err
is an instance of Reportable
.
class ResumeReports (effs :: EffectRow) (errs :: [Type]) (r :: EffectRow) where Source #
Resume multiple effects as Report
s.
resumeReports :: InterpretersFor effs r Source #
Resume multiple effects as Report
s.
This needs both effects and errors specified as type applications (though only the shape for the errors).
resumeReports @[Rpc, Settings] @[_, _]
Instances
ResumeReports ('[] :: [Effect]) ('[] :: [Type]) r Source # | |
Defined in Ribosome.Host.Data.Report resumeReports :: InterpretersFor '[] r Source # | |
(Reportable err, ResumeReports effs errs r, Members '[eff !! err, Stop Report] (effs ++ r)) => ResumeReports (eff ': effs) (err ': errs) r Source # | |
Defined in Ribosome.Host.Data.Report resumeReports :: InterpretersFor (eff ': effs) r Source # |
reportMessages :: Report -> Text Source #
Extract both user and log messages from an Report
, for use in tests.
userReport :: forall e. Reportable e => e -> Text Source #
Extract the user message from an instance of Reportable
.
resumeHoistUserMessage :: forall err eff err' r. Reportable err => Members [eff !! err, Stop err'] r => (Text -> err') -> InterpreterFor eff r Source #
Resume an effect with an error that's an instance of Reportable
by passing its user message to a function.
mapUserMessage :: forall err err' r. Reportable err => Member (Stop err') r => (Text -> err') -> InterpreterFor (Stop err) r Source #
Map an error that's an instance of Reportable
by passing its user message to a function.
stopReportToFail :: forall e r. Member Fail r => Reportable e => InterpreterFor (Stop e) r Source #
Convert an error that's an instance of Reportable
to Fail
, for use in tests.
resumeReportFail :: forall eff err r. Members [Fail, eff !! err] r => Reportable err => InterpreterFor eff r Source #
Resume an effect with an error that's an instance of Reportable
by reinterpreting to Fail
, for use in tests.