| 1 |
use crate::{ |
| 2 |
DynamicRegistrationClientCapabilities, Range, StaticRegistrationOptions, |
| 3 |
TextDocumentIdentifier, TextDocumentRegistrationOptions, WorkDoneProgressOptions, |
| 4 |
WorkDoneProgressParams, |
| 5 |
}; |
| 6 |
use serde::{Deserialize, Serialize}; |
| 7 |
|
| 8 |
pub type InlineValueClientCapabilities = DynamicRegistrationClientCapabilities; |
| 9 |
|
| 10 |
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 11 |
#[serde(untagged)] |
| 12 |
pub enum InlineValueServerCapabilities { |
| 13 |
Options(InlineValueOptions), |
| 14 |
RegistrationOptions(InlineValueRegistrationOptions), |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 21 |
pub struct InlineValueOptions { |
| 22 |
#[serde(flatten)] |
| 23 |
pub work_done_progress_options: WorkDoneProgressOptions, |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 30 |
pub struct InlineValueRegistrationOptions { |
| 31 |
#[serde(flatten)] |
| 32 |
pub inline_value_options: InlineValueOptions, |
| 33 |
|
| 34 |
#[serde(flatten)] |
| 35 |
pub text_document_registration_options: TextDocumentRegistrationOptions, |
| 36 |
|
| 37 |
#[serde(flatten)] |
| 38 |
pub static_registration_options: StaticRegistrationOptions, |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 45 |
#[serde(rename_all = "camelCase")] |
| 46 |
pub struct InlineValueParams { |
| 47 |
#[serde(flatten)] |
| 48 |
pub work_done_progress_params: WorkDoneProgressParams, |
| 49 |
|
| 50 |
|
| 51 |
pub text_document: TextDocumentIdentifier, |
| 52 |
|
| 53 |
|
| 54 |
pub range: Range, |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
pub context: InlineValueContext, |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 63 |
#[serde(rename_all = "camelCase")] |
| 64 |
pub struct InlineValueContext { |
| 65 |
|
| 66 |
pub frame_id: i32, |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
pub stopped_location: Range, |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 78 |
pub struct InlineValueText { |
| 79 |
|
| 80 |
pub range: Range, |
| 81 |
|
| 82 |
|
| 83 |
pub text: String, |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 95 |
#[serde(rename_all = "camelCase")] |
| 96 |
pub struct InlineValueVariableLookup { |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
pub range: Range, |
| 101 |
|
| 102 |
|
| 103 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 104 |
pub variable_name: Option<String>, |
| 105 |
|
| 106 |
|
| 107 |
pub case_sensitive_lookup: bool, |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 119 |
#[serde(rename_all = "camelCase")] |
| 120 |
pub struct InlineValueEvaluatableExpression { |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
pub range: Range, |
| 125 |
|
| 126 |
|
| 127 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 128 |
pub expression: Option<String>, |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] |
| 140 |
#[serde(untagged)] |
| 141 |
pub enum InlineValue { |
| 142 |
Text(InlineValueText), |
| 143 |
VariableLookup(InlineValueVariableLookup), |
| 144 |
EvaluatableExpression(InlineValueEvaluatableExpression), |
| 145 |
} |
| 146 |
|
| 147 |
impl From<InlineValueText> for InlineValue { |
| 148 |
#[inline] |
| 149 |
fn from(from: InlineValueText) -> Self { |
| 150 |
Self::Text(from) |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
impl From<InlineValueVariableLookup> for InlineValue { |
| 155 |
#[inline] |
| 156 |
fn from(from: InlineValueVariableLookup) -> Self { |
| 157 |
Self::VariableLookup(from) |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
impl From<InlineValueEvaluatableExpression> for InlineValue { |
| 162 |
#[inline] |
| 163 |
fn from(from: InlineValueEvaluatableExpression) -> Self { |
| 164 |
Self::EvaluatableExpression(from) |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] |
| 170 |
|
| 171 |
|
| 172 |
#[serde(rename_all = "camelCase")] |
| 173 |
pub struct InlineValueWorkspaceClientCapabilities { |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 182 |
pub refresh_support: Option<bool>, |
| 183 |
} |
| 184 |
|
| 185 |
#[cfg(test)] |
| 186 |
mod tests { |
| 187 |
use super::*; |
| 188 |
use crate::tests::test_serialization; |
| 189 |
use crate::Position; |
| 190 |
|
| 191 |
#[test] |
| 192 |
fn inline_values() { |
| 193 |
test_serialization( |
| 194 |
&InlineValueText { |
| 195 |
range: Range::new(Position::new(0, 0), Position::new(0, 4)), |
| 196 |
text: "one".to_owned(), |
| 197 |
}, |
| 198 |
r#"{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":4}},"text":"one"}"#, |
| 199 |
); |
| 200 |
|
| 201 |
test_serialization( |
| 202 |
&InlineValue::VariableLookup(InlineValueVariableLookup { |
| 203 |
range: Range::new(Position::new(1, 0), Position::new(1, 4)), |
| 204 |
variable_name: None, |
| 205 |
case_sensitive_lookup: false, |
| 206 |
}), |
| 207 |
r#"{"range":{"start":{"line":1,"character":0},"end":{"line":1,"character":4}},"caseSensitiveLookup":false}"#, |
| 208 |
); |
| 209 |
|
| 210 |
test_serialization( |
| 211 |
&InlineValue::EvaluatableExpression(InlineValueEvaluatableExpression { |
| 212 |
range: Range::new(Position::new(2, 0), Position::new(2, 4)), |
| 213 |
expression: None, |
| 214 |
}), |
| 215 |
r#"{"range":{"start":{"line":2,"character":0},"end":{"line":2,"character":4}}}"#, |
| 216 |
); |
| 217 |
} |
| 218 |
} |