dap: support getting scopes and variables

pull/574/head
Dmitry Sharshakov 3 years ago committed by Blaž Hrastnik
parent 7d2d4ed4a8
commit 0fa127b105

@ -28,7 +28,7 @@ pub async fn main() -> Result<()> {
.set_breakpoints( .set_breakpoints(
"/tmp/godebug/main.go".to_owned(), "/tmp/godebug/main.go".to_owned(),
vec![SourceBreakpoint { vec![SourceBreakpoint {
line: 6, line: 8,
column: Some(2), column: Some(2),
}] }]
) )
@ -43,7 +43,17 @@ pub async fn main() -> Result<()> {
println!("configurationDone: {:?}", client.configuration_done().await); println!("configurationDone: {:?}", client.configuration_done().await);
println!("stopped: {:?}", client.wait_for_stopped().await); println!("stopped: {:?}", client.wait_for_stopped().await);
println!("threads: {:#?}", client.threads().await); println!("threads: {:#?}", client.threads().await);
println!("stack trace: {:#?}", client.stack_trace(1).await); let bt = client.stack_trace(1).await.expect("expected stack trace");
println!("stack trace: {:#?}", bt);
let scopes = client
.scopes(bt.0[0].id)
.await
.expect("expected scopes for thread");
println!("scopes: {:#?}", scopes);
println!(
"vars: {:#?}",
client.variables(scopes[1].variables_reference).await
);
let mut _in = String::new(); let mut _in = String::new();
std::io::stdin() std::io::stdin()

@ -128,17 +128,17 @@ struct StackTraceArguments {
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct StackFrame { pub struct StackFrame {
id: usize, pub id: usize,
name: String, pub name: String,
source: Option<Source>, pub source: Option<Source>,
line: usize, pub line: usize,
column: usize, pub column: usize,
end_line: Option<usize>, pub end_line: Option<usize>,
end_column: Option<usize>, pub end_column: Option<usize>,
can_restart: Option<bool>, pub can_restart: Option<bool>,
instruction_pointer_reference: Option<String>, pub instruction_pointer_reference: Option<String>,
// module_id // module_id
presentation_hint: Option<String>, pub presentation_hint: Option<String>,
} }
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
@ -151,8 +151,8 @@ struct StackTraceResponseBody {
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Thread { pub struct Thread {
id: usize, pub id: usize,
name: String, pub name: String,
} }
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
@ -161,6 +161,79 @@ struct ThreadsResponseBody {
threads: Vec<Thread>, threads: Vec<Thread>,
} }
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct ScopesArguments {
frame_id: usize,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Scope {
pub name: String,
pub presentation_hint: Option<String>,
pub variables_reference: usize,
pub named_variables: Option<usize>,
pub indexed_variables: Option<usize>,
pub expensive: bool,
pub source: Option<Source>,
pub line: Option<usize>,
pub column: Option<usize>,
pub end_line: Option<usize>,
pub end_column: Option<usize>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct ScopesResponseBody {
scopes: Vec<Scope>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct ValueFormat {
hex: Option<bool>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct VariablesArguments {
variables_reference: usize,
filter: Option<String>,
start: Option<usize>,
count: Option<usize>,
format: Option<ValueFormat>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct VariablePresentationHint {
pub kind: Option<String>,
pub attributes: Option<Vec<String>>,
pub visibility: Option<String>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Variable {
pub name: String,
pub value: String,
#[serde(rename = "type")]
pub data_type: Option<String>,
pub presentation_hint: Option<VariablePresentationHint>,
pub evaluate_name: Option<String>,
pub variables_reference: usize,
pub named_variables: Option<usize>,
pub indexed_variables: Option<usize>,
pub memory_reference: Option<String>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct VariablesResponseBody {
variables: Vec<Variable>,
}
#[derive(Debug)] #[derive(Debug)]
pub struct Client { pub struct Client {
id: usize, id: usize,
@ -370,4 +443,34 @@ impl Client {
Ok(body.threads) Ok(body.threads)
} }
pub async fn scopes(&mut self, frame_id: usize) -> Result<Vec<Scope>> {
let args = ScopesArguments { frame_id };
let response = self
.request("scopes".to_owned(), to_value(args).ok())
.await?;
let body: ScopesResponseBody = from_value(response.body.unwrap()).unwrap();
Ok(body.scopes)
}
pub async fn variables(&mut self, variables_reference: usize) -> Result<Vec<Variable>> {
let args = VariablesArguments {
variables_reference,
filter: None,
start: None,
count: None,
format: None,
};
let response = self
.request("variables".to_owned(), to_value(args).ok())
.await?;
let body: VariablesResponseBody = from_value(response.body.unwrap()).unwrap();
Ok(body.variables)
}
} }

Loading…
Cancel
Save