Skip to content

Commit 3df9d6a

Browse files
committed
chore(debug): address comments
Signed-off-by: Filip Dutescu <[email protected]>
1 parent 929e22f commit 3df9d6a

File tree

10 files changed

+97
-52
lines changed

10 files changed

+97
-52
lines changed

book/src/themes.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ These scopes are used for theming the editor interface.
260260
| `ui.cursor.primary.normal` | |
261261
| `ui.cursor.primary.insert` | |
262262
| `ui.cursor.primary.select` | |
263-
| `ui.highlight.breakpoint` | Color of the breakpoint signal, found in the gutter. |
264-
| `ui.highlight.currentline` | Color of the current line, at which debugging execution is paused at. |
263+
| `ui.debug.breakpoint` | Color of the breakpoint signal, found in the gutter. |
264+
| `ui.debug.current` | Color of the current line at which debugging execution is paused at. |
265+
| `ui.debug.indicator` | Gutter indicator for `ui.debug.current`. Falls back on `ui.debug.breakpoint`. |
265266
| `ui.gutter` | Gutter |
266267
| `ui.gutter.selected` | Gutter for the line the cursor is on |
267268
| `ui.linenr` | Line numbers |

helix-dap/src/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,14 @@ impl Client {
477477

478478
self.call::<requests::SetExceptionBreakpoints>(args)
479479
}
480+
481+
pub fn current_stack_frame(&self) -> Option<&StackFrame> {
482+
if let (Some(frame), Some(thread_id)) = (self.active_frame, self.thread_id) {
483+
self.stack_frames
484+
.get(&thread_id)
485+
.and_then(|bt| bt.get(frame))
486+
} else {
487+
None
488+
}
489+
}
480490
}

helix-term/src/ui/editor.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,48 +91,40 @@ impl EditorView {
9191
let mut line_decorations: Vec<Box<dyn LineDecoration>> = Vec::new();
9292
let mut translated_positions: Vec<TranslatedPosition> = Vec::new();
9393

94+
if is_focused && config.cursorline {
95+
line_decorations.push(Self::cursorline_decorator(doc, view, theme))
96+
}
97+
98+
if is_focused && config.cursorcolumn {
99+
Self::highlight_cursorcolumn(doc, view, surface, theme, inner, &text_annotations);
100+
}
101+
94102
// DAP: Highlight current stack frame position
95-
let stack_frame = editor.debugger.as_ref().and_then(|debugger| {
96-
if let (Some(frame), Some(thread_id)) = (debugger.active_frame, debugger.thread_id) {
97-
debugger
98-
.stack_frames
99-
.get(&thread_id)
100-
.and_then(|bt| bt.get(frame))
101-
} else {
102-
None
103-
}
104-
});
105-
if let Some(frame) = stack_frame {
103+
if let Some(frame) = editor.current_stack_frame() {
106104
if doc.path().is_some()
107105
&& frame
108106
.source
109107
.as_ref()
110108
.and_then(|source| source.path.as_ref())
111109
== doc.path()
112110
{
113-
let line = frame.line;
114-
let style = theme.get("ui.highlight.currentline");
111+
let line = frame.line - 1; // convert to 0-indexing
112+
let style = theme.get("ui.debug.current");
115113
let line_decoration = move |renderer: &mut TextRenderer, pos: LinePos| {
116114
if pos.doc_line != line {
117115
return;
118116
}
119-
renderer
120-
.surface
121-
.set_style(Rect::new(inner.x, pos.visual_line, inner.width, 1), style);
117+
118+
renderer.surface.set_style(
119+
Rect::new(inner.x, inner.y + pos.visual_line, inner.width, 1),
120+
style,
121+
);
122122
};
123123

124124
line_decorations.push(Box::new(line_decoration));
125125
}
126126
}
127127

128-
if stack_frame.is_none() && is_focused && config.cursorline {
129-
line_decorations.push(Self::cursorline_decorator(doc, view, theme))
130-
}
131-
132-
if stack_frame.is_none() && is_focused && config.cursorcolumn {
133-
Self::highlight_cursorcolumn(doc, view, surface, theme, inner, &text_annotations);
134-
}
135-
136128
let mut highlights =
137129
Self::doc_syntax_highlights(doc, view.offset.anchor, inner.height, theme);
138130
let overlay_highlights = Self::overlay_syntax_highlights(

helix-view/src/editor.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
view::ViewPosition,
1111
Align, Document, DocumentId, View, ViewId,
1212
};
13+
use dap::StackFrame;
1314
use helix_vcs::DiffProviderRegistry;
1415

1516
use futures_util::stream::select_all::SelectAll;
@@ -1650,6 +1651,17 @@ impl Editor {
16501651
doc.restore_cursor = false;
16511652
}
16521653
}
1654+
1655+
pub fn current_stack_frame(&self) -> Option<&StackFrame> {
1656+
let debugger = match self.debugger.as_ref() {
1657+
Some(debugger) => debugger,
1658+
None => {
1659+
return None;
1660+
}
1661+
};
1662+
1663+
debugger.current_stack_frame()
1664+
}
16531665
}
16541666

16551667
fn try_restore_indent(doc: &mut Document, view: &mut View) {

helix-view/src/gutter.rs

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt::Write;
22

33
use crate::{
44
editor::GutterType,
5-
graphics::{Color, Style, UnderlineStyle},
5+
graphics::{Style, UnderlineStyle},
66
Document, Editor, Theme, View,
77
};
88

@@ -247,7 +247,7 @@ pub fn breakpoints<'doc>(
247247
) -> GutterFn<'doc> {
248248
let error = theme.get("error");
249249
let info = theme.get("info");
250-
let breakpoint_style = theme.get("ui.highlight.breakpoint");
250+
let breakpoint_style = theme.get("ui.debug.breakpoint");
251251

252252
let breakpoints = doc.path().and_then(|path| editor.breakpoints.get(path));
253253

@@ -265,7 +265,7 @@ pub fn breakpoints<'doc>(
265265
.iter()
266266
.find(|breakpoint| breakpoint.line == line)?;
267267

268-
let mut style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() {
268+
let style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() {
269269
error.underline_style(UnderlineStyle::Line)
270270
} else if breakpoint.condition.is_some() {
271271
error
@@ -275,20 +275,48 @@ pub fn breakpoints<'doc>(
275275
breakpoint_style
276276
};
277277

278-
if !breakpoint.verified {
279-
// Faded colors
280-
style = if let Some(Color::Rgb(r, g, b)) = breakpoint_style.fg {
281-
style.fg(Color::Rgb(
282-
((r as f32) * 0.7).floor() as u8,
283-
((g as f32) * 0.7).floor() as u8,
284-
((b as f32) * 0.7).floor() as u8,
285-
))
286-
} else {
287-
style.fg(Color::Gray)
278+
let sym = if breakpoint.verified { "●" } else { "◯" };
279+
write!(out, "{}", sym).unwrap();
280+
Some(style)
281+
},
282+
)
283+
}
284+
285+
fn execution_pause_indicator<'doc>(
286+
editor: &'doc Editor,
287+
doc: &'doc Document,
288+
theme: &Theme,
289+
is_focused: bool,
290+
) -> GutterFn<'doc> {
291+
let mut style = theme.get("ui.debug.indicator");
292+
if style == Style::default() {
293+
style = theme.get("ui.debug.breakpoint");
294+
}
295+
296+
Box::new(
297+
move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
298+
if !first_visual_line || !is_focused {
299+
return None;
300+
}
301+
302+
let current_stack_frame = match editor.current_stack_frame() {
303+
Some(frame) => frame,
304+
None => {
305+
return None;
288306
}
289307
};
308+
if line != current_stack_frame.line - 1
309+
|| doc.path().is_none()
310+
|| current_stack_frame
311+
.source
312+
.as_ref()
313+
.and_then(|source| source.path.as_ref())
314+
!= doc.path()
315+
{
316+
return None;
317+
}
290318

291-
let sym = "";
319+
let sym = "";
292320
write!(out, "{}", sym).unwrap();
293321
Some(style)
294322
},
@@ -304,9 +332,11 @@ pub fn diagnostics_or_breakpoints<'doc>(
304332
) -> GutterFn<'doc> {
305333
let mut diagnostics = diagnostic(editor, doc, view, theme, is_focused);
306334
let mut breakpoints = breakpoints(editor, doc, view, theme, is_focused);
335+
let mut execution_pause_indicator = execution_pause_indicator(editor, doc, theme, is_focused);
307336

308337
Box::new(move |line, selected, first_visual_line: bool, out| {
309-
breakpoints(line, selected, first_visual_line, out)
338+
execution_pause_indicator(line, selected, first_visual_line, out)
339+
.or_else(|| breakpoints(line, selected, first_visual_line, out))
310340
.or_else(|| diagnostics(line, selected, first_visual_line, out))
311341
})
312342
}

runtime/themes/dracula.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"ui.cursor.primary" = { fg = "background", bg = "cyan", modifiers = ["dim"] }
2626
"ui.cursorline.primary" = { bg = "background_dark" }
2727
"ui.help" = { fg = "foreground", bg = "background_dark" }
28-
"ui.highlight.breakpoint" = { fg = "red" }
29-
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
28+
"ui.debug.breakpoint" = { fg = "red" }
29+
"ui.debug.current" = { fg = "black", bg = "red" }
3030
"ui.linenr" = { fg = "comment" }
3131
"ui.linenr.selected" = { fg = "foreground" }
3232
"ui.menu" = { fg = "foreground", bg = "background_dark" }

runtime/themes/dracula_at_night.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"ui.cursor.match" = { fg = "green", modifiers = ["underlined"] }
2626
"ui.cursor.primary" = { fg = "background", bg = "cyan", modifiers = ["dim"] }
2727
"ui.help" = { fg = "foreground", bg = "background_dark" }
28-
"ui.highlight.breakpoint" = { fg = "red" }
29-
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
28+
"ui.debug.breakpoint" = { fg = "red" }
29+
"ui.debug.current" = { fg = "black", bg = "red" }
3030
"ui.linenr" = { fg = "comment" }
3131
"ui.linenr.selected" = { fg = "foreground" }
3232
"ui.menu" = { fg = "foreground", bg = "background_dark" }

runtime/themes/onedark.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
"ui.text.focus" = { fg = "white", bg = "light-black", modifiers = ["bold"] }
7979

8080
"ui.help" = { fg = "white", bg = "gray" }
81-
"ui.highlight.breakpoint" = { fg = "red" }
82-
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
81+
"ui.debug.breakpoint" = { fg = "red" }
82+
"ui.debug.current" = { fg = "black", bg = "red" }
8383
"ui.popup" = { bg = "gray" }
8484
"ui.window" = { fg = "gray" }
8585
"ui.menu" = { fg = "white", bg = "gray" }

runtime/themes/onedarker.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
"ui.text.focus" = { fg = "white", bg = "light-black", modifiers = ["bold"] }
7979

8080
"ui.help" = { fg = "white", bg = "gray" }
81-
"ui.highlight.breakpoint" = { fg = "red" }
82-
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
81+
"ui.debug.breakpoint" = { fg = "red" }
82+
"ui.debug.current" = { fg = "black", bg = "red" }
8383
"ui.popup" = { bg = "gray" }
8484
"ui.window" = { fg = "gray" }
8585
"ui.menu" = { fg = "white", bg = "gray" }

theme.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ label = "honey"
6868
"ui.cursor.match" = { fg = "#212121", bg = "#6C6999" }
6969
"ui.cursor" = { modifiers = ["reversed"] }
7070
"ui.cursorline.primary" = { bg = "bossanova" }
71-
"ui.highlight" = { bg = "bossanova" }
72-
"ui.highlight.breakpoint" = { fg = "apricot" }
73-
"ui.highlight.currentline" = { fg = "bossanova", bg = "apricot", modifiers = ["bold"] }
71+
"ui.debug.breakpoint" = { fg = "apricot" }
72+
"ui.debug.current" = { fg = "bossanova", bg = "lilac" }
73+
"ui.debug.indicator" = { fg = "lilac" }
7474

7575
"ui.menu" = { fg = "lavender", bg = "revolver" }
7676
"ui.menu.selected" = { fg = "revolver", bg = "white" }

0 commit comments

Comments
 (0)