Debian Codegraph @

helix-lsp-types/src/inline_value.rs

raw symbols SCIP
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 /// Inline value options used during static registration.
18 ///
19 /// @since 3.17.0
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 /// Inline value options used during static or dynamic registration.
27 ///
28 /// @since 3.17.0
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 /// 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")]
46 pub 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")]
64 pub 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)]
78 pub 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")]
96 pub 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")]
120 pub 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 ///
136 /// The InlineValue types combines all inline value types into one type.
137 ///
138 /// @since 3.17.0
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 /// Client workspace capabilities specific to inline values.
169 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
170 ///
171 /// @since 3.17.0
172 #[serde(rename_all = "camelCase")]
173 pub struct InlineValueWorkspaceClientCapabilities {
174 /// Whether the client implementation supports a refresh request sent from
175 /// the server to the client.
176 ///
177 /// Note that this event is global and will force the client to refresh all
178 /// inline values currently shown. It should be used with absolute care and
179 /// is useful for situation where a server for example detect a project wide
180 /// change that requires such a calculation.
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 }