on master help sign in
dap: Highlight line of current stack frame
dfd499fBlaž Hrastnik
helix-term/src/ui/editor.rs+34−55
@@ -72,6 +72,40 @@ impl EditorView {
72 let area = view.area;
72 let area = view.area;
73 let theme = &editor.theme;
73 let theme = &editor.theme;
74
74
75+ // DAP: Highlight current stack frame position
76+ let stack_frame = editor.debugger.as_ref().and_then(|debugger| {
77+ if let (Some(frame), Some(thread_id)) = (debugger.active_frame, debugger.thread_id) {
78+ debugger
79+ .stack_frames
80+ .get(&thread_id)
81+ .and_then(|bt| bt.get(frame))
82+ } else {
83+ None
84+ }
85+ });
86+ if let Some(frame) = stack_frame {
87+ if doc.path().is_some()
88+ && frame
89+ .source
90+ .as_ref()
91+ .and_then(|source| source.path.as_ref())
92+ == doc.path()
93+ {
94+ let line = frame.line - 1; // convert to 0-indexing
95+ if line >= view.offset.row && line < view.offset.row + area.height as usize {
96+ surface.set_style(
97+ Rect::new(
98+ area.x,
99+ area.y + (line - view.offset.row) as u16,
100+ area.width,
101+ 1,
102+ ),
103+ theme.get("ui.highlight"),
104+ );
105+ }
106+ }
107+ }
108+
75 let highlights =
109 let highlights =
76 Self::doc_syntax_highlights(doc, view.offset, inner.height, theme, &editor.syn_loader);
110 Self::doc_syntax_highlights(doc, view.offset, inner.height, theme, &editor.syn_loader);
77 let highlights = syntax::merge(highlights, Self::doc_diagnostics_highlights(doc, theme));
111 let highlights = syntax::merge(highlights, Self::doc_diagnostics_highlights(doc, theme));
@@ -417,38 +451,6 @@ impl EditorView {
417 .map(|range| range.cursor_line(text))
451 .map(|range| range.cursor_line(text))
418 .collect();
452 .collect();
419
453
420− // let mut stack_frame: Option<&StackFrame> = None;
421− // if let Some(path) = doc.path() {
422− // if let Some(debugger) = debugger {
423− // // if we have a frame, and the frame path matches document
424− // if let (Some(frame), Some(thread_id)) = (debugger.active_frame, debugger.thread_id)
425− // {
426− // let frame = debugger
427− // .stack_frames
428− // .get(&thread_id)
429− // .and_then(|bt| bt.get(frame)); // TODO: drop the clone..
430− // if let Some(StackFrame {
431− // source: Some(source),
432− // ..
433− // }) = &frame
434− // {
435− // if source.path.as_ref() == Some(path) {
436− // stack_frame = frame;
437− // }
438− // };
439− // };
440− // }
441− // }
442− // if let Some(frame) = stack_frame {
443− // if frame.line - 1 == line {
444− // surface.set_style(
445− // Rect::new(viewport.x, viewport.y + i as u16, 6, 1),
446− // helix_view::graphics::Style::default()
447− // .bg(helix_view::graphics::Color::LightYellow),
448− // );
449− // }
450− // }
451−
452 let mut offset = 0;
454 let mut offset = 0;
453
455
454 // avoid lots of small allocations by reusing a text buffer for each line
456 // avoid lots of small allocations by reusing a text buffer for each line
@@ -520,29 +522,6 @@ impl EditorView {
520 lines.extend(text.lines);
522 lines.extend(text.lines);
521 }
523 }
522
524
523− // let line = doc.text().char_to_line(cursor);
524− // let breakpoint = doc
525− // .path()
526− // .and_then(|path| all_breakpoints.get(path))
527− // .and_then(|breakpoints| {
528− // breakpoints
529− // .iter()
530− // .find(|breakpoint| breakpoint.line == line)
531− // });
532−
533− // if let Some(breakpoint) = breakpoint {
534− // if let Some(condition) = &breakpoint.condition {
535− // lines.extend(
536− // Text::styled(condition, warning.add_modifier(Modifier::UNDERLINED)).lines,
537− // );
538− // }
539− // if let Some(log_message) = &breakpoint.log_message {
540− // lines.extend(
541− // Text::styled(log_message, info.add_modifier(Modifier::UNDERLINED)).lines,
542− // );
543− // }
544− // }
545−
546 let paragraph = Paragraph::new(lines)
525 let paragraph = Paragraph::new(lines)
547 .alignment(Alignment::Right)
526 .alignment(Alignment::Right)
548 .wrap(Wrap { trim: true });
527 .wrap(Wrap { trim: true });