lsp_types/
workspace_diagnostic.rs

1use serde::{Deserialize, Serialize};
2use url::Url;
3
4use crate::{
5    FullDocumentDiagnosticReport, PartialResultParams, UnchangedDocumentDiagnosticReport,
6    WorkDoneProgressParams,
7};
8
9/// Workspace client capabilities specific to diagnostic pull requests.
10///
11/// @since 3.17.0
12#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
13#[serde(rename_all = "camelCase")]
14pub struct DiagnosticWorkspaceClientCapabilities {
15    /// Whether the client implementation supports a refresh request sent from
16    /// the server to the client.
17    ///
18    /// Note that this event is global and will force the client to refresh all
19    /// pulled diagnostics currently shown. It should be used with absolute care
20    /// and is useful for situation where a server for example detects a project
21    /// wide change that requires such a calculation.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub refresh_support: Option<bool>,
24}
25
26/// A previous result ID in a workspace pull request.
27///
28/// @since 3.17.0
29#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
30pub struct PreviousResultId {
31    /// The URI for which the client knows a result ID.
32    pub uri: Url,
33
34    /// The value of the previous result ID.
35    pub value: String,
36}
37
38/// Parameters of the workspace diagnostic request.
39///
40/// @since 3.17.0
41#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
42#[serde(rename_all = "camelCase")]
43pub struct WorkspaceDiagnosticParams {
44    /// The additional identifier provided during registration.
45    pub identifier: Option<String>,
46
47    /// The currently known diagnostic reports with their
48    /// previous result ids.
49    pub previous_result_ids: Vec<PreviousResultId>,
50
51    #[serde(flatten)]
52    pub work_done_progress_params: WorkDoneProgressParams,
53
54    #[serde(flatten)]
55    pub partial_result_params: PartialResultParams,
56}
57
58/// A full document diagnostic report for a workspace diagnostic result.
59///
60/// @since 3.17.0
61#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
62#[serde(rename_all = "camelCase")]
63pub struct WorkspaceFullDocumentDiagnosticReport {
64    /// The URI for which diagnostic information is reported.
65    pub uri: Url,
66
67    /// The version number for which the diagnostics are reported.
68    ///
69    /// If the document is not marked as open, `None` can be provided.
70    pub version: Option<i64>,
71
72    #[serde(flatten)]
73    pub full_document_diagnostic_report: FullDocumentDiagnosticReport,
74}
75
76/// An unchanged document diagnostic report for a workspace diagnostic result.
77///
78/// @since 3.17.0
79#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
80#[serde(rename_all = "camelCase")]
81pub struct WorkspaceUnchangedDocumentDiagnosticReport {
82    /// The URI for which diagnostic information is reported.
83    pub uri: Url,
84
85    /// The version number for which the diagnostics are reported.
86    ///
87    /// If the document is not marked as open, `None` can be provided.
88    pub version: Option<i64>,
89
90    #[serde(flatten)]
91    pub unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport,
92}
93
94/// A workspace diagnostic document report.
95///
96/// @since 3.17.0
97#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
98#[serde(tag = "kind", rename_all = "lowercase")]
99pub enum WorkspaceDocumentDiagnosticReport {
100    Full(WorkspaceFullDocumentDiagnosticReport),
101    Unchanged(WorkspaceUnchangedDocumentDiagnosticReport),
102}
103
104impl From<WorkspaceFullDocumentDiagnosticReport> for WorkspaceDocumentDiagnosticReport {
105    fn from(from: WorkspaceFullDocumentDiagnosticReport) -> Self {
106        WorkspaceDocumentDiagnosticReport::Full(from)
107    }
108}
109
110impl From<WorkspaceUnchangedDocumentDiagnosticReport> for WorkspaceDocumentDiagnosticReport {
111    fn from(from: WorkspaceUnchangedDocumentDiagnosticReport) -> Self {
112        WorkspaceDocumentDiagnosticReport::Unchanged(from)
113    }
114}
115
116/// A workspace diagnostic report.
117///
118/// @since 3.17.0
119#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
120pub struct WorkspaceDiagnosticReport {
121    pub items: Vec<WorkspaceDocumentDiagnosticReport>,
122}
123
124/// A partial result for a workspace diagnostic report.
125///
126/// @since 3.17.0
127#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
128pub struct WorkspaceDiagnosticReportPartialResult {
129    pub items: Vec<WorkspaceDocumentDiagnosticReport>,
130}
131
132#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
133#[serde(untagged)]
134pub enum WorkspaceDiagnosticReportResult {
135    Report(WorkspaceDiagnosticReport),
136    Partial(WorkspaceDiagnosticReportPartialResult),
137}
138
139impl From<WorkspaceDiagnosticReport> for WorkspaceDiagnosticReportResult {
140    fn from(from: WorkspaceDiagnosticReport) -> Self {
141        WorkspaceDiagnosticReportResult::Report(from)
142    }
143}
144
145impl From<WorkspaceDiagnosticReportPartialResult> for WorkspaceDiagnosticReportResult {
146    fn from(from: WorkspaceDiagnosticReportPartialResult) -> Self {
147        WorkspaceDiagnosticReportResult::Partial(from)
148    }
149}