1use crate::{
2 DynamicRegistrationClientCapabilities, Range, StaticRegistrationOptions,
3 TextDocumentIdentifier, TextDocumentRegistrationOptions, WorkDoneProgressOptions,
4 WorkDoneProgressParams,
5};
6use serde::{Deserialize, Serialize};
7
8pub type InlineValueClientCapabilities = DynamicRegistrationClientCapabilities;
9
10#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
11#[serde(untagged)]
12pub enum InlineValueServerCapabilities {
13 Options(InlineValueOptions),
14 RegistrationOptions(InlineValueRegistrationOptions),
15}
16
17/// Inline value options used during static registration.
18///
19/// @since 3.17.0
20#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
21pub struct InlineValueOptions {
22 #[serde(flatten)]
23 pub work_done_progress_options: WorkDoneProgressOptions,
24}
25
26/// Inline value options used during static or dynamic registration.
27///
28/// @since 3.17.0
29#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
30pub 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/// A parameter literal used in inline value requests.
42///
43/// @since 3.17.0
44#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
45#[serde(rename_all = "camelCase")]
46pub struct InlineValueParams {
47 #[serde(flatten)]
48 pub work_done_progress_params: WorkDoneProgressParams,
49
50 /// The text document.
51 pub text_document: TextDocumentIdentifier,
52
53 /// The document range for which inline values should be computed.
54 pub range: Range,
55
56 /// Additional information about the context in which inline values were
57 /// requested.
58 pub context: InlineValueContext,
59}
60
61/// @since 3.17.0
62#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
63#[serde(rename_all = "camelCase")]
64pub struct InlineValueContext {
65 /// The stack frame (as a DAP Id) where the execution has stopped.
66 pub frame_id: i32,
67
68 /// The document range where execution has stopped.
69 /// Typically the end position of the range denotes the line where the
70 /// inline values are shown.
71 pub stopped_location: Range,
72}
73
74/// Provide inline value as text.
75///
76/// @since 3.17.0
77#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
78pub struct InlineValueText {
79 /// The document range for which the inline value applies.
80 pub range: Range,
81
82 /// The text of the inline value.
83 pub text: String,
84}
85
86/// Provide inline value through a variable lookup.
87///
88/// If only a range is specified, the variable name will be extracted from
89/// the underlying document.
90///
91/// An optional variable name can be used to override the extracted name.
92///
93/// @since 3.17.0
94#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
95#[serde(rename_all = "camelCase")]
96pub struct InlineValueVariableLookup {
97 /// The document range for which the inline value applies.
98 /// The range is used to extract the variable name from the underlying
99 /// document.
100 pub range: Range,
101
102 /// If specified the name of the variable to look up.
103 #[serde(skip_serializing_if = "Option::is_none")]
104 pub variable_name: Option<String>,
105
106 /// How to perform the lookup.
107 pub case_sensitive_lookup: bool,
108}
109
110/// Provide an inline value through an expression evaluation.
111///
112/// If only a range is specified, the expression will be extracted from the
113/// underlying document.
114///
115/// An optional expression can be used to override the extracted expression.
116///
117/// @since 3.17.0
118#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
119#[serde(rename_all = "camelCase")]
120pub struct InlineValueEvaluatableExpression {
121 /// The document range for which the inline value applies.
122 /// The range is used to extract the evaluatable expression from the
123 /// underlying document.
124 pub range: Range,
125
126 /// If specified the expression overrides the extracted expression.
127 #[serde(skip_serializing_if = "Option::is_none")]
128 pub expression: Option<String>,
129}
130
131/// Inline value information can be provided by different means:
132/// - directly as a text value (class InlineValueText).
133/// - as a name to use for a variable lookup (class InlineValueVariableLookup)
134/// - as an evaluatable expression (class InlineValueEvaluatableExpression)
135/// The InlineValue types combines all inline value types into one type.
136///
137/// @since 3.17.0
138#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
139#[serde(untagged)]
140pub enum InlineValue {
141 Text(InlineValueText),
142 VariableLookup(InlineValueVariableLookup),
143 EvaluatableExpression(InlineValueEvaluatableExpression),
144}
145
146impl From<InlineValueText> for InlineValue {
147 #[inline]
148 fn from(from: InlineValueText) -> Self {
149 Self::Text(from)
150 }
151}
152
153impl From<InlineValueVariableLookup> for InlineValue {
154 #[inline]
155 fn from(from: InlineValueVariableLookup) -> Self {
156 Self::VariableLookup(from)
157 }
158}
159
160impl From<InlineValueEvaluatableExpression> for InlineValue {
161 #[inline]
162 fn from(from: InlineValueEvaluatableExpression) -> Self {
163 Self::EvaluatableExpression(from)
164 }
165}
166
167/// Client workspace capabilities specific to inline values.
168#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
169///
170/// @since 3.17.0
171#[serde(rename_all = "camelCase")]
172pub struct InlineValueWorkspaceClientCapabilities {
173 /// Whether the client implementation supports a refresh request sent from
174 /// the server to the client.
175 ///
176 /// Note that this event is global and will force the client to refresh all
177 /// inline values currently shown. It should be used with absolute care and
178 /// is useful for situation where a server for example detect a project wide
179 /// change that requires such a calculation.
180 #[serde(skip_serializing_if = "Option::is_none")]
181 pub refresh_support: Option<bool>,
182}
183
184#[cfg(test)]
185mod tests {
186 use super::*;
187 use crate::tests::test_serialization;
188 use crate::Position;
189
190 #[test]
191 fn inline_values() {
192 test_serialization(
193 &InlineValueText {
194 range: Range::new(Position::new(0, 0), Position::new(0, 4)),
195 text: "one".to_owned(),
196 },
197 r#"{"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":4}},"text":"one"}"#,
198 );
199
200 test_serialization(
201 &InlineValue::VariableLookup(InlineValueVariableLookup {
202 range: Range::new(Position::new(1, 0), Position::new(1, 4)),
203 variable_name: None,
204 case_sensitive_lookup: false,
205 }),
206 r#"{"range":{"start":{"line":1,"character":0},"end":{"line":1,"character":4}},"caseSensitiveLookup":false}"#,
207 );
208
209 test_serialization(
210 &InlineValue::EvaluatableExpression(InlineValueEvaluatableExpression {
211 range: Range::new(Position::new(2, 0), Position::new(2, 4)),
212 expression: None,
213 }),
214 r#"{"range":{"start":{"line":2,"character":0},"end":{"line":2,"character":4}}}"#,
215 );
216 }
217}
218