2021-08-12 21:35:15 +08:00
|
|
|
mod client;
|
|
|
|
mod transport;
|
2021-08-16 12:22:54 +08:00
|
|
|
mod types;
|
2021-08-12 21:35:15 +08:00
|
|
|
|
feat(dap): send Disconnect if Terminated event received (#5532)
Send a `Disconnect` DAP request if the `Terminated` event is received.
According to the specification, if the debugging session was started by
as `launch`, the debuggee should be terminated alongside the session. If
instead the session was started as `attach`, it should not be disposed of.
This default behaviour can be overriden if the `supportTerminateDebuggee`
capability is supported by the adapter, through the `Disconnect` request
`terminateDebuggee` argument, as described in
[the specification][discon-spec].
This also implies saving the starting command for a debug sessions, in
order to decide which behaviour should be used, as well as validating the
capabilities of the adapter, in order to decide what the disconnect should
do.
An additional change made is handling of the `Exited` event, showing a
message if the exit code is different than `0`, for the user to be aware
off the termination failure.
[discon-spec]: https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disconnect
Closes: #4674
Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
2023-02-20 12:00:00 +08:00
|
|
|
pub use client::{Client, ConnectionType};
|
2021-08-22 15:05:12 +08:00
|
|
|
pub use transport::{Payload, Response, Transport};
|
2021-08-16 12:22:54 +08:00
|
|
|
pub use types::*;
|
2021-08-12 21:35:15 +08:00
|
|
|
|
2025-01-28 04:27:35 +08:00
|
|
|
use serde::de::DeserializeOwned;
|
|
|
|
|
2021-08-12 21:35:15 +08:00
|
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
#[error("failed to parse: {0}")]
|
|
|
|
Parse(#[from] serde_json::Error),
|
|
|
|
#[error("IO Error: {0}")]
|
|
|
|
IO(#[from] std::io::Error),
|
2023-02-17 00:21:12 +08:00
|
|
|
#[error("request {0} timed out")]
|
|
|
|
Timeout(u64),
|
2021-08-12 21:35:15 +08:00
|
|
|
#[error("server closed the stream")]
|
|
|
|
StreamClosed,
|
2025-01-28 04:27:35 +08:00
|
|
|
#[error("Unhandled")]
|
|
|
|
Unhandled,
|
2021-08-12 21:35:15 +08:00
|
|
|
#[error(transparent)]
|
2024-01-24 02:36:53 +08:00
|
|
|
ExecutableNotFound(#[from] helix_stdx::env::ExecutableNotFoundError),
|
|
|
|
#[error(transparent)]
|
2021-08-12 21:35:15 +08:00
|
|
|
Other(#[from] anyhow::Error),
|
|
|
|
}
|
|
|
|
pub type Result<T> = core::result::Result<T, Error>;
|
2025-01-28 04:27:35 +08:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Request {
|
|
|
|
RunInTerminal(<requests::RunInTerminal as types::Request>::Arguments),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Request {
|
|
|
|
pub fn parse(command: &str, arguments: Option<serde_json::Value>) -> Result<Self> {
|
|
|
|
use crate::types::Request as _;
|
|
|
|
|
|
|
|
let arguments = arguments.unwrap_or_default();
|
|
|
|
let request = match command {
|
|
|
|
requests::RunInTerminal::COMMAND => Self::RunInTerminal(parse_value(arguments)?),
|
|
|
|
_ => return Err(Error::Unhandled),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(request)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Event {
|
|
|
|
Initialized(<events::Initialized as events::Event>::Body),
|
|
|
|
Stopped(<events::Stopped as events::Event>::Body),
|
|
|
|
Continued(<events::Continued as events::Event>::Body),
|
|
|
|
Exited(<events::Exited as events::Event>::Body),
|
|
|
|
Terminated(<events::Terminated as events::Event>::Body),
|
|
|
|
Thread(<events::Thread as events::Event>::Body),
|
|
|
|
Output(<events::Output as events::Event>::Body),
|
|
|
|
Breakpoint(<events::Breakpoint as events::Event>::Body),
|
|
|
|
Module(<events::Module as events::Event>::Body),
|
|
|
|
LoadedSource(<events::LoadedSource as events::Event>::Body),
|
|
|
|
Process(<events::Process as events::Event>::Body),
|
|
|
|
Capabilities(<events::Capabilities as events::Event>::Body),
|
|
|
|
// ProgressStart(),
|
|
|
|
// ProgressUpdate(),
|
|
|
|
// ProgressEnd(),
|
|
|
|
// Invalidated(),
|
|
|
|
Memory(<events::Memory as events::Event>::Body),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Event {
|
|
|
|
pub fn parse(event: &str, body: Option<serde_json::Value>) -> Result<Self> {
|
|
|
|
use crate::events::Event as _;
|
|
|
|
|
|
|
|
let body = body.unwrap_or_default();
|
|
|
|
let event = match event {
|
|
|
|
events::Initialized::EVENT => Self::Initialized(parse_value(body)?),
|
|
|
|
events::Stopped::EVENT => Self::Stopped(parse_value(body)?),
|
|
|
|
events::Continued::EVENT => Self::Continued(parse_value(body)?),
|
|
|
|
events::Exited::EVENT => Self::Exited(parse_value(body)?),
|
|
|
|
events::Terminated::EVENT => Self::Terminated(parse_value(body)?),
|
|
|
|
events::Thread::EVENT => Self::Thread(parse_value(body)?),
|
|
|
|
events::Output::EVENT => Self::Output(parse_value(body)?),
|
|
|
|
events::Breakpoint::EVENT => Self::Breakpoint(parse_value(body)?),
|
|
|
|
events::Module::EVENT => Self::Module(parse_value(body)?),
|
|
|
|
events::LoadedSource::EVENT => Self::LoadedSource(parse_value(body)?),
|
|
|
|
events::Process::EVENT => Self::Process(parse_value(body)?),
|
|
|
|
events::Capabilities::EVENT => Self::Capabilities(parse_value(body)?),
|
|
|
|
events::Memory::EVENT => Self::Memory(parse_value(body)?),
|
|
|
|
_ => return Err(Error::Unhandled),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_value<T>(value: serde_json::Value) -> Result<T>
|
|
|
|
where
|
|
|
|
T: DeserializeOwned,
|
|
|
|
{
|
|
|
|
serde_json::from_value(value).map_err(|err| err.into())
|
|
|
|
}
|