| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 14 |
#[serde(rename_all = "camelCase")] |
| 15 |
pub struct DiagnosticClientCapabilities { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 21 |
pub dynamic_registration: Option<bool>, |
| 22 |
|
| 23 |
|
| 24 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 25 |
pub related_document_support: Option<bool>, |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 32 |
#[serde(rename_all = "camelCase")] |
| 33 |
pub struct DiagnosticOptions { |
| 34 |
|
| 35 |
|
| 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 |
|
| 45 |
|
| 46 |
|
| 47 |
pub inter_file_dependencies: bool, |
| 48 |
|
| 49 |
|
| 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 |
|
| 70 |
|
| 71 |
|
| 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 |
|
| 93 |
|
| 94 |
|
| 95 |
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 96 |
#[serde(rename_all = "camelCase")] |
| 97 |
pub struct DocumentDiagnosticParams { |
| 98 |
|
| 99 |
pub text_document: TextDocumentIdentifier, |
| 100 |
|
| 101 |
|
| 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 |
|
| 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 |
|
| 122 |
|
| 123 |
|
| 124 |
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)] |
| 125 |
#[serde(rename_all = "camelCase")] |
| 126 |
pub struct FullDocumentDiagnosticReport { |
| 127 |
|
| 128 |
|
| 129 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 130 |
pub result_id: Option<String>, |
| 131 |
|
| 132 |
|
| 133 |
pub items: Vec<Diagnostic>, |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)] |
| 142 |
#[serde(rename_all = "camelCase")] |
| 143 |
pub struct UnchangedDocumentDiagnosticReport { |
| 144 |
|
| 145 |
pub result_id: String, |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)] |
| 152 |
#[serde(tag = "kind", rename_all = "lowercase")] |
| 153 |
pub enum DocumentDiagnosticReportKind { |
| 154 |
|
| 155 |
Full(FullDocumentDiagnosticReport), |
| 156 |
|
| 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 |
|
| 173 |
|
| 174 |
|
| 175 |
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)] |
| 176 |
#[serde(rename_all = "camelCase")] |
| 177 |
pub struct RelatedFullDocumentDiagnosticReport { |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 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 |
|
| 190 |
#[serde(flatten)] |
| 191 |
pub full_document_diagnostic_report: FullDocumentDiagnosticReport, |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)] |
| 198 |
#[serde(rename_all = "camelCase")] |
| 199 |
pub struct RelatedUnchangedDocumentDiagnosticReport { |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 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 |
|
| 212 |
#[serde(flatten)] |
| 213 |
pub unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport, |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)] |
| 224 |
#[serde(tag = "kind", rename_all = "lowercase")] |
| 225 |
pub enum DocumentDiagnosticReport { |
| 226 |
|
| 227 |
Full(RelatedFullDocumentDiagnosticReport), |
| 228 |
|
| 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 |
|
| 245 |
|
| 246 |
|
| 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 |
|
| 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 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 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 |
} |