mirror of
https://github.com/Mesabloo/diagnose.git
synced 2024-11-25 06:16:42 +03:00
Add helper functions for getting Reports & Markers out of Diagnostics
This commit is contained in:
parent
f8badb4d8c
commit
b40f573a0a
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user