Skip to content

Commit df3b883

Browse files
committed
dap: Improve variables UI
1 parent dac317e commit df3b883

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

helix-term/src/commands/dap.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,22 +619,41 @@ pub fn dap_variables(cx: &mut Context) {
619619
// TODO: group by scope
620620
// TODO: ui::Text to use tui::text + styled builder
621621

622+
// let contents = tui::text::Text::new();
623+
624+
let theme = &cx.editor.theme;
625+
let scope_style = theme.get("ui.linenr.selected");
626+
let type_style = theme.get("ui.text");
627+
let text_style = theme.get("ui.text.focus");
628+
622629
for scope in scopes.iter() {
630+
// use helix_view::graphics::Style;
631+
use tui::text::{Span, Spans};
623632
let response = block_on(debugger.variables(scope.variables_reference));
624633

634+
variables.push(Spans::from(Span::styled(
635+
format!("▸ {}", scope.name),
636+
scope_style,
637+
)));
638+
625639
if let Ok(vars) = response {
626640
variables.reserve(vars.len());
627641
for var in vars {
628-
let prefix = match var.ty {
629-
Some(data_type) => format!("{} ", data_type),
630-
None => "".to_owned(),
631-
};
632-
variables.push(format!("{}{} = {}", prefix, var.name, var.value));
642+
let mut spans = Vec::with_capacity(5);
643+
644+
spans.push(Span::styled(var.name.to_owned(), text_style));
645+
if let Some(ty) = var.ty {
646+
spans.push(Span::raw(": "));
647+
spans.push(Span::styled(ty.to_owned(), type_style));
648+
}
649+
spans.push(Span::raw(" = "));
650+
spans.push(Span::styled(var.value.to_owned(), text_style));
651+
variables.push(Spans::from(spans));
633652
}
634653
}
635654
}
636655

637-
let contents = Text::new(variables.join("\n"));
656+
let contents = Text::from(tui::text::Text::from(variables));
638657
let popup = Popup::new(contents);
639658
cx.push_layer(Box::new(popup));
640659
}

helix-term/src/ui/text.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,45 @@ use tui::buffer::Buffer as Surface;
44
use helix_view::graphics::Rect;
55

66
pub struct Text {
7-
contents: String,
7+
contents: tui::text::Text<'static>,
88
size: (u16, u16),
99
viewport: (u16, u16),
1010
}
1111

1212
impl Text {
1313
pub fn new(contents: String) -> Self {
14+
Self {
15+
contents: tui::text::Text::from(contents),
16+
size: (0, 0),
17+
viewport: (0, 0),
18+
}
19+
}
20+
}
21+
22+
impl From<tui::text::Text<'static>> for Text {
23+
fn from(contents: tui::text::Text<'static>) -> Self {
1424
Self {
1525
contents,
1626
size: (0, 0),
1727
viewport: (0, 0),
1828
}
1929
}
2030
}
31+
2132
impl Component for Text {
2233
fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
2334
use tui::widgets::{Paragraph, Widget, Wrap};
24-
let contents = tui::text::Text::from(self.contents.clone());
2535

26-
let par = Paragraph::new(contents).wrap(Wrap { trim: false });
36+
let par = Paragraph::new(self.contents.clone()).wrap(Wrap { trim: false });
2737
// .scroll(x, y) offsets
2838

2939
par.render(area, surface);
3040
}
3141

3242
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
3343
if viewport != self.viewport {
34-
let contents = tui::text::Text::from(self.contents.clone());
35-
let width = std::cmp::min(contents.width() as u16, viewport.0);
36-
let height = std::cmp::min(contents.height() as u16, viewport.1);
44+
let width = std::cmp::min(self.contents.width() as u16, viewport.0);
45+
let height = std::cmp::min(self.contents.height() as u16, viewport.1);
3746
self.size = (width, height);
3847
self.viewport = viewport;
3948
}

0 commit comments

Comments
 (0)