use crate::{
DynamicRegistrationClientCapabilities, Range, StaticRegistrationOptions,
TextDocumentIdentifier, TextDocumentRegistrationOptions, WorkDoneProgressOptions,
WorkDoneProgressParams,
};
use serde::{Deserialize, Serialize};
pub type InlineValueClientCapabilities = DynamicRegistrationClientCapabilities;
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum InlineValueServerCapabilities {
Options(InlineValueOptions),
RegistrationOptions(InlineValueRegistrationOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct InlineValueOptions {
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct InlineValueRegistrationOptions {
#[serde(flatten)]
pub inline_value_options: InlineValueOptions,
#[serde(flatten)]
pub text_document_registration_options: TextDocumentRegistrationOptions,
#[serde(flatten)]
pub static_registration_options: StaticRegistrationOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineValueParams {
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
pub text_document: TextDocumentIdentifier,
pub range: Range,
pub context: InlineValueContext,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineValueContext {
pub frame_id: i32,
pub stopped_location: Range,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct InlineValueText {
pub range: Range,
pub text: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineValueVariableLookup {
pub range: Range,
#[serde(skip_serializing_if = "Option::is_none")]
pub variable_name: Option<String>,
pub case_sensitive_lookup: bool,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineValueEvaluatableExpression {
pub range: Range,
#[serde(skip_serializing_if = "Option::is_none")]
pub expression: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum InlineValue {
Text(InlineValueText),
VariableLookup(InlineValueVariableLookup),
EvaluatableExpression(InlineValueEvaluatableExpression),
}
impl From<InlineValueText> for InlineValue {
#[inline]
fn from(from: InlineValueText) -> Self {
Self::Text(from)
}
}
impl From<InlineValueVariableLookup> for InlineValue {
#[inline]
fn from(from: InlineValueVariableLookup) -> Self {
Self::VariableLookup(from)
}
}
impl From<InlineValueEvaluatableExpression> for InlineValue {
#[inline]
fn from(from: InlineValueEvaluatableExpression) -> Self {
Self::EvaluatableExpression(from)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineValueWorkspaceClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub refresh_support: Option<bool>,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::test_serialization;
use crate::Position;
#[test]
fn inline_values() {
test_serialization(
&InlineValueText {
range: Range::new(Position::new(0, 0), Position::new(0, 4)),
text: "one".to_owned(),
},
r#"{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":4}},"text":"one"}"#,
);
test_serialization(
&InlineValue::VariableLookup(InlineValueVariableLookup {
range: Range::new(Position::new(1, 0), Position::new(1, 4)),
variable_name: None,
case_sensitive_lookup: false,
}),
r#"{"range":{"start":{"line":1,"character":0},"end":{"line":1,"character":4}},"caseSensitiveLookup":false}"#,
);
test_serialization(
&InlineValue::EvaluatableExpression(InlineValueEvaluatableExpression {
range: Range::new(Position::new(2, 0), Position::new(2, 4)),
expression: None,
}),
r#"{"range":{"start":{"line":2,"character":0},"end":{"line":2,"character":4}}}"#,
);
}
}