0 | ||| Logging utilities for the LSP server implementation.
 1 | |||
 2 | ||| (C) The Idris Community, 2023
 3 | module Language.LSP.Severity
 4 |
 5 | import Data.String
 6 |
 7 | %default total
 8 |
 9 | ||| Type for the severity of logging messages.
10 | ||| Levels are roughly categorised as follow:
11 | ||| - Debug    Messages targeted only for developing purposes
12 | ||| - Info     Messages for progress without unexpected behaviour or errors
13 | ||| - Warning  Messages for unsupported requests or wrong configurations
14 | ||| - Error    Messages for either server or compiler error which are unexpected but recoverable
15 | ||| - Critical Messages for error that require immediate stopping of the server
16 | public export
17 | data Severity = Debug | Info | Warning | Error | Critical
18 |
19 | export
20 | parseSeverity : String -> Maybe Severity
21 | parseSeverity str = case toUpper str of
22 |   "DEBUG"    => Just Debug
23 |   "INFO"     => Just Info
24 |   "WARNING"  => Just Warning
25 |   "ERROR"    => Just Error
26 |   "CRITICAL" => Just Critical
27 |   _          => Nothing
28 |
29 | Cast Severity Integer where
30 |   cast Debug    = 0
31 |   cast Info     = 1
32 |   cast Warning  = 2
33 |   cast Error    = 3
34 |   cast Critical = 4
35 |
36 | export
37 | Eq Severity where
38 |   Debug    == Debug    = True
39 |   Info     == Info     = True
40 |   Warning  == Warning  = True
41 |   Error    == Error    = True
42 |   Critical == Critical = True
43 |   _ == _ = False
44 |
45 | export
46 | Show Severity where
47 |   show Debug    = "DEBUG"
48 |   show Info     = "INFO"
49 |   show Warning  = "WARNING"
50 |   show Error    = "ERROR"
51 |   show Critical = "CRITICAL"
52 |
53 | export
54 | Ord Severity where
55 |   compare x y = compare (cast {to = Integer} x) (cast y)
56 |