Something went wrong. Try again.
fork of gpui
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976use std::sync::Arc;
use anyhow::{Context as _, Ok, Result};use base64::Engine;use dap::{ Capabilities, ContinueArguments, ExceptionFilterOptions, InitializeRequestArguments, InitializeRequestArgumentsPathFormat, NextArguments, SetVariableResponse, SourceBreakpoint, StepInArguments, StepOutArguments, SteppingGranularity, ValueFormat, Variable, VariablesArgumentsFilter, client::SessionId, proto_conversions::ProtoConversion, requests::{Continue, Next},};
use rpc::proto;use serde_json::Value;use util::ResultExt;
pub trait LocalDapCommand: 'static + Send + Sync + std::fmt::Debug { type Response: 'static + Send + std::fmt::Debug; type DapRequest: 'static + Send + dap::requests::Request; /// Is this request idempotent? Is it safe to cache the response for as long as the execution environment is unchanged? const CACHEABLE: bool = false;
fn is_supported(_capabilities: &Capabilities) -> bool { true }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments;
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response>;}
pub trait DapCommand: LocalDapCommand { type ProtoRequest: 'static + Send; type ProtoResponse: 'static + Send;
#[allow(dead_code)] fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId;
#[allow(dead_code)] fn from_proto(request: &Self::ProtoRequest) -> Self;
#[allow(unused)] fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest;
#[allow(dead_code)] fn response_to_proto( debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse;
#[allow(unused)] fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response>;}
impl<T: LocalDapCommand> LocalDapCommand for Arc<T> { type Response = T::Response; type DapRequest = T::DapRequest;
fn is_supported(capabilities: &Capabilities) -> bool { T::is_supported(capabilities) }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { T::to_dap(self) }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { T::response_from_dap(self, message) }}
impl<T: DapCommand> DapCommand for Arc<T> { type ProtoRequest = T::ProtoRequest; type ProtoResponse = T::ProtoResponse;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { T::client_id_from_proto(request) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Arc::new(T::from_proto(request)) }
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { T::to_proto(self, debug_client_id, upstream_project_id) }
fn response_to_proto( debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { T::response_to_proto(debug_client_id, message) }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { T::response_from_proto(self, message) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub struct StepCommand { pub thread_id: i64, pub granularity: Option<SteppingGranularity>, pub single_thread: Option<bool>,}
impl StepCommand { fn from_proto(message: proto::DapNextRequest) -> Self { const LINE: i32 = proto::SteppingGranularity::Line as i32; const INSTRUCTION: i32 = proto::SteppingGranularity::Instruction as i32;
let granularity = message.granularity.map(|granularity| match granularity { LINE => SteppingGranularity::Line, INSTRUCTION => SteppingGranularity::Instruction, _ => SteppingGranularity::Statement, });
Self { thread_id: message.thread_id, granularity, single_thread: message.single_thread, } }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct NextCommand { pub inner: StepCommand,}
impl LocalDapCommand for NextCommand { type Response = <Next as dap::requests::Request>::Response; type DapRequest = Next;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { NextArguments { thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, granularity: self.inner.granularity, } } fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for NextCommand { type ProtoRequest = proto::DapNextRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { inner: StepCommand::from_proto(request.clone()), } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapNextRequest { proto::DapNextRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, granularity: self.inner.granularity.map(|gran| gran.to_proto() as i32), } }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct StepInCommand { pub inner: StepCommand,}
impl LocalDapCommand for StepInCommand { type Response = <dap::requests::StepIn as dap::requests::Request>::Response; type DapRequest = dap::requests::StepIn;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { StepInArguments { thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, target_id: None, granularity: self.inner.granularity, } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for StepInCommand { type ProtoRequest = proto::DapStepInRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { inner: StepCommand::from_proto(proto::DapNextRequest { project_id: request.project_id, client_id: request.client_id, thread_id: request.thread_id, single_thread: request.single_thread, granularity: request.granularity, }), } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapStepInRequest { proto::DapStepInRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, granularity: self.inner.granularity.map(|gran| gran.to_proto() as i32), target_id: None, } }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct StepOutCommand { pub inner: StepCommand,}
impl LocalDapCommand for StepOutCommand { type Response = <dap::requests::StepOut as dap::requests::Request>::Response; type DapRequest = dap::requests::StepOut;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { StepOutArguments { thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, granularity: self.inner.granularity, } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for StepOutCommand { type ProtoRequest = proto::DapStepOutRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { inner: StepCommand::from_proto(proto::DapNextRequest { project_id: request.project_id, client_id: request.client_id, thread_id: request.thread_id, single_thread: request.single_thread, granularity: request.granularity, }), } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapStepOutRequest { proto::DapStepOutRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, granularity: self.inner.granularity.map(|gran| gran.to_proto() as i32), } }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct StepBackCommand { pub inner: StepCommand,}impl LocalDapCommand for StepBackCommand { type Response = <dap::requests::StepBack as dap::requests::Request>::Response; type DapRequest = dap::requests::StepBack;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_step_back.unwrap_or_default() }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::StepBackArguments { thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, granularity: self.inner.granularity, } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for StepBackCommand { type ProtoRequest = proto::DapStepBackRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { inner: StepCommand::from_proto(proto::DapNextRequest { project_id: request.project_id, client_id: request.client_id, thread_id: request.thread_id, single_thread: request.single_thread, granularity: request.granularity, }), } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapStepBackRequest { proto::DapStepBackRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_id: self.inner.thread_id, single_thread: self.inner.single_thread, granularity: self.inner.granularity.map(|gran| gran.to_proto() as i32), } }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct ContinueCommand { pub args: ContinueArguments,}
impl LocalDapCommand for ContinueCommand { type Response = <Continue as dap::requests::Request>::Response; type DapRequest = Continue;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { self.args.clone() }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
impl DapCommand for ContinueCommand { type ProtoRequest = proto::DapContinueRequest; type ProtoResponse = proto::DapContinueResponse;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapContinueRequest { proto::DapContinueRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_id: self.args.thread_id, single_thread: self.args.single_thread, } }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { args: ContinueArguments { thread_id: request.thread_id, single_thread: request.single_thread, }, } }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(Self::Response { all_threads_continued: message.all_threads_continued, }) }
fn response_to_proto( debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapContinueResponse { client_id: debug_client_id.to_proto(), all_threads_continued: message.all_threads_continued, } }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct PauseCommand { pub thread_id: i64,}
impl LocalDapCommand for PauseCommand { type Response = <dap::requests::Pause as dap::requests::Request>::Response; type DapRequest = dap::requests::Pause; fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::PauseArguments { thread_id: self.thread_id, } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for PauseCommand { type ProtoRequest = proto::DapPauseRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { thread_id: request.thread_id, } }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapPauseRequest { proto::DapPauseRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_id: self.thread_id, } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct DisconnectCommand { pub restart: Option<bool>, pub terminate_debuggee: Option<bool>, pub suspend_debuggee: Option<bool>,}
impl LocalDapCommand for DisconnectCommand { type Response = <dap::requests::Disconnect as dap::requests::Request>::Response; type DapRequest = dap::requests::Disconnect;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::DisconnectArguments { restart: self.restart, terminate_debuggee: self.terminate_debuggee, suspend_debuggee: self.suspend_debuggee, } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for DisconnectCommand { type ProtoRequest = proto::DapDisconnectRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { restart: request.restart, terminate_debuggee: request.terminate_debuggee, suspend_debuggee: request.suspend_debuggee, } }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapDisconnectRequest { proto::DapDisconnectRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), restart: self.restart, terminate_debuggee: self.terminate_debuggee, suspend_debuggee: self.suspend_debuggee, } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct TerminateThreadsCommand { pub thread_ids: Option<Vec<i64>>,}
impl LocalDapCommand for TerminateThreadsCommand { type Response = <dap::requests::TerminateThreads as dap::requests::Request>::Response; type DapRequest = dap::requests::TerminateThreads;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities .supports_terminate_threads_request .unwrap_or_default() }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::TerminateThreadsArguments { thread_ids: self.thread_ids.clone(), } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for TerminateThreadsCommand { type ProtoRequest = proto::DapTerminateThreadsRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { let thread_ids = if request.thread_ids.is_empty() { None } else { Some(request.thread_ids.clone()) };
Self { thread_ids } }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapTerminateThreadsRequest { proto::DapTerminateThreadsRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_ids: self.thread_ids.clone().unwrap_or_default(), } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct TerminateCommand { pub restart: Option<bool>,}
impl LocalDapCommand for TerminateCommand { type Response = <dap::requests::Terminate as dap::requests::Request>::Response; type DapRequest = dap::requests::Terminate;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_terminate_request.unwrap_or_default() } fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::TerminateArguments { restart: self.restart, } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for TerminateCommand { type ProtoRequest = proto::DapTerminateRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { restart: request.restart, } }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapTerminateRequest { proto::DapTerminateRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), restart: self.restart, } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct RestartCommand { pub raw: serde_json::Value,}
impl LocalDapCommand for RestartCommand { type Response = <dap::requests::Restart as dap::requests::Request>::Response; type DapRequest = dap::requests::Restart;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_restart_request.unwrap_or_default() }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::RestartArguments { raw: self.raw.clone(), } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for RestartCommand { type ProtoRequest = proto::DapRestartRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { raw: serde_json::from_slice(&request.raw_args) .log_err() .unwrap_or(serde_json::Value::Null), } }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapRestartRequest { let raw_args = serde_json::to_vec(&self.raw).log_err().unwrap_or_default();
proto::DapRestartRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), raw_args, } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]pub struct VariablesCommand { pub variables_reference: u64, pub filter: Option<VariablesArgumentsFilter>, pub start: Option<u64>, pub count: Option<u64>, pub format: Option<ValueFormat>,}
impl LocalDapCommand for VariablesCommand { type Response = Vec<Variable>; type DapRequest = dap::requests::Variables; const CACHEABLE: bool = true;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::VariablesArguments { variables_reference: self.variables_reference, filter: self.filter, start: self.start, count: self.count, format: self.format.clone(), } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.variables) }}
impl DapCommand for VariablesCommand { type ProtoRequest = proto::VariablesRequest; type ProtoResponse = proto::DapVariables;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { proto::VariablesRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), variables_reference: self.variables_reference, filter: None, start: self.start, count: self.count, format: None, } }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { variables_reference: request.variables_reference, filter: None, start: request.start, count: request.count, format: None, } }
fn response_to_proto( debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapVariables { client_id: debug_client_id.to_proto(), variables: message.to_proto(), } }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(Vec::from_proto(message.variables)) }}
#[derive(Debug, Hash, PartialEq, Eq)]pub(crate) struct SetVariableValueCommand { pub name: String, pub value: String, pub variables_reference: u64,}impl LocalDapCommand for SetVariableValueCommand { type Response = SetVariableResponse; type DapRequest = dap::requests::SetVariable; fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_set_variable.unwrap_or_default() } fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::SetVariableArguments { format: None, name: self.name.clone(), value: self.value.clone(), variables_reference: self.variables_reference, } } fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
impl DapCommand for SetVariableValueCommand { type ProtoRequest = proto::DapSetVariableValueRequest; type ProtoResponse = proto::DapSetVariableValueResponse;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { proto::DapSetVariableValueRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), variables_reference: self.variables_reference, value: self.value.clone(), name: self.name.clone(), } }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { variables_reference: request.variables_reference, name: request.name.clone(), value: request.value.clone(), } }
fn response_to_proto( debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapSetVariableValueResponse { client_id: debug_client_id.to_proto(), value: message.value, variable_type: message.type_, named_variables: message.named_variables, variables_reference: message.variables_reference, indexed_variables: message.indexed_variables, memory_reference: message.memory_reference, } }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(SetVariableResponse { value: message.value, type_: message.variable_type, variables_reference: message.variables_reference, named_variables: message.named_variables, indexed_variables: message.indexed_variables, memory_reference: message.memory_reference, value_location_reference: None, // TODO }) }}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]pub(crate) struct RestartStackFrameCommand { pub stack_frame_id: u64,}
impl LocalDapCommand for RestartStackFrameCommand { type Response = <dap::requests::RestartFrame as dap::requests::Request>::Response; type DapRequest = dap::requests::RestartFrame;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_restart_frame.unwrap_or_default() }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::RestartFrameArguments { frame_id: self.stack_frame_id, } }
fn response_from_dap( &self, _message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(()) }}
impl DapCommand for RestartStackFrameCommand { type ProtoRequest = proto::DapRestartStackFrameRequest; type ProtoResponse = proto::Ack;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { stack_frame_id: request.stack_frame_id, } }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapRestartStackFrameRequest { proto::DapRestartStackFrameRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), stack_frame_id: self.stack_frame_id, } }
fn response_to_proto( _debug_client_id: SessionId, _message: Self::Response, ) -> Self::ProtoResponse { proto::Ack {} }
fn response_from_proto(&self, _message: Self::ProtoResponse) -> Result<Self::Response> { Ok(()) }}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]pub(crate) struct ModulesCommand;
impl LocalDapCommand for ModulesCommand { type Response = Vec<dap::Module>; type DapRequest = dap::requests::Modules; const CACHEABLE: bool = true;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_modules_request.unwrap_or_default() }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::ModulesArguments { start_module: None, module_count: None, } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.modules) }}
impl DapCommand for ModulesCommand { type ProtoRequest = proto::DapModulesRequest; type ProtoResponse = proto::DapModulesResponse;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(_request: &Self::ProtoRequest) -> Self { Self {} }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapModulesRequest { proto::DapModulesRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), } }
fn response_to_proto( debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapModulesResponse { modules: message .into_iter() .map(|module| module.to_proto()) .collect(), client_id: debug_client_id.to_proto(), } }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(message .modules .into_iter() .filter_map(|module| dap::Module::from_proto(module).ok()) .collect()) }}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]pub(crate) struct LoadedSourcesCommand;
impl LocalDapCommand for LoadedSourcesCommand { type Response = Vec<dap::Source>; type DapRequest = dap::requests::LoadedSources; const CACHEABLE: bool = true;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities .supports_loaded_sources_request .unwrap_or_default() } fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::LoadedSourcesArguments {} }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.sources) }}
impl DapCommand for LoadedSourcesCommand { type ProtoRequest = proto::DapLoadedSourcesRequest; type ProtoResponse = proto::DapLoadedSourcesResponse;
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(_request: &Self::ProtoRequest) -> Self { Self {} }
fn to_proto( &self, debug_client_id: SessionId, upstream_project_id: u64, ) -> proto::DapLoadedSourcesRequest { proto::DapLoadedSourcesRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), } }
fn response_to_proto( debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapLoadedSourcesResponse { sources: message .into_iter() .map(|source| source.to_proto()) .collect(), client_id: debug_client_id.to_proto(), } }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(message .sources .into_iter() .map(dap::Source::from_proto) .collect()) }}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]pub(crate) struct StackTraceCommand { pub thread_id: i64, pub start_frame: Option<u64>, pub levels: Option<u64>,}
impl LocalDapCommand for StackTraceCommand { type Response = Vec<dap::StackFrame>; type DapRequest = dap::requests::StackTrace; const CACHEABLE: bool = true;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::StackTraceArguments { thread_id: self.thread_id, start_frame: self.start_frame, levels: self.levels, format: None, } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.stack_frames) }}
impl DapCommand for StackTraceCommand { type ProtoRequest = proto::DapStackTraceRequest; type ProtoResponse = proto::DapStackTraceResponse;
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { proto::DapStackTraceRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), thread_id: self.thread_id, start_frame: self.start_frame, stack_trace_levels: self.levels, } }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { thread_id: request.thread_id, start_frame: request.start_frame, levels: request.stack_trace_levels, } }
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(message .frames .into_iter() .map(dap::StackFrame::from_proto) .collect()) }
fn response_to_proto( _debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapStackTraceResponse { frames: message.to_proto(), } }}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]pub(crate) struct ScopesCommand { pub stack_frame_id: u64,}
impl LocalDapCommand for ScopesCommand { type Response = Vec<dap::Scope>; type DapRequest = dap::requests::Scopes; const CACHEABLE: bool = true;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::ScopesArguments { frame_id: self.stack_frame_id, } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.scopes) }}
impl DapCommand for ScopesCommand { type ProtoRequest = proto::DapScopesRequest; type ProtoResponse = proto::DapScopesResponse;
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { proto::DapScopesRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), stack_frame_id: self.stack_frame_id, } }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { stack_frame_id: request.stack_frame_id, } }
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(Vec::from_proto(message.scopes)) }
fn response_to_proto( _debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapScopesResponse { scopes: message.to_proto(), } }}
impl LocalDapCommand for super::session::CompletionsQuery { type Response = dap::CompletionsResponse; type DapRequest = dap::requests::Completions; const CACHEABLE: bool = true;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::CompletionsArguments { text: self.query.clone(), frame_id: self.frame_id, column: self.column, line: None, } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }
fn is_supported(capabilities: &Capabilities) -> bool { capabilities .supports_completions_request .unwrap_or_default() }}
impl DapCommand for super::session::CompletionsQuery { type ProtoRequest = proto::DapCompletionRequest; type ProtoResponse = proto::DapCompletionResponse;
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { proto::DapCompletionRequest { client_id: debug_client_id.to_proto(), project_id: upstream_project_id, frame_id: self.frame_id, query: self.query.clone(), column: self.column, line: self.line, } }
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { query: request.query.clone(), frame_id: request.frame_id, column: request.column, line: request.line, } }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(dap::CompletionsResponse { targets: Vec::from_proto(message.completions), }) }
fn response_to_proto( _debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapCompletionResponse { client_id: _debug_client_id.to_proto(), completions: message.targets.to_proto(), } }}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]pub(crate) struct EvaluateCommand { pub expression: String, pub frame_id: Option<u64>, pub context: Option<dap::EvaluateArgumentsContext>, pub source: Option<dap::Source>,}
impl LocalDapCommand for EvaluateCommand { type Response = dap::EvaluateResponse; type DapRequest = dap::requests::Evaluate; fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::EvaluateArguments { expression: self.expression.clone(), frame_id: self.frame_id, context: self.context.clone(), source: self.source.clone(), line: None, column: None, format: None, } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}impl DapCommand for EvaluateCommand { type ProtoRequest = proto::DapEvaluateRequest; type ProtoResponse = proto::DapEvaluateResponse;
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { proto::DapEvaluateRequest { client_id: debug_client_id.to_proto(), project_id: upstream_project_id, expression: self.expression.clone(), frame_id: self.frame_id, context: self .context .clone() .map(|context| context.to_proto().into()), } }
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn from_proto(request: &Self::ProtoRequest) -> Self { Self { expression: request.expression.clone(), frame_id: request.frame_id, context: Some(dap::EvaluateArgumentsContext::from_proto(request.context())), source: None, } }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(dap::EvaluateResponse { result: message.result.clone(), type_: message.evaluate_type.clone(), presentation_hint: None, variables_reference: message.variable_reference, named_variables: message.named_variables, indexed_variables: message.indexed_variables, memory_reference: message.memory_reference, value_location_reference: None, //TODO }) }
fn response_to_proto( _debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapEvaluateResponse { result: message.result, evaluate_type: message.type_, variable_reference: message.variables_reference, named_variables: message.named_variables, indexed_variables: message.indexed_variables, memory_reference: message.memory_reference, } }}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]pub(crate) struct ThreadsCommand;
impl LocalDapCommand for ThreadsCommand { type Response = Vec<dap::Thread>; type DapRequest = dap::requests::Threads; const CACHEABLE: bool = true;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::ThreadsArgument {} }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.threads) }}
impl DapCommand for ThreadsCommand { type ProtoRequest = proto::DapThreadsRequest; type ProtoResponse = proto::DapThreadsResponse;
fn to_proto(&self, debug_client_id: SessionId, upstream_project_id: u64) -> Self::ProtoRequest { proto::DapThreadsRequest { project_id: upstream_project_id, client_id: debug_client_id.to_proto(), } }
fn from_proto(_request: &Self::ProtoRequest) -> Self { Self {} }
fn client_id_from_proto(request: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(request.client_id) }
fn response_from_proto(&self, message: Self::ProtoResponse) -> Result<Self::Response> { Ok(Vec::from_proto(message.threads)) }
fn response_to_proto( _debug_client_id: SessionId, message: Self::Response, ) -> Self::ProtoResponse { proto::DapThreadsResponse { threads: message.to_proto(), } }}
#[derive(Clone, Debug, Hash, PartialEq)]pub(super) struct Initialize { pub(super) adapter_id: String,}
fn dap_client_capabilities(adapter_id: String) -> InitializeRequestArguments { InitializeRequestArguments { client_id: Some("zed".to_owned()), client_name: Some("Zed".to_owned()), adapter_id, locale: Some("en-US".to_owned()), path_format: Some(InitializeRequestArgumentsPathFormat::Path), supports_variable_type: Some(true), supports_variable_paging: Some(false), supports_run_in_terminal_request: Some(true), supports_memory_references: Some(true), supports_progress_reporting: Some(false), supports_invalidated_event: Some(false), lines_start_at1: Some(true), columns_start_at1: Some(true), supports_memory_event: Some(false), supports_args_can_be_interpreted_by_shell: Some(false), supports_start_debugging_request: Some(true), supports_ansistyling: Some(true), }}
impl LocalDapCommand for Initialize { type Response = Capabilities; type DapRequest = dap::requests::Initialize;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap_client_capabilities(self.adapter_id.clone()) }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
#[derive(Clone, Debug, Hash, PartialEq)]pub(super) struct ConfigurationDone {}
impl LocalDapCommand for ConfigurationDone { type Response = (); type DapRequest = dap::requests::ConfigurationDone;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities .supports_configuration_done_request .unwrap_or_default() }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::ConfigurationDoneArguments {} }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
#[derive(Clone, Debug, Hash, PartialEq)]pub(super) struct Launch { pub(super) raw: Value,}
impl LocalDapCommand for Launch { type Response = (); type DapRequest = dap::requests::Launch;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::LaunchRequestArguments { raw: self.raw.clone(), } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
#[derive(Clone, Debug, Hash, PartialEq)]pub(super) struct Attach { pub(super) raw: Value,}
impl LocalDapCommand for Attach { type Response = (); type DapRequest = dap::requests::Attach;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::AttachRequestArguments { raw: self.raw.clone(), } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
#[derive(Clone, Debug, Hash, PartialEq)]pub(super) struct SetBreakpoints { pub(super) source: dap::Source, pub(super) breakpoints: Vec<SourceBreakpoint>, pub(super) source_modified: Option<bool>,}
impl LocalDapCommand for SetBreakpoints { type Response = Vec<dap::Breakpoint>; type DapRequest = dap::requests::SetBreakpoints;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::SetBreakpointsArguments { lines: None, source_modified: self.source_modified, source: self.source.clone(), breakpoints: Some(self.breakpoints.clone()), } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.breakpoints) }}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]pub enum DataBreakpointContext { Variable { variables_reference: u64, name: String, bytes: Option<u64>, }, Expression { expression: String, frame_id: Option<u64>, }, Address { address: String, bytes: Option<u64>, },}
impl DataBreakpointContext { pub fn human_readable_label(&self) -> String { match self { DataBreakpointContext::Variable { name, .. } => format!("Variable: {}", name), DataBreakpointContext::Expression { expression, .. } => { format!("Expression: {}", expression) } DataBreakpointContext::Address { address, bytes } => { let mut label = format!("Address: {}", address); if let Some(bytes) = bytes { label.push_str(&format!( " ({} byte{})", bytes, if *bytes == 1 { "" } else { "s" } )); } label } } }}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]pub(crate) struct DataBreakpointInfoCommand { pub context: Arc<DataBreakpointContext>, pub mode: Option<String>,}
impl LocalDapCommand for DataBreakpointInfoCommand { type Response = dap::DataBreakpointInfoResponse; type DapRequest = dap::requests::DataBreakpointInfo; const CACHEABLE: bool = true;
// todo(debugger): We should expand this trait in the future to take a &self // Depending on this command is_supported could be differentb fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_data_breakpoints.unwrap_or(false) }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { let (variables_reference, name, frame_id, as_address, bytes) = match &*self.context { DataBreakpointContext::Variable { variables_reference, name, bytes, } => ( Some(*variables_reference), name.clone(), None, Some(false), *bytes, ), DataBreakpointContext::Expression { expression, frame_id, } => (None, expression.clone(), *frame_id, Some(false), None), DataBreakpointContext::Address { address, bytes } => { (None, address.clone(), None, Some(true), *bytes) } };
dap::DataBreakpointInfoArguments { variables_reference, name, frame_id, bytes, as_address, mode: self.mode.clone(), } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]pub(crate) struct SetDataBreakpointsCommand { pub breakpoints: Vec<dap::DataBreakpoint>,}
impl LocalDapCommand for SetDataBreakpointsCommand { type Response = Vec<dap::Breakpoint>; type DapRequest = dap::requests::SetDataBreakpoints;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_data_breakpoints.unwrap_or(false) }
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::SetDataBreakpointsArguments { breakpoints: self.breakpoints.clone(), } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.breakpoints) }}
#[derive(Clone, Debug, Hash, PartialEq)]pub(super) enum SetExceptionBreakpoints { Plain { filters: Vec<String>, }, WithOptions { filters: Vec<ExceptionFilterOptions>, },}
impl LocalDapCommand for SetExceptionBreakpoints { type Response = Vec<dap::Breakpoint>; type DapRequest = dap::requests::SetExceptionBreakpoints;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { match self { SetExceptionBreakpoints::Plain { filters } => dap::SetExceptionBreakpointsArguments { filters: filters.clone(), exception_options: None, filter_options: None, }, SetExceptionBreakpoints::WithOptions { filters } => { dap::SetExceptionBreakpointsArguments { filters: vec![], filter_options: Some(filters.clone()), exception_options: None, } } } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message.breakpoints.unwrap_or_default()) }}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]pub(super) struct LocationsCommand { pub(super) reference: u64,}
impl LocalDapCommand for LocationsCommand { type Response = dap::LocationsResponse; type DapRequest = dap::requests::Locations; const CACHEABLE: bool = true;
fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::LocationsArguments { location_reference: self.reference, } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}
impl DapCommand for LocationsCommand { type ProtoRequest = proto::DapLocationsRequest; type ProtoResponse = proto::DapLocationsResponse;
fn client_id_from_proto(message: &Self::ProtoRequest) -> SessionId { SessionId::from_proto(message.session_id) }
fn from_proto(message: &Self::ProtoRequest) -> Self { Self { reference: message.location_reference, } }
fn to_proto(&self, session_id: SessionId, project_id: u64) -> Self::ProtoRequest { proto::DapLocationsRequest { project_id, session_id: session_id.to_proto(), location_reference: self.reference, } }
fn response_to_proto(_: SessionId, response: Self::Response) -> Self::ProtoResponse { proto::DapLocationsResponse { source: Some(response.source.to_proto()), line: response.line, column: response.column, end_line: response.end_line, end_column: response.end_column, } }
fn response_from_proto(&self, response: Self::ProtoResponse) -> Result<Self::Response> { Ok(dap::LocationsResponse { source: response .source .map(<dap::Source as ProtoConversion>::from_proto) .context("Missing `source` field in Locations proto")?, line: response.line, column: response.column, end_line: response.end_line, end_column: response.end_column, }) }}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]pub(crate) struct ReadMemory { pub(crate) memory_reference: String, pub(crate) offset: Option<u64>, pub(crate) count: u64,}
#[derive(Clone, Debug, PartialEq)]pub(crate) struct ReadMemoryResponse { pub(super) address: Arc<str>, pub(super) unreadable_bytes: Option<u64>, pub(super) content: Arc<[u8]>,}
impl LocalDapCommand for ReadMemory { type Response = ReadMemoryResponse; type DapRequest = dap::requests::ReadMemory; const CACHEABLE: bool = true;
fn is_supported(capabilities: &Capabilities) -> bool { capabilities .supports_read_memory_request .unwrap_or_default() } fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { dap::ReadMemoryArguments { memory_reference: self.memory_reference.clone(), offset: self.offset, count: self.count, } }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { let data = if let Some(data) = message.data { base64::engine::general_purpose::STANDARD .decode(data) .log_err() .context("parsing base64 data from DAP's ReadMemory response")? } else { vec![] };
Ok(ReadMemoryResponse { address: message.address.into(), content: data.into(), unreadable_bytes: message.unreadable_bytes, }) }}
impl LocalDapCommand for dap::WriteMemoryArguments { type Response = dap::WriteMemoryResponse; type DapRequest = dap::requests::WriteMemory; fn is_supported(capabilities: &Capabilities) -> bool { capabilities .supports_write_memory_request .unwrap_or_default() } fn to_dap(&self) -> <Self::DapRequest as dap::requests::Request>::Arguments { self.clone() }
fn response_from_dap( &self, message: <Self::DapRequest as dap::requests::Request>::Response, ) -> Result<Self::Response> { Ok(message) }}