Debian Codegraph @

LspCpp/include/LibLsp/lsp/lsp_diagnostic.h

raw
1 #pragma once
2 #include <optional>
3 #include "lsRange.h"
4 #include "lsTextEdit.h"
5 #include "lsDocumentUri.h"
6
7 #include "lsResponseError.h"
8 #include "location_type.h"
9
10 #include "LibLsp/JsonRpc/RequestInMessage.h"
11 #include "LibLsp/JsonRpc/lsResponseMessage.h"
12
13 enum class lsDiagnosticSeverity
14 {
15 // Reports an error.
16 Error = 1,
17 // Reports a warning.
18 Warning = 2,
19 // Reports an information.
20 Information = 3,
21 // Reports a hint.
22 Hint = 4
23 };
24 MAKE_REFLECT_TYPE_PROXY(lsDiagnosticSeverity);
25
26 /**
27 * The diagnostic tags.
28 *
29 * @since 3.15.0
30 */
31 enum class DiagnosticTag : uint8_t
32 {
33
34 /**
35 * Unused or unnecessary code.
36 *
37 * Clients are allowed to render diagnostics with this tag faded out instead of having
38 * an error squiggle.
39 */
40 Unnecessary = (1),
41
42 /**
43 * Deprecated or obsolete code.
44 *
45 * Clients are allowed to rendered diagnostics with this tag strike through.
46 */
47 Deprecated = (2),
48 };
49 MAKE_REFLECT_TYPE_PROXY(DiagnosticTag);
50
51 /**
52 * Represents a related message and source code location for a diagnostic. This should be
53 * used to point to code locations that cause or related to a diagnostics, e.g when duplicating
54 * a symbol in a scope.
55 *
56 * Since 3.7.0
57 */
58
59 struct DiagnosticRelatedInformation
60 {
61 /**
62 * The location of this related diagnostic information.
63 */
64
65 lsLocation location;
66
67 /**
68 * The message of this related diagnostic information.
69 */
70
71 std::string message;
72
73 MAKE_SWAP_METHOD(DiagnosticRelatedInformation, location, message)
74 };
75 MAKE_REFLECT_STRUCT(DiagnosticRelatedInformation, location, message)
76 /**
77 * Structure to capture a description for an error code.
78 *
79 * @since 3.16.0
80 */
81 struct DiagnosticCodeDescription
82 {
83 /**
84 * An URI to open with more information about the diagnostic error.
85 */
86 std::string href;
87 MAKE_SWAP_METHOD(DiagnosticCodeDescription, href)
88 };
89 MAKE_REFLECT_STRUCT(DiagnosticCodeDescription, href)
90
91 //Represents a diagnostic, such as a compiler error or warning.Diagnostic objects are only valid in the scope of a resource.
92 struct lsDiagnostic
93 {
94 // The range at which the message applies.
95 lsRange range;
96
97 // The diagnostic's severity. Can be omitted. If omitted it is up to the
98 // client to interpret diagnostics as error, warning, info or hint.
99 optional<lsDiagnosticSeverity> severity;
100
101 // The diagnostic's code. Can be omitted.
102 optional<std::pair<optional<std::string>, optional<int>>> code;
103
104 optional<DiagnosticCodeDescription> codeDescription;
105 // A human-readable string describing the source of this
106 // diagnostic, e.g. 'typescript' or 'super lint'.
107 optional<std::string> source;
108
109 // The diagnostic's message.
110 std::string message;
111
112 // Non-serialized set of fixits.
113 std::vector<lsTextEdit> fixits_;
114
115 /**
116 * Additional metadata about the diagnostic.
117 *
118 * @since 3.15.0
119 */
120 optional<std::vector<DiagnosticTag>> tags;
121
122 /**
123 * An array of related diagnostic information, e.g. when symbol-names within a scope collide
124 * all definitions can be marked via this property.
125 *
126 * Since 3.7.0
127 */
128 optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
129
130 /**
131 * A data entry field that is preserved between a
132 * `textDocument/publishDiagnostics` notification and
133 * `textDocument/codeAction` request.
134 *
135 * @since 3.16.0
136 */
137 optional<lsp::Any> data;
138 bool operator==(lsDiagnostic const& rhs) const;
139 bool operator!=(lsDiagnostic const& rhs) const;
140
141 MAKE_SWAP_METHOD(lsDiagnostic, range, severity, code, codeDescription, source, message, tags, data)
142 };
143 MAKE_REFLECT_STRUCT(lsDiagnostic, range, severity, code, codeDescription, source, message, tags, data)
144
145 struct Rsp_Error : ResponseError<lsResponseError, Rsp_Error>
146 {
147
148 MAKE_SWAP_METHOD(Rsp_Error, jsonrpc, id, error)
149 };
150 MAKE_REFLECT_STRUCT(Rsp_Error, jsonrpc, id, error)