Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cider-dap changes #1768

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
PR revisions
  • Loading branch information
root authored and root committed Nov 13, 2023
commit 0fbeb53fad44c28983bd9702fd6f2fcc430b6899
55 changes: 36 additions & 19 deletions cider-dap/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::fs::File;
pub struct MyAdapter {
#[allow(dead_code)]
file: File,
breakpoints: Vec<(Source, i64)>,
breakpoints: Vec<(Source, i64)>, //This field is a placeholder
break_count: Counter,
threads: Vec<Thread>,
threads: Vec<Thread>, //This field is a placeholder
}

impl MyAdapter {
Expand All @@ -18,7 +18,7 @@ impl MyAdapter {
}
}

//Set breakpoints for adapter
///Set breakpoints for adapter
pub fn set_breakpoint(
&mut self,
path: Source,
Expand All @@ -31,32 +31,25 @@ impl MyAdapter {
for source_point in source {
self.breakpoints.push((path.clone(), source_point.line));
//Create new Breakpoint instance
let breakpoint = Breakpoint {
id: self.break_count.increment().into(),
verified: true,
message: None,
source: Some(path.clone()),
line: None,
column: None,
end_line: None,
end_column: None,
instruction_reference: None,
offset: None,
};
let breakpoint = make_breakpoint(
self.break_count.increment().into(),
true,
Some(path.clone()),
);

out_vec.push(breakpoint);
}

out_vec
}

//Return threads
pub fn get_threads(&self) -> Vec<Thread> {
/// Clone threads
pub fn clone_threads(&self) -> Vec<Thread> {
self.threads.clone()
}
}

//Simple struct used to keep an index of the breakpoints used.
/// Simple struct used to keep an index of the breakpoints used.
pub struct Counter {
value: i64,
}
Expand All @@ -65,10 +58,34 @@ impl Counter {
pub fn new() -> Self {
Counter { value: 0 }
}
//Inc the counter, return the OLD value

/// Increment the counter by 1 and return the OLD value
pub fn increment(&mut self) -> i64 {
let out = self.value;
self.value += 1;
out
}
}

/// Returns a Breakpoint object.
///
/// This function takes in relevant fields in Breakpoint that are used
/// by the adapter. This is subject to change.
pub fn make_breakpoint(
id: Option<i64>,
verified: bool,
source: Option<Source>,
) -> Breakpoint {
Breakpoint {
id,
verified,
message: None,
source,
line: None,
column: None,
end_line: None,
end_column: None,
instruction_reference: None,
offset: None,
}
}
2 changes: 1 addition & 1 deletion cider-dap/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dap::requests::Command;

#[allow(dead_code)] // remove this later
#[derive(thiserror::Error, Debug)]
pub enum MyAdapterError{
pub enum MyAdapterError {
/// Represents an unhandled command error.
#[error("Unhandled command: {0:?}")]
UnhandledCommandError(Command),
Expand Down
2 changes: 1 addition & 1 deletion cider-dap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn run_server<R: Read, W: Write>(
//Retrieve a list of all threads
Command::Threads => {
let rsp = req.success(ResponseBody::Threads(ThreadsResponse {
threads: adapter.get_threads(),
threads: adapter.clone_threads(),
}));
server.respond(rsp)?;
}
Expand Down
Loading