Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sztomi/dap-rs
A Rust implementation of the Debug Adapter Protocol
https://github.com/sztomi/dap-rs
debugging debugging-tool framework protocol
Last synced: 9 days ago
JSON representation
A Rust implementation of the Debug Adapter Protocol
- Host: GitHub
- URL: https://github.com/sztomi/dap-rs
- Owner: sztomi
- License: mit
- Created: 2022-10-21T11:34:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-16T16:24:21.000Z (10 months ago)
- Last Synced: 2025-01-16T16:13:51.475Z (16 days ago)
- Topics: debugging, debugging-tool, framework, protocol
- Language: Rust
- Homepage:
- Size: 185 KB
- Stars: 52
- Watchers: 5
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.Apache2.0
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# dap-rs, a Rust implementation of the Debug Adapter Protocol
## Introduction
This crate is a Rust implementation of the [Debug Adapter Protocol][1] (or DAP for short).
The best way to think of DAP is to compare it to [LSP][2] (Language Server Protocol) but
for debuggers. The core idea is the same: a protocol that serves as *lingua franca*
for editors and debuggers to talk to each other. This means that an editor that implements
DAP can use a debugger that also implements DAP.In practice, the adapter might be separate from the actual debugger. For example, one could
implement an adapter that writes commands to the stdin of a gdb subprocess, then parses
the output it receives (this is why it's called an "adapter" - it adapts the debugger to
editors that know DAP).## Stability
This crate is in a fairly early stage and breakages will be frequent. Any version before
1.0 might be a breaking version.## Minimal example
To get started, create a binary project and add `dap` to your Cargo.toml:
```toml
[package]
name = "dummy-server"
version = "*"
edition = "2021"[dependencies]
dap = "*"
```Our dummy server is going to read its input from a text file and write the output to stdout.
```rust
use std::fs::File;
use std::io::{BufReader, BufWriter};use thiserror::Error;
use dap::prelude::*;
#[derive(Error, Debug)]
enum MyAdapterError {
#[error("Unhandled command")]
UnhandledCommandError,#[error("Missing command")]
MissingCommandError,
}type DynResult = std::result::Result>;
fn main() -> DynResult<()> {
let output = BufWriter::new(std::io::stdout());
let f = File::open("testinput.txt")?;
let input = BufReader::new(f);
let mut server = Server::new(input, output);let req = match server.poll_request()? {
Some(req) => req,
None => return Err(Box::new(MyAdapterError::MissingCommandError)),
};
if let Command::Initialize(_) = req.command {
let rsp = req.success(
ResponseBody::Initialize(Some(types::Capabilities {
..Default::default()
})),
);// When you call respond, send_event etc. the message will be wrapped
// in a base message with a appropriate seq number, so you don't have to keep track of that yourself
server.respond(rsp)?;server.send_event(Event::Initialized)?;
} else {
return Err(Box::new(MyAdapterError::UnhandledCommandError));
}
Ok(())
}
```## License
This library is dual-licensed as MIT and Apache 2.0. That means users may choose either of these
licenses. In general, these are non-restrictive, non-viral licenses, a.k.a. *"do what you want
but no guarantees from me"*.Commercial support is available on a contract basis (contact me: [email protected]).
[1]: https://microsoft.github.io/debug-adapter-protocol/
[2]: https://microsoft.github.io/language-server-protocol/
[3]: https://microsoft.github.io/debug-adapter-protocol/specification#Requests