Skip to content

Instantly share code, notes, and snippets.

@h-michael
Created May 1, 2019 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-michael/3ef8b8b22252934d050bae7b1b9f9c34 to your computer and use it in GitHub Desktop.
Save h-michael/3ef8b8b22252934d050bae7b1b9f9c34 to your computer and use it in GitHub Desktop.
build adp definitions macro sample
macro_rules! _adp_denitition {
($($doc_comment: literal)*, $enum_name:ident, $trait_name:ident, $type_ident:ident, $(($type_name:ident, $type_definition:ident),)*) => {
$(#[doc=$doc_comment])*
#[derive(Debug)]
pub enum $enum_name {}
impl $trait_name for $enum_name {
$(type $type_name = $type_definition;)*
const $type_ident: &'static str = stringify!(stringify!($enum_name).to_lowercase());
}
}
}
pub trait Request {
type Arguments;
type Result;
const COMMAND: &'static str;
}
macro_rules! adp_request {
($($doc_comment:literal)*, $enum_name:ident, $arguments:ident, $result: ident) => {
_adp_denitition!($($doc_comment)*, $enum_name, Request, COMMAND, (Arguments, $arguments), (Result, $result),);
}
}
pub trait Event {
type Body;
const EVENT: &'static str;
}
macro_rules! adb_event {
($($doc_comment:literal)*, $enum_name:ident, $body:ident) => {
_adp_denitition!($($doc_comment)*, $enum_name, Event, EVENT, (Body, $body),);
}
}
type NoneBody = ();
adb_event!(
"This event indicates that the debug adapter is ready to accept configuration requests (e.g. SetBreakpointsRequest, SetExceptionBreakpointsRequest)."
"A debug adapter is expected to send this event when it is ready to accept configuration requests (but not before the ‘initialize’ request has finished).",
Initialized,
NoneBody
);
type StoppedBody = ();
adb_event!(
"The event indicates that the execution of the debuggee has stopped due to some condition."
"This can be caused by a break point previously set, a stepping action has completed, by executing a debugger statement etc.",
Stopped,
StoppedBody
);
type ContinuedBody = ();
adb_event!(
"The event indicates that the execution of the debuggee has continued."
"Please note: a debug adapter is not expected to send this event in response to a request that implies that execution continues, e.g. ‘launch’ or ‘continue’."
"It is only necessary to send a ‘continued’ event if there was no previous request that implied thi",
Continued,
ContinuedBody
);
type ExitedBody = ();
adb_event!(
"The event indicates that the debuggee has exited and returns its exit code.",
Exited,
ExitedBody
);
type TerminatedBody = ();
adb_event!(
"The event indicates that debugging of the debuggee has terminated. This does not mean that the debuggee itself has exited.",
Terminated,
TerminatedBody
);
type ThreadBody = ();
adb_event!(
"The event indicates that a thread has started or exited.",
Thread,
ThreadBody
);
type OutputBody = ();
adb_event!(
"The event indicates that the target has produced some output.",
Output,
OutputBody
);
type BreakpointBody = ();
adb_event!(
"The event indicates that some information about a breakpoint has changed.",
Breakpoint,
BreakpointBody
);
type ModuleBody = ();
adb_event!(
"The event indicates that some information about a module has changed.",
Module,
ModuleBody
);
type LoadedSourceBody = ();
adb_event!(
"The event indicates that some source has been added, changed, or removed from the set of all loaded sources.",
LoadedSource,
LoadedSourceBody
);
type ProcessBody = ();
adb_event!(
"The event indicates that the debugger has begun debugging a new process. Either one that it has launched, or one that it has attached to.",
Process,
ProcessBody
);
type CapabilitiesBody = ();
adb_event!(
"The event indicates that one or more capabilities have changed."
"Since the capabilities are dependent on the frontend and its UI, it might not be possible to change that at random times (or too late)."
"Consequently this event has a hint characteristic: a frontend can only be expected to make a ‘best effort’ in honouring individual capabilities but there are no guarantees."
"Only changed capabilities need to be included, all other capabilities keep their values.",
Capabilities,
CapabilitiesBody
);
type NoneArgument = ();
type NoneResult = ();
adp_request!(
"The attach request is sent from the client to the debug adapter to attach to a debuggee that is already running."
"Since attaching is debugger/runtime specific, the arguments for this request are not part of this specification.",
Attach,
NoneArgument,
NoneResult
);
// /**
// The attach request is sent from the client to the debug adapter to attach to a debuggee that is already running.AsMut
// Since attaching is debugger/runtime specific, the arguments for this request are not part of this specification.
// */
// #[derive(Debug)]
// pub enum Attach {}
//
// impl Request for Attach {
// type Arguments = AttachRequestArguments;
// type Result = AttachResponse;
// const COMMAND: &'static str = "attach";
// }
//
// /**
// */
// #[derive(Debug)]
// pub enum Restart {}
//
// impl Request for Restart {
// type Arguments = ;
// type Result = ;
// const COMMAND: &'static str = "";
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment