Add helper functions for getting Reports & Markers out of Diagnostics

This commit is contained in:
Luc Tielen 2022-08-14 13:20:00 +02:00
parent f8badb4d8c
commit b40f573a0a
4 changed files with 12 additions and 1 deletions

View File

@ -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)

View File

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

View File

@ -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)

View File

@ -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.