Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-lsp-types/src/document_diagnostic.rs')
| -rw-r--r-- | helix-lsp-types/src/document_diagnostic.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/helix-lsp-types/src/document_diagnostic.rs b/helix-lsp-types/src/document_diagnostic.rs index 5a1c6b35..d2dcc544 100644 --- a/helix-lsp-types/src/document_diagnostic.rs +++ b/helix-lsp-types/src/document_diagnostic.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; use serde::{Deserialize, Serialize}; @@ -33,8 +33,13 @@ pub struct DiagnosticClientCapabilities { pub struct DiagnosticOptions { /// An optional identifier under which the diagnostics are /// managed by the client. - #[serde(skip_serializing_if = "Option::is_none")] - pub identifier: Option<String>, + #[serde( + default, + skip_serializing_if = "Option::is_none", + serialize_with = "serialize_option_arc_str", + deserialize_with = "deserialize_option_arc_str" + )] + pub identifier: Option<Arc<str>>, /// Whether the language has inter file dependencies, meaning that editing code in one file can /// result in a different diagnostic set in another file. Inter file dependencies are common @@ -48,6 +53,19 @@ pub struct DiagnosticOptions { pub work_done_progress_options: WorkDoneProgressOptions, } +fn serialize_option_arc_str<S: serde::Serializer>( + val: &Option<Arc<str>>, + serializer: S, +) -> Result<S::Ok, S::Error> { + serializer.serialize_str(val.as_ref().unwrap()) +} + +fn deserialize_option_arc_str<'de, D: serde::Deserializer<'de>>( + deserializer: D, +) -> Result<Option<Arc<str>>, D::Error> { + Option::<String>::deserialize(deserializer).map(|opt| opt.map(|s| s.into())) +} + /// Diagnostic registration options. /// /// @since 3.17.0 @@ -81,7 +99,13 @@ pub struct DocumentDiagnosticParams { pub text_document: TextDocumentIdentifier, /// The additional identifier provided during registration. - pub identifier: Option<String>, + #[serde( + default, + skip_serializing_if = "Option::is_none", + serialize_with = "serialize_option_arc_str", + deserialize_with = "deserialize_option_arc_str" + )] + pub identifier: Option<Arc<str>>, /// The result ID of a previous response if provided. pub previous_result_id: Option<String>, |