Debian Codegraph @

helix-lsp-types/src/document_diagnostic.rs

raw symbols SCIP
1 use std::{collections::HashMap, sync::Arc};
2
3 use serde::{Deserialize, Serialize};
4
5 use crate::{
6 Diagnostic, PartialResultParams, StaticRegistrationOptions, TextDocumentIdentifier,
7 TextDocumentRegistrationOptions, Url, WorkDoneProgressOptions, WorkDoneProgressParams,
8 };
9
10 /// Client capabilities specific to diagnostic pull requests.
11 ///
12 /// @since 3.17.0
13 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
14 #[serde(rename_all = "camelCase")]
15 pub struct DiagnosticClientCapabilities {
16 /// Whether implementation supports dynamic registration.
17 ///
18 /// If this is set to `true` the client supports the new `(TextDocumentRegistrationOptions &
19 /// StaticRegistrationOptions)` return value for the corresponding server capability as well.
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub dynamic_registration: Option<bool>,
22
23 /// Whether the clients supports related documents for document diagnostic pulls.
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub related_document_support: Option<bool>,
26 }
27
28 /// Diagnostic options.
29 ///
30 /// @since 3.17.0
31 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
32 #[serde(rename_all = "camelCase")]
33 pub struct DiagnosticOptions {
34 /// An optional identifier under which the diagnostics are
35 /// managed by the client.
36 #[serde(
37 default,
38 skip_serializing_if = "Option::is_none",
39 serialize_with = "serialize_option_arc_str",
40 deserialize_with = "deserialize_option_arc_str"
41 )]
42 pub identifier: Option<Arc<str>>,
43
44 /// Whether the language has inter file dependencies, meaning that editing code in one file can
45 /// result in a different diagnostic set in another file. Inter file dependencies are common
46 /// for most programming languages and typically uncommon for linters.
47 pub inter_file_dependencies: bool,
48
49 /// The server provides support for workspace diagnostics as well.
50 pub workspace_diagnostics: bool,
51
52 #[serde(flatten)]
53 pub work_done_progress_options: WorkDoneProgressOptions,
54 }
55
56 fn serialize_option_arc_str<S: serde::Serializer>(
57 val: &Option<Arc<str>>,
58 serializer: S,
59 ) -> Result<S::Ok, S::Error> {
60 serializer.serialize_str(val.as_ref().unwrap())
61 }
62
63 fn deserialize_option_arc_str<'de, D: serde::Deserializer<'de>>(
64 deserializer: D,
65 ) -> Result<Option<Arc<str>>, D::Error> {
66 Option::<String>::deserialize(deserializer).map(|opt| opt.map(|s| s.into()))
67 }
68
69 /// Diagnostic registration options.
70 ///
71 /// @since 3.17.0
72 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
73 #[serde(rename_all = "camelCase")]
74 pub struct DiagnosticRegistrationOptions {
75 #[serde(flatten)]
76 pub text_document_registration_options: TextDocumentRegistrationOptions,
77
78 #[serde(flatten)]
79 pub diagnostic_options: DiagnosticOptions,
80
81 #[serde(flatten)]
82 pub static_registration_options: StaticRegistrationOptions,
83 }
84
85 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
86 #[serde(untagged)]
87 pub enum DiagnosticServerCapabilities {
88 Options(DiagnosticOptions),
89 RegistrationOptions(DiagnosticRegistrationOptions),
90 }
91
92 /// Parameters of the document diagnostic request.
93 ///
94 /// @since 3.17.0
95 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
96 #[serde(rename_all = "camelCase")]
97 pub struct DocumentDiagnosticParams {
98 /// The text document.
99 pub text_document: TextDocumentIdentifier,
100
101 /// The additional identifier provided during registration.
102 #[serde(
103 default,
104 skip_serializing_if = "Option::is_none",
105 serialize_with = "serialize_option_arc_str",
106 deserialize_with = "deserialize_option_arc_str"
107 )]
108 pub identifier: Option<Arc<str>>,
109
110 /// The result ID of a previous response if provided.
111 #[serde(skip_serializing_if = "Option::is_none")]
112 pub previous_result_id: Option<String>,
113
114 #[serde(flatten)]
115 pub work_done_progress_params: WorkDoneProgressParams,
116
117 #[serde(flatten)]
118 pub partial_result_params: PartialResultParams,
119 }
120
121 /// A diagnostic report with a full set of problems.
122 ///
123 /// @since 3.17.0
124 #[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
125 #[serde(rename_all = "camelCase")]
126 pub struct FullDocumentDiagnosticReport {
127 /// An optional result ID. If provided it will be sent on the next diagnostic request for the
128 /// same document.
129 #[serde(skip_serializing_if = "Option::is_none")]
130 pub result_id: Option<String>,
131
132 /// The actual items.
133 pub items: Vec<Diagnostic>,
134 }
135
136 /// A diagnostic report indicating that the last returned report is still accurate.
137 ///
138 /// A server can only return `unchanged` if result ids are provided.
139 ///
140 /// @since 3.17.0
141 #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
142 #[serde(rename_all = "camelCase")]
143 pub struct UnchangedDocumentDiagnosticReport {
144 /// A result ID which will be sent on the next diagnostic request for the same document.
145 pub result_id: String,
146 }
147
148 /// The document diagnostic report kinds.
149 ///
150 /// @since 3.17.0
151 #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
152 #[serde(tag = "kind", rename_all = "lowercase")]
153 pub enum DocumentDiagnosticReportKind {
154 /// A diagnostic report with a full set of problems.
155 Full(FullDocumentDiagnosticReport),
156 /// A report indicating that the last returned report is still accurate.
157 Unchanged(UnchangedDocumentDiagnosticReport),
158 }
159
160 impl From<FullDocumentDiagnosticReport> for DocumentDiagnosticReportKind {
161 fn from(from: FullDocumentDiagnosticReport) -> Self {
162 DocumentDiagnosticReportKind::Full(from)
163 }
164 }
165
166 impl From<UnchangedDocumentDiagnosticReport> for DocumentDiagnosticReportKind {
167 fn from(from: UnchangedDocumentDiagnosticReport) -> Self {
168 DocumentDiagnosticReportKind::Unchanged(from)
169 }
170 }
171
172 /// A full diagnostic report with a set of related documents.
173 ///
174 /// @since 3.17.0
175 #[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
176 #[serde(rename_all = "camelCase")]
177 pub struct RelatedFullDocumentDiagnosticReport {
178 /// Diagnostics of related documents.
179 ///
180 /// This information is useful in programming languages where code in a file A can generate
181 /// diagnostics in a file B which A depends on. An example of such a language is C/C++ where
182 /// macro definitions in a file `a.cpp` result in errors in a header file `b.hpp`.
183 ///
184 /// @since 3.17.0
185 #[serde(with = "crate::url_map")]
186 #[serde(skip_serializing_if = "Option::is_none")]
187 #[serde(default)]
188 pub related_documents: Option<HashMap<Url, DocumentDiagnosticReportKind>>,
189 // relatedDocuments?: { [uri: string]: FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport; };
190 #[serde(flatten)]
191 pub full_document_diagnostic_report: FullDocumentDiagnosticReport,
192 }
193
194 /// An unchanged diagnostic report with a set of related documents.
195 ///
196 /// @since 3.17.0
197 #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
198 #[serde(rename_all = "camelCase")]
199 pub struct RelatedUnchangedDocumentDiagnosticReport {
200 /// Diagnostics of related documents.
201 ///
202 /// This information is useful in programming languages where code in a file A can generate
203 /// diagnostics in a file B which A depends on. An example of such a language is C/C++ where
204 /// macro definitions in a file `a.cpp` result in errors in a header file `b.hpp`.
205 ///
206 /// @since 3.17.0
207 #[serde(with = "crate::url_map")]
208 #[serde(skip_serializing_if = "Option::is_none")]
209 #[serde(default)]
210 pub related_documents: Option<HashMap<Url, DocumentDiagnosticReportKind>>,
211 // relatedDocuments?: { [uri: string]: FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport; };
212 #[serde(flatten)]
213 pub unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport,
214 }
215
216 /// The result of a document diagnostic pull request.
217 ///
218 /// A report can either be a full report containing all diagnostics for the requested document or
219 /// an unchanged report indicating that nothing has changed in terms of diagnostics in comparison
220 /// to the last pull request.
221 ///
222 /// @since 3.17.0
223 #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
224 #[serde(tag = "kind", rename_all = "lowercase")]
225 pub enum DocumentDiagnosticReport {
226 /// A diagnostic report with a full set of problems.
227 Full(RelatedFullDocumentDiagnosticReport),
228 /// A report indicating that the last returned report is still accurate.
229 Unchanged(RelatedUnchangedDocumentDiagnosticReport),
230 }
231
232 impl From<RelatedFullDocumentDiagnosticReport> for DocumentDiagnosticReport {
233 fn from(from: RelatedFullDocumentDiagnosticReport) -> Self {
234 DocumentDiagnosticReport::Full(from)
235 }
236 }
237
238 impl From<RelatedUnchangedDocumentDiagnosticReport> for DocumentDiagnosticReport {
239 fn from(from: RelatedUnchangedDocumentDiagnosticReport) -> Self {
240 DocumentDiagnosticReport::Unchanged(from)
241 }
242 }
243
244 /// A partial result for a document diagnostic report.
245 ///
246 /// @since 3.17.0
247 #[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
248 #[serde(rename_all = "camelCase")]
249 pub struct DocumentDiagnosticReportPartialResult {
250 #[serde(with = "crate::url_map")]
251 #[serde(skip_serializing_if = "Option::is_none")]
252 #[serde(default)]
253 pub related_documents: Option<HashMap<Url, DocumentDiagnosticReportKind>>,
254 // relatedDocuments?: { [uri: string]: FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport; };
255 }
256
257 #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
258 #[serde(untagged)]
259 pub enum DocumentDiagnosticReportResult {
260 Report(DocumentDiagnosticReport),
261 Partial(DocumentDiagnosticReportPartialResult),
262 }
263
264 impl From<DocumentDiagnosticReport> for DocumentDiagnosticReportResult {
265 fn from(from: DocumentDiagnosticReport) -> Self {
266 DocumentDiagnosticReportResult::Report(from)
267 }
268 }
269
270 impl From<DocumentDiagnosticReportPartialResult> for DocumentDiagnosticReportResult {
271 fn from(from: DocumentDiagnosticReportPartialResult) -> Self {
272 DocumentDiagnosticReportResult::Partial(from)
273 }
274 }
275
276 /// Cancellation data returned from a diagnostic request.
277 ///
278 /// If no data is provided, it defaults to `{ retrigger_request: true }`.
279 ///
280 /// @since 3.17.0
281 #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
282 #[serde(rename_all = "camelCase")]
283 pub struct DiagnosticServerCancellationData {
284 pub retrigger_request: bool,
285 }
286
287 impl Default for DiagnosticServerCancellationData {
288 fn default() -> Self {
289 DiagnosticServerCancellationData {
290 retrigger_request: true,
291 }
292 }
293 }