Debian Codegraph @

LspCpp/include/LibLsp/JsonRpc/MessageIssue.h

raw
1 #pragma once
2 #include <string>
3 #include <functional>
4 #include <vector>
5 namespace lsp
6 {
7 class Log
8 {
9 public:
10 virtual ~Log() = default;
11
12 enum class Level
13 {
14 /**
15 * OFF is a special level that can be used to turn off logging.
16
17 */
18 OFF = 0,
19
20 /**
21 * SEVERE is a message level indicating a serious failure.
22 * <p>
23 * In general SEVERE messages should describe events that are
24 * of considerable importance and which will prevent normal
25 * program execution. They should be reasonably intelligible
26 * to end users and to system administrators.
27
28 */
29 SEVERE = 1,
30
31 /**
32 * WARNING is a message level indicating a potential problem.
33 * <p>
34 * In general WARNING messages should describe events that will
35 * be of interest to end users or system managers, or which
36 * indicate potential problems.
37
38 *
39 */
40 WARNING = 2,
41 /**
42 * INFO is a message level for informational messages.
43 * <p>
44 * Typically INFO messages will be written to the console
45 * or its equivalent. So the INFO level should only be
46 * used for reasonably significant messages that will
47 * make sense to end users and system administrators.
48
49 */
50 INFO = 3,
51 /**
52 * CONFIG is a message level for static configuration messages.
53 * <p>
54 * CONFIG messages are intended to provide a variety of static
55 * configuration information, to assist in debugging problems
56 * that may be associated with particular configurations.
57 * For example, CONFIG message might include the CPU type,
58 * the graphics depth, the GUI look-and-feel, etc.
59 * This level is initialized to <CODE>4</CODE>.
60 */
61
62 CONFIG = 4,
63
64 /**
65 * FINE is a message level providing tracing information.
66 * <p>
67 * All of FINE, FINER, and FINEST are intended for relatively
68 * detailed tracing. The exact meaning of the three levels will
69 * vary between subsystems, but in general, FINEST should be used
70 * for the most voluminous detailed output, FINER for somewhat
71 * less detailed output, and FINE for the lowest volume (and
72 * most important) messages.
73 * <p>
74 * In general the FINE level should be used for information
75 * that will be broadly interesting to developers who do not have
76 * a specialized interest in the specific subsystem.
77 * <p>
78 * FINE messages might include things like minor (recoverable)
79 * failures. Issues indicating potential performance problems
80 * are also worth logging as FINE.
81 * This level is initialized to <CODE>5</CODE>.
82 */
83 FINE = 5,
84
85 /**
86 * FINER indicates a fairly detailed tracing message.
87 * By default logging calls for entering, returning, or throwing
88 * an exception are traced at this level.
89 * This level is initialized to <CODE>400</CODE>.
90 */
91 FINER = 6,
92
93 /**
94 * FINEST indicates a highly detailed tracing message.
95 * This level is initialized to <CODE>300</CODE>.
96 */
97 FINEST = 7,
98
99 /**
100 * ALL indicates that all messages should be logged.
101 * This level is initialized to <CODE>Integer.MIN_VALUE</CODE>.
102 */
103 ALL,
104 };
105 virtual void log(Level level, std::wstring&& msg) = 0;
106 virtual void log(Level level, std::wstring const& msg) = 0;
107 virtual void log(Level level, std::string&& msg) = 0;
108 virtual void log(Level level, std::string const& msg) = 0;
109
110 void info(std::string const& msg)
111 {
112 log(Level::INFO, msg);
113 }
114 void info(std::wstring const& msg)
115 {
116 log(Level::INFO, msg);
117 }
118 void error(std::string const& msg)
119 {
120 log(Level::SEVERE, msg);
121 }
122 void error(std::wstring const& msg)
123 {
124 log(Level::SEVERE, msg);
125 }
126 void warning(std::string const& msg)
127 {
128 log(Level::WARNING, msg);
129 }
130 void warning(std::wstring const& msg)
131 {
132 log(Level::WARNING, msg);
133 }
134 };
135 } // namespace lsp
136
137 class MessageIssue
138 {
139
140 public:
141 std::string text;
142
143 lsp::Log::Level code;
144
145 MessageIssue(std::string const& text, lsp::Log::Level code) : text(text), code(code)
146 {
147 }
148 MessageIssue(std::string&& text, lsp::Log::Level code) : text(text), code(code)
149 {
150 }
151
152 std::string getText()
153 {
154 return text;
155 }
156
157 lsp::Log::Level getIssueCode()
158 {
159 return code;
160 }
161
162 std::string toString()
163 {
164 return getText();
165 }
166 };
167 class MessageIssueHandler
168 {
169 public:
170 /**
171 * Handle issues found while parsing or validating a message. The list of issues must not be empty.
172 */
173 virtual ~MessageIssueHandler() = default;
174
175 virtual void handle(std::vector<MessageIssue>&&) = 0;
176 virtual void handle(MessageIssue&&) = 0;
177 };