diff --git a/src/Error/Diagnose/Diagnostic.hs b/src/Error/Diagnose/Diagnostic.hs index 8774437..89617b6 100644 --- a/src/Error/Diagnose/Diagnostic.hs +++ b/src/Error/Diagnose/Diagnostic.hs @@ -23,8 +23,10 @@ import Error.Diagnose.Diagnostic.Internal as Export def, errorsToWarnings, hasReports, + reportsOf, prettyDiagnostic, printDiagnostic, warningsToErrors, ) +import Error.Diagnose.Report as Export (markersOf) import System.IO as Export (stderr, stdout) diff --git a/src/Error/Diagnose/Diagnostic/Internal.hs b/src/Error/Diagnose/Diagnostic/Internal.hs index 407fe82..7e59379 100644 --- a/src/Error/Diagnose/Diagnostic/Internal.hs +++ b/src/Error/Diagnose/Diagnostic/Internal.hs @@ -72,6 +72,10 @@ hasReports :: Diagnostic msg -> Bool hasReports (Diagnostic DL.Nil _) = False hasReports _ = True +-- | Retrieves the reports for this diagnostic. +reportsOf :: Diagnostic msg -> [Report msg] +reportsOf (Diagnostic reports _) = toList reports + -- | Transforms every warning report in this diagnostic into an error report. warningsToErrors :: Diagnostic msg -> Diagnostic msg warningsToErrors (Diagnostic reports files) = Diagnostic (warningToError <$> reports) files diff --git a/src/Error/Diagnose/Report.hs b/src/Error/Diagnose/Report.hs index 42d4dca..96cee1b 100644 --- a/src/Error/Diagnose/Report.hs +++ b/src/Error/Diagnose/Report.hs @@ -11,4 +11,4 @@ module Error.Diagnose.Report ) where -import Error.Diagnose.Report.Internal as Export (Marker (..), Note (..), Report, err, errorToWarning, warn, warningToError) +import Error.Diagnose.Report.Internal as Export (Marker (..), Note (..), Report, err, errorToWarning, warn, warningToError, markersOf) diff --git a/src/Error/Diagnose/Report/Internal.hs b/src/Error/Diagnose/Report/Internal.hs index 8496557..8d0a0af 100644 --- a/src/Error/Diagnose/Report/Internal.hs +++ b/src/Error/Diagnose/Report/Internal.hs @@ -95,6 +95,11 @@ instance ToJSON msg => ToJSON (Report msg) where ] #endif +-- | Retrieves the markers for this reports, along with their corresponding +-- positions in the source code. +markersOf :: Report msg -> [(Position, Marker msg)] +markersOf (Report _ _ _ markers _) = markers + -- | The type of markers with abstract message type, shown under code lines. data Marker msg = -- | A red or yellow marker under source code, marking important parts of the code.