Skip to content

Commit

Permalink
chore(debug): address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Dutescu <[email protected]>
  • Loading branch information
filipdutescu committed Feb 13, 2023
1 parent 929e22f commit 3df9d6a
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 52 deletions.
5 changes: 3 additions & 2 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ These scopes are used for theming the editor interface.
| `ui.cursor.primary.normal` | |
| `ui.cursor.primary.insert` | |
| `ui.cursor.primary.select` | |
| `ui.highlight.breakpoint` | Color of the breakpoint signal, found in the gutter. |
| `ui.highlight.currentline` | Color of the current line, at which debugging execution is paused at. |
| `ui.debug.breakpoint` | Color of the breakpoint signal, found in the gutter. |
| `ui.debug.current` | Color of the current line at which debugging execution is paused at. |
| `ui.debug.indicator` | Gutter indicator for `ui.debug.current`. Falls back on `ui.debug.breakpoint`. |
| `ui.gutter` | Gutter |
| `ui.gutter.selected` | Gutter for the line the cursor is on |
| `ui.linenr` | Line numbers |
Expand Down
10 changes: 10 additions & 0 deletions helix-dap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,14 @@ impl Client {

self.call::<requests::SetExceptionBreakpoints>(args)
}

pub fn current_stack_frame(&self) -> Option<&StackFrame> {
if let (Some(frame), Some(thread_id)) = (self.active_frame, self.thread_id) {
self.stack_frames
.get(&thread_id)
.and_then(|bt| bt.get(frame))
} else {
None
}
}
}
40 changes: 16 additions & 24 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,48 +91,40 @@ impl EditorView {
let mut line_decorations: Vec<Box<dyn LineDecoration>> = Vec::new();
let mut translated_positions: Vec<TranslatedPosition> = Vec::new();

if is_focused && config.cursorline {
line_decorations.push(Self::cursorline_decorator(doc, view, theme))
}

if is_focused && config.cursorcolumn {
Self::highlight_cursorcolumn(doc, view, surface, theme, inner, &text_annotations);
}

// DAP: Highlight current stack frame position
let stack_frame = editor.debugger.as_ref().and_then(|debugger| {
if let (Some(frame), Some(thread_id)) = (debugger.active_frame, debugger.thread_id) {
debugger
.stack_frames
.get(&thread_id)
.and_then(|bt| bt.get(frame))
} else {
None
}
});
if let Some(frame) = stack_frame {
if let Some(frame) = editor.current_stack_frame() {
if doc.path().is_some()
&& frame
.source
.as_ref()
.and_then(|source| source.path.as_ref())
== doc.path()
{
let line = frame.line;
let style = theme.get("ui.highlight.currentline");
let line = frame.line - 1; // convert to 0-indexing
let style = theme.get("ui.debug.current");
let line_decoration = move |renderer: &mut TextRenderer, pos: LinePos| {
if pos.doc_line != line {
return;
}
renderer
.surface
.set_style(Rect::new(inner.x, pos.visual_line, inner.width, 1), style);

renderer.surface.set_style(
Rect::new(inner.x, inner.y + pos.visual_line, inner.width, 1),
style,
);
};

line_decorations.push(Box::new(line_decoration));
}
}

if stack_frame.is_none() && is_focused && config.cursorline {
line_decorations.push(Self::cursorline_decorator(doc, view, theme))
}

if stack_frame.is_none() && is_focused && config.cursorcolumn {
Self::highlight_cursorcolumn(doc, view, surface, theme, inner, &text_annotations);
}

let mut highlights =
Self::doc_syntax_highlights(doc, view.offset.anchor, inner.height, theme);
let overlay_highlights = Self::overlay_syntax_highlights(
Expand Down
12 changes: 12 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
view::ViewPosition,
Align, Document, DocumentId, View, ViewId,
};
use dap::StackFrame;
use helix_vcs::DiffProviderRegistry;

use futures_util::stream::select_all::SelectAll;
Expand Down Expand Up @@ -1650,6 +1651,17 @@ impl Editor {
doc.restore_cursor = false;
}
}

pub fn current_stack_frame(&self) -> Option<&StackFrame> {
let debugger = match self.debugger.as_ref() {
Some(debugger) => debugger,
None => {
return None;
}
};

debugger.current_stack_frame()
}
}

fn try_restore_indent(doc: &mut Document, view: &mut View) {
Expand Down
60 changes: 45 additions & 15 deletions helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Write;

use crate::{
editor::GutterType,
graphics::{Color, Style, UnderlineStyle},
graphics::{Style, UnderlineStyle},
Document, Editor, Theme, View,
};

Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn breakpoints<'doc>(
) -> GutterFn<'doc> {
let error = theme.get("error");
let info = theme.get("info");
let breakpoint_style = theme.get("ui.highlight.breakpoint");
let breakpoint_style = theme.get("ui.debug.breakpoint");

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

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

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

if !breakpoint.verified {
// Faded colors
style = if let Some(Color::Rgb(r, g, b)) = breakpoint_style.fg {
style.fg(Color::Rgb(
((r as f32) * 0.7).floor() as u8,
((g as f32) * 0.7).floor() as u8,
((b as f32) * 0.7).floor() as u8,
))
} else {
style.fg(Color::Gray)
let sym = if breakpoint.verified { "●" } else { "◯" };
write!(out, "{}", sym).unwrap();
Some(style)
},
)
}

fn execution_pause_indicator<'doc>(
editor: &'doc Editor,
doc: &'doc Document,
theme: &Theme,
is_focused: bool,
) -> GutterFn<'doc> {
let mut style = theme.get("ui.debug.indicator");
if style == Style::default() {
style = theme.get("ui.debug.breakpoint");
}

Box::new(
move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
if !first_visual_line || !is_focused {
return None;
}

let current_stack_frame = match editor.current_stack_frame() {
Some(frame) => frame,
None => {
return None;
}
};
if line != current_stack_frame.line - 1
|| doc.path().is_none()
|| current_stack_frame
.source
.as_ref()
.and_then(|source| source.path.as_ref())
!= doc.path()
{
return None;
}

let sym = "";
let sym = "";
write!(out, "{}", sym).unwrap();
Some(style)
},
Expand All @@ -304,9 +332,11 @@ pub fn diagnostics_or_breakpoints<'doc>(
) -> GutterFn<'doc> {
let mut diagnostics = diagnostic(editor, doc, view, theme, is_focused);
let mut breakpoints = breakpoints(editor, doc, view, theme, is_focused);
let mut execution_pause_indicator = execution_pause_indicator(editor, doc, theme, is_focused);

Box::new(move |line, selected, first_visual_line: bool, out| {
breakpoints(line, selected, first_visual_line, out)
execution_pause_indicator(line, selected, first_visual_line, out)
.or_else(|| breakpoints(line, selected, first_visual_line, out))
.or_else(|| diagnostics(line, selected, first_visual_line, out))
})
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/themes/dracula.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"ui.cursor.primary" = { fg = "background", bg = "cyan", modifiers = ["dim"] }
"ui.cursorline.primary" = { bg = "background_dark" }
"ui.help" = { fg = "foreground", bg = "background_dark" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.debug.breakpoint" = { fg = "red" }
"ui.debug.current" = { fg = "black", bg = "red" }
"ui.linenr" = { fg = "comment" }
"ui.linenr.selected" = { fg = "foreground" }
"ui.menu" = { fg = "foreground", bg = "background_dark" }
Expand Down
4 changes: 2 additions & 2 deletions runtime/themes/dracula_at_night.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"ui.cursor.match" = { fg = "green", modifiers = ["underlined"] }
"ui.cursor.primary" = { fg = "background", bg = "cyan", modifiers = ["dim"] }
"ui.help" = { fg = "foreground", bg = "background_dark" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.debug.breakpoint" = { fg = "red" }
"ui.debug.current" = { fg = "black", bg = "red" }
"ui.linenr" = { fg = "comment" }
"ui.linenr.selected" = { fg = "foreground" }
"ui.menu" = { fg = "foreground", bg = "background_dark" }
Expand Down
4 changes: 2 additions & 2 deletions runtime/themes/onedark.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"ui.text.focus" = { fg = "white", bg = "light-black", modifiers = ["bold"] }

"ui.help" = { fg = "white", bg = "gray" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.debug.breakpoint" = { fg = "red" }
"ui.debug.current" = { fg = "black", bg = "red" }
"ui.popup" = { bg = "gray" }
"ui.window" = { fg = "gray" }
"ui.menu" = { fg = "white", bg = "gray" }
Expand Down
4 changes: 2 additions & 2 deletions runtime/themes/onedarker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"ui.text.focus" = { fg = "white", bg = "light-black", modifiers = ["bold"] }

"ui.help" = { fg = "white", bg = "gray" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.debug.breakpoint" = { fg = "red" }
"ui.debug.current" = { fg = "black", bg = "red" }
"ui.popup" = { bg = "gray" }
"ui.window" = { fg = "gray" }
"ui.menu" = { fg = "white", bg = "gray" }
Expand Down
6 changes: 3 additions & 3 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ label = "honey"
"ui.cursor.match" = { fg = "#212121", bg = "#6C6999" }
"ui.cursor" = { modifiers = ["reversed"] }
"ui.cursorline.primary" = { bg = "bossanova" }
"ui.highlight" = { bg = "bossanova" }
"ui.highlight.breakpoint" = { fg = "apricot" }
"ui.highlight.currentline" = { fg = "bossanova", bg = "apricot", modifiers = ["bold"] }
"ui.debug.breakpoint" = { fg = "apricot" }
"ui.debug.current" = { fg = "bossanova", bg = "lilac" }
"ui.debug.indicator" = { fg = "lilac" }

"ui.menu" = { fg = "lavender", bg = "revolver" }
"ui.menu.selected" = { fg = "revolver", bg = "white" }
Expand Down

0 comments on commit 3df9d6a

Please sign in to comment.