lsp_types/
document_diagnostic.rs

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