on master help sign in
dap: support getting scopes and variables
commit0fa127b1051ad9af9371a1c9b424921e4f52d066 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateThu 12 Aug 2021, 20:47 (5 years ago) parent7d2d4ed
2 files changed+127−14
helix-dap/examples/dap-basic.rs+12−2 helix-dap/src/client.rs+115−12
helix-dap/examples/dap-basic.rs+12−2
@@ -28,7 +28,7 @@ pub async fn main() -> Result<()> {
2828 .set_breakpoints(
2929 "/tmp/godebug/main.go".to_owned(),
3030 vec![SourceBreakpoint {
31− line: 6,
31+ line: 8,
3232 column: Some(2),
3333 }]
3434 )
@@ -43,7 +43,17 @@ pub async fn main() -> Result<()> {
4343 println!("configurationDone: {:?}", client.configuration_done().await);
4444 println!("stopped: {:?}", client.wait_for_stopped().await);
4545 println!("threads: {:#?}", client.threads().await);
46− println!("stack trace: {:#?}", client.stack_trace(1).await);
46+ let bt = client.stack_trace(1).await.expect("expected stack trace");
47+ println!("stack trace: {:#?}", bt);
48+ let scopes = client
49+ .scopes(bt.0[0].id)
50+ .await
51+ .expect("expected scopes for thread");
52+ println!("scopes: {:#?}", scopes);
53+ println!(
54+ "vars: {:#?}",
55+ client.variables(scopes[1].variables_reference).await
56+ );
4757
4858 let mut _in = String::new();
4959 std::io::stdin()
helix-dap/src/client.rs+115−12
@@ -128,17 +128,17 @@ struct StackTraceArguments {
128128#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
129129#[serde(rename_all = "camelCase")]
130130pub struct StackFrame {
131− id: usize,
132− name: String,
133− source: Option<Source>,
134− line: usize,
135− column: usize,
136− end_line: Option<usize>,
137− end_column: Option<usize>,
138− can_restart: Option<bool>,
139− instruction_pointer_reference: Option<String>,
131+ pub id: usize,
132+ pub name: String,
133+ pub source: Option<Source>,
134+ pub line: usize,
135+ pub column: usize,
136+ pub end_line: Option<usize>,
137+ pub end_column: Option<usize>,
138+ pub can_restart: Option<bool>,
139+ pub instruction_pointer_reference: Option<String>,
140140 // module_id
141− presentation_hint: Option<String>,
141+ pub presentation_hint: Option<String>,
142142}
143143
144144#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
@@ -151,8 +151,8 @@ struct StackTraceResponseBody {
151151#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
152152#[serde(rename_all = "camelCase")]
153153pub struct Thread {
154− id: usize,
155− name: String,
154+ pub id: usize,
155+ pub name: String,
156156}
157157
158158#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
@@ -161,6 +161,79 @@ struct ThreadsResponseBody {
161161 threads: Vec<Thread>,
162162}
163163
164+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
165+#[serde(rename_all = "camelCase")]
166+struct ScopesArguments {
167+ frame_id: usize,
168+}
169+
170+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
171+#[serde(rename_all = "camelCase")]
172+pub struct Scope {
173+ pub name: String,
174+ pub presentation_hint: Option<String>,
175+ pub variables_reference: usize,
176+ pub named_variables: Option<usize>,
177+ pub indexed_variables: Option<usize>,
178+ pub expensive: bool,
179+ pub source: Option<Source>,
180+ pub line: Option<usize>,
181+ pub column: Option<usize>,
182+ pub end_line: Option<usize>,
183+ pub end_column: Option<usize>,
184+}
185+
186+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
187+#[serde(rename_all = "camelCase")]
188+struct ScopesResponseBody {
189+ scopes: Vec<Scope>,
190+}
191+
192+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
193+#[serde(rename_all = "camelCase")]
194+struct ValueFormat {
195+ hex: Option<bool>,
196+}
197+
198+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
199+#[serde(rename_all = "camelCase")]
200+struct VariablesArguments {
201+ variables_reference: usize,
202+ filter: Option<String>,
203+ start: Option<usize>,
204+ count: Option<usize>,
205+ format: Option<ValueFormat>,
206+}
207+
208+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
209+#[serde(rename_all = "camelCase")]
210+pub struct VariablePresentationHint {
211+ pub kind: Option<String>,
212+ pub attributes: Option<Vec<String>>,
213+ pub visibility: Option<String>,
214+}
215+
216+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
217+#[serde(rename_all = "camelCase")]
218+pub struct Variable {
219+ pub name: String,
220+ pub value: String,
221+ #[serde(rename = "type")]
222+ pub data_type: Option<String>,
223+ pub presentation_hint: Option<VariablePresentationHint>,
224+ pub evaluate_name: Option<String>,
225+ pub variables_reference: usize,
226+ pub named_variables: Option<usize>,
227+ pub indexed_variables: Option<usize>,
228+ pub memory_reference: Option<String>,
229+}
230+
231+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
232+#[serde(rename_all = "camelCase")]
233+struct VariablesResponseBody {
234+ variables: Vec<Variable>,
235+}
236+
164237#[derive(Debug)]
165238pub struct Client {
166239 id: usize,
@@ -370,4 +443,34 @@ impl Client {
370443
371444 Ok(body.threads)
372445 }
446+
447+ pub async fn scopes(&mut self, frame_id: usize) -> Result<Vec<Scope>> {
448+ let args = ScopesArguments { frame_id };
449+
450+ let response = self
451+ .request("scopes".to_owned(), to_value(args).ok())
452+ .await?;
453+
454+ let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
455+
456+ Ok(body.scopes)
457+ }
458+
459+ pub async fn variables(&mut self, variables_reference: usize) -> Result<Vec<Variable>> {
460+ let args = VariablesArguments {
461+ variables_reference,
462+ filter: None,
463+ start: None,
464+ count: None,
465+ format: None,
466+ };
467+
468+ let response = self
469+ .request("variables".to_owned(), to_value(args).ok())
470+ .await?;
471+
472+ let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
473+
474+ Ok(body.variables)
475+ }
373476}