use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::{
Diagnostic, PartialResultParams, StaticRegistrationOptions, TextDocumentIdentifier,
TextDocumentRegistrationOptions, WorkDoneProgressOptions, WorkDoneProgressParams,
};
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DiagnosticClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub related_document_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DiagnosticOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub identifier: Option<String>,
pub inter_file_dependencies: bool,
pub workspace_diagnostics: bool,
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DiagnosticRegistrationOptions {
#[serde(flatten)]
pub text_document_registration_options: TextDocumentRegistrationOptions,
#[serde(flatten)]
pub diagnostic_options: DiagnosticOptions,
#[serde(flatten)]
pub static_registration_options: StaticRegistrationOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum DiagnosticServerCapabilities {
Options(DiagnosticOptions),
RegistrationOptions(DiagnosticRegistrationOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentDiagnosticParams {
pub text_document: TextDocumentIdentifier,
pub identifier: Option<String>,
pub previous_result_id: Option<String>,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FullDocumentDiagnosticReport {
#[serde(skip_serializing_if = "Option::is_none")]
pub result_id: Option<String>,
pub items: Vec<Diagnostic>,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UnchangedDocumentDiagnosticReport {
pub result_id: String,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum DocumentDiagnosticReportKind {
Full(FullDocumentDiagnosticReport),
Unchanged(UnchangedDocumentDiagnosticReport),
}
impl From<FullDocumentDiagnosticReport> for DocumentDiagnosticReportKind {
fn from(from: FullDocumentDiagnosticReport) -> Self {
DocumentDiagnosticReportKind::Full(from)
}
}
impl From<UnchangedDocumentDiagnosticReport> for DocumentDiagnosticReportKind {
fn from(from: UnchangedDocumentDiagnosticReport) -> Self {
DocumentDiagnosticReportKind::Unchanged(from)
}
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RelatedFullDocumentDiagnosticReport {
#[serde(with = "crate::url_map")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub related_documents: Option<HashMap<Url, DocumentDiagnosticReportKind>>,
#[serde(flatten)]
pub full_document_diagnostic_report: FullDocumentDiagnosticReport,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RelatedUnchangedDocumentDiagnosticReport {
#[serde(with = "crate::url_map")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub related_documents: Option<HashMap<Url, DocumentDiagnosticReportKind>>,
#[serde(flatten)]
pub unchanged_document_diagnostic_report: UnchangedDocumentDiagnosticReport,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum DocumentDiagnosticReport {
Full(RelatedFullDocumentDiagnosticReport),
Unchanged(RelatedUnchangedDocumentDiagnosticReport),
}
impl From<RelatedFullDocumentDiagnosticReport> for DocumentDiagnosticReport {
fn from(from: RelatedFullDocumentDiagnosticReport) -> Self {
DocumentDiagnosticReport::Full(from)
}
}
impl From<RelatedUnchangedDocumentDiagnosticReport> for DocumentDiagnosticReport {
fn from(from: RelatedUnchangedDocumentDiagnosticReport) -> Self {
DocumentDiagnosticReport::Unchanged(from)
}
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DocumentDiagnosticReportPartialResult {
#[serde(with = "crate::url_map")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub related_documents: Option<HashMap<Url, DocumentDiagnosticReportKind>>,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(untagged)]
pub enum DocumentDiagnosticReportResult {
Report(DocumentDiagnosticReport),
Partial(DocumentDiagnosticReportPartialResult),
}
impl From<DocumentDiagnosticReport> for DocumentDiagnosticReportResult {
fn from(from: DocumentDiagnosticReport) -> Self {
DocumentDiagnosticReportResult::Report(from)
}
}
impl From<DocumentDiagnosticReportPartialResult> for DocumentDiagnosticReportResult {
fn from(from: DocumentDiagnosticReportPartialResult) -> Self {
DocumentDiagnosticReportResult::Partial(from)
}
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DiagnosticServerCancellationData {
pub retrigger_request: bool,
}
impl Default for DiagnosticServerCancellationData {
fn default() -> Self {
DiagnosticServerCancellationData {
retrigger_request: true,
}
}
}