on master help sign in
Merge branch 'debug' of https://github.com/sh7dm/helix into debug
7233ab2Dmitry Sharshakov
helix-term/src/application.rs+78−71
@@ -187,76 +187,7 @@ impl Application {
187 }
187 }
188 }
188 }
189 Some(payload) = self.editor.debugger_events.next() => {
189 Some(payload) = self.editor.debugger_events.next() => {
190− if self.editor.debugger.is_none() {
190+ self.handle_debugger_message(payload).await;
191− continue;
192− }
193− let mut debugger = self.editor.debugger.as_mut().unwrap();
194− match payload {
195− Payload::Event(ev) => {
196− match &ev.event[..] {
197− "stopped" => {
198− debugger.is_running = false;
199− let main = debugger
200− .threads()
201− .await
202− .ok()
203− .and_then(|threads| threads.get(0).cloned());
204− if let Some(main) = main {
205− let (bt, _) = debugger.stack_trace(main.id).await.unwrap();
206− debugger.stack_pointer = bt.get(0).cloned();
207− }
208−
209− let body: helix_dap::events::Stopped = from_value(ev.body.expect("`stopped` event must have a body")).unwrap();
210− let scope = match body.thread_id {
211− Some(id) => format!("Thread {}", id),
212− None => "Target".to_owned(),
213− };
214−
215− let mut status = format!("{} stopped because of {}", scope, body.reason);
216− if let Some(desc) = body.description {
217− status.push_str(&format!(" {}", desc));
218− }
219− if let Some(text) = body.text {
220− status.push_str(&format!(" {}", text));
221− }
222− if body.all_threads_stopped == Some(true) {
223− status.push_str(" (all threads stopped)");
224− }
225−
226− if let Some(helix_dap::StackFrame {
227− source: Some(helix_dap::Source {
228− path: Some(src),
229− ..
230− }),
231− ..
232− }) = &debugger.stack_pointer {
233− let path = src.clone().into();
234− self.editor.open(path, helix_view::editor::Action::Replace).unwrap();
235− }
236− self.editor.set_status(status);
237− self.render();
238− }
239− "output" => {
240− let body: helix_dap::events::Output = from_value(ev.body.expect("`output` event must have a body")).unwrap();
241−
242− let prefix = match body.category {
243− Some(category) => format!("Debug ({}):", category),
244− None => "Debug:".to_owned(),
245− };
246−
247− self.editor.set_status(format!("{} {}", prefix, body.output));
248− self.render();
249− }
250− "initialized" => {
251− self.editor.set_status("Debugged application started".to_owned());
252− self.render();
253− }
254− _ => {}
255− }
256− },
257− Payload::Response(_) => unreachable!(),
258− Payload::Request(_) => todo!(),
259− }
260 }
191 }
261 Some(callback) = self.jobs.futures.next() => {
192 Some(callback) = self.jobs.futures.next() => {
262 self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
193 self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
@@ -319,7 +250,83 @@ impl Application {
319 }
250 }
320 }
251 }
321
252
322− pub async fn handle_debugger_message(&mut self, _call: ()) {
253+ pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
254+ let mut debugger = match self.editor.debugger.as_mut() {
255+ Some(debugger) => debugger,
256+ None => return,
257+ };
258+
259+ match payload {
260+ Payload::Event(ev) => match &ev.event[..] {
261+ "stopped" => {
262+ debugger.is_running = false;
263+ let main = debugger
264+ .threads()
265+ .await
266+ .ok()
267+ .and_then(|threads| threads.get(0).cloned());
268+ if let Some(main) = main {
269+ let (bt, _) = debugger.stack_trace(main.id).await.unwrap();
270+ debugger.stack_pointer = bt.get(0).cloned();
271+ }
272+
273+ let body: helix_dap::events::Stopped =
274+ from_value(ev.body.expect("`stopped` event must have a body")).unwrap();
275+ let scope = match body.thread_id {
276+ Some(id) => format!("Thread {}", id),
277+ None => "Target".to_owned(),
278+ };
279+
280+ let mut status = format!("{} stopped because of {}", scope, body.reason);
281+ if let Some(desc) = body.description {
282+ status.push_str(&format!(" {}", desc));
283+ }
284+ if let Some(text) = body.text {
285+ status.push_str(&format!(" {}", text));
286+ }
287+ if body.all_threads_stopped == Some(true) {
288+ status.push_str(" (all threads stopped)");
289+ }
290+
291+ if let Some(helix_dap::StackFrame {
292+ source:
293+ Some(helix_dap::Source {
294+ path: Some(src), ..
295+ }),
296+ ..
297+ }) = &debugger.stack_pointer
298+ {
299+ let path = src.clone().into();
300+ self.editor
301+ .open(path, helix_view::editor::Action::Replace)
302+ .unwrap();
303+ }
304+ self.editor.set_status(status);
305+ self.render();
306+ }
307+ "output" => {
308+ let body: helix_dap::events::Output =
309+ from_value(ev.body.expect("`output` event must have a body")).unwrap();
310+
311+ let prefix = match body.category {
312+ Some(category) => format!("Debug ({}):", category),
313+ None => "Debug:".to_owned(),
314+ };
315+
316+ self.editor
317+ .set_status(format!("{} {}", prefix, body.output));
318+ self.render();
319+ }
320+ "initialized" => {
321+ self.editor
322+ .set_status("Debugged application started".to_owned());
323+ self.render();
324+ }
325+ _ => {}
326+ },
327+ Payload::Response(_) => unreachable!(),
328+ Payload::Request(_) => todo!(),
329+ }
323 // TODO
330 // TODO
324 }
331 }
325
332