use lsp_types::{ClientCapabilities, ResourceOperationKind};
use serde::Deserialize;
macro_rules! try_or_default {
($expr:expr) => {
|| -> Option<_> { Some($expr) }().unwrap_or_default()
};
}
pub trait ClientCapabilitiesExt {
fn did_change_watched_files_dynamic_registration(&self) -> bool;
fn workspace_configuration_support(&self) -> bool;
fn workspace_semantic_tokens_refresh_support(&self) -> bool;
fn workspace_code_lens_refresh_support(&self) -> bool;
fn workspace_edit_rename_resource_support(&self) -> bool;
fn text_document_synchronization_dynamic_registration(&self) -> bool;
fn completion_dynamic_registration(&self) -> bool;
fn execute_command_dynamic_registration(&self) -> bool;
fn semantic_tokens_dynamic_registration(&self) -> bool;
fn formatting_dynamic_registration(&self) -> bool;
fn hover_dynamic_registration(&self) -> bool;
fn definition_dynamic_registration(&self) -> bool;
fn code_action_dynamic_registration(&self) -> bool;
fn references_provider_dynamic_registration(&self) -> bool;
fn rename_provider_dynamic_registration(&self) -> bool;
fn document_highlight_provider_dynamic_registration(&self) -> bool;
fn code_lens_provider_dynamic_registration(&self) -> bool;
fn workspace_will_rename_files_support(&self) -> bool;
fn text_document_inlay_hints_dynamic_registration(&self) -> bool;
fn execute_in_terminal_support(&self) -> bool;
fn launch_debugger_support(&self) -> bool;
}
impl ClientCapabilitiesExt for ClientCapabilities {
fn did_change_watched_files_dynamic_registration(&self) -> bool {
try_or_default!(
self.workspace.as_ref()?.did_change_watched_files.as_ref()?.dynamic_registration?
)
}
fn workspace_configuration_support(&self) -> bool {
try_or_default! {
self.workspace.as_ref()?.configuration?
}
}
fn workspace_semantic_tokens_refresh_support(&self) -> bool {
try_or_default!(self.workspace.as_ref()?.semantic_tokens.as_ref()?.refresh_support?)
}
fn workspace_code_lens_refresh_support(&self) -> bool {
try_or_default!(self.workspace.as_ref()?.code_lens.as_ref()?.refresh_support?)
}
fn workspace_edit_rename_resource_support(&self) -> bool {
try_or_default! {
self.workspace.as_ref()?.workspace_edit.as_ref()?
.resource_operations.as_ref()?.contains(&ResourceOperationKind::Rename)
}
}
fn text_document_synchronization_dynamic_registration(&self) -> bool {
try_or_default!(
self.text_document.as_ref()?.synchronization.as_ref()?.dynamic_registration?
)
}
fn completion_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.completion.as_ref()?.dynamic_registration?)
}
fn execute_command_dynamic_registration(&self) -> bool {
try_or_default!(self.workspace.as_ref()?.execute_command.as_ref()?.dynamic_registration?)
}
fn semantic_tokens_dynamic_registration(&self) -> bool {
try_or_default!(
self.text_document.as_ref()?.semantic_tokens.as_ref()?.dynamic_registration?
)
}
fn formatting_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.formatting.as_ref()?.dynamic_registration?)
}
fn hover_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.hover.as_ref()?.dynamic_registration?)
}
fn definition_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.definition.as_ref()?.dynamic_registration?)
}
fn code_action_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.code_action.as_ref()?.dynamic_registration?)
}
fn references_provider_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.references.as_ref()?.dynamic_registration?)
}
fn rename_provider_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.rename.as_ref()?.dynamic_registration?)
}
fn document_highlight_provider_dynamic_registration(&self) -> bool {
try_or_default!(
self.text_document.as_ref()?.document_highlight.as_ref()?.dynamic_registration?
)
}
fn code_lens_provider_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.code_lens.as_ref()?.dynamic_registration?)
}
fn workspace_will_rename_files_support(&self) -> bool {
try_or_default!(self.workspace.as_ref()?.file_operations.as_ref()?.will_rename?)
}
fn text_document_inlay_hints_dynamic_registration(&self) -> bool {
try_or_default!(self.text_document.as_ref()?.inlay_hint.as_ref()?.dynamic_registration?)
}
fn execute_in_terminal_support(&self) -> bool {
try_or_default!(
serde_json::from_value::<ExperimentalCapabilities>(self.experimental.clone()?)
.ok()?
.cairo?
.execute_in_terminal
.is_some()
)
}
fn launch_debugger_support(&self) -> bool {
try_or_default!(
serde_json::from_value::<ExperimentalCapabilities>(self.experimental.clone()?)
.ok()?
.cairo?
.launch_debugger
.is_some()
)
}
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct ExperimentalCapabilities {
#[serde(default)]
cairo: Option<CairoMethods>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct CairoMethods {
#[serde(default)]
execute_in_terminal: Option<ExecuteInTerminalCapabilities>,
#[serde(default)]
launch_debugger: Option<LaunchDebuggerCapabilities>,
}
#[derive(Deserialize)]
struct ExecuteInTerminalCapabilities {}
#[derive(Deserialize)]
struct LaunchDebuggerCapabilities {}