From 8ffafb826faa75c76f74af3350d73adceb24e81d Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 30 Nov 2021 17:52:39 +0900 Subject: dap: Rewrite breakpoints so that there's a single set maintained --- helix-term/src/ui/editor.rs | 81 +++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 51 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index bae1edfb..a3421991 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -15,7 +15,6 @@ use helix_core::{ unicode::width::UnicodeWidthStr, LineEnding, Position, Range, Selection, }; -use helix_dap::{Breakpoint, SourceBreakpoint, StackFrame}; use helix_view::{ document::{Mode, SCRATCH_BUFFER_NAME}, graphics::{Color, CursorKind, Modifier, Rect, Style}, @@ -24,7 +23,7 @@ use helix_view::{ keyboard::{KeyCode, KeyModifiers}, Document, Editor, Theme, View, }; -use std::{borrow::Cow, collections::HashMap, path::PathBuf}; +use std::borrow::Cow; use crossterm::event::{Event, MouseButton, MouseEvent, MouseEventKind}; use tui::buffer::Buffer as Surface; @@ -74,7 +73,6 @@ impl EditorView { let inner = view.inner_area(); let area = view.area; let theme = &editor.theme; - let all_breakpoints = HashMap::new(); let highlights = Self::doc_syntax_highlights(doc, view.offset, inner.height, theme, loader); let highlights = syntax::merge(highlights, Self::doc_diagnostics_highlights(doc, theme)); @@ -107,7 +105,7 @@ impl EditorView { } } - self.render_diagnostics(doc, view, inner, surface, theme, &all_breakpoints); + self.render_diagnostics(doc, view, inner, surface, theme); let statusline_area = view .area @@ -436,39 +434,21 @@ impl EditorView { let error = theme.get("error"); let info = theme.get("info"); - let all_breakpoints = &editor.breakpoints; - - // TODO: debugger breakpoints should keep editor level breakpoints in sync - let breakpoints = doc .path() - .and_then(|path| all_breakpoints.get(path)) + .and_then(|path| editor.breakpoints.get(path)) .unwrap(); Box::new(move |line: usize, _selected: bool, out: &mut String| { - // TODO: debugger should translate received breakpoints to 0-indexing - let breakpoint = breakpoints.iter().find(|breakpoint| { - false - // if breakpoint.source == doc.path() { - // match (breakpoint.line, breakpoint.end_line) { - // #[allow(clippy::int_plus_one)] - // (Some(l), Some(el)) => l - 1 <= line && line <= el - 1, - // (Some(l), None) => l - 1 == line, - // _ => false, - // } - // } else { - // false - // } - }); + let breakpoint = breakpoints + .iter() + .find(|breakpoint| breakpoint.line == line); let breakpoint = match breakpoint { Some(b) => b, None => return None, }; - // let verified = breakpoint.verified; - let verified = false; - let mut style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() { error.add_modifier(Modifier::UNDERLINED) @@ -480,7 +460,7 @@ impl EditorView { warning }; - if !verified { + if !breakpoint.verified { // Faded colors style = if let Some(Color::Rgb(r, g, b)) = style.fg { style.fg(Color::Rgb( @@ -495,7 +475,7 @@ impl EditorView { // TODO: also handle breakpoints only present in the user struct use std::fmt::Write; - let sym = if verified { "▲" } else { "⊚" }; + let sym = if breakpoint.verified { "▲" } else { "⊚" }; write!(out, "{}", sym).unwrap(); Some(style) }) @@ -567,7 +547,6 @@ impl EditorView { viewport: Rect, surface: &mut Surface, theme: &Theme, - all_breakpoints: &HashMap>, ) { use helix_core::diagnostic::Severity; use tui::{ @@ -605,28 +584,28 @@ impl EditorView { lines.extend(text.lines); } - if let Some(path) = doc.path() { - let line = doc.text().char_to_line(cursor); - if let Some(breakpoints) = all_breakpoints.get(path) { - if let Some(breakpoint) = breakpoints - .iter() - .find(|breakpoint| breakpoint.line - 1 == line) - { - if let Some(condition) = &breakpoint.condition { - lines.extend( - Text::styled(condition, warning.add_modifier(Modifier::UNDERLINED)) - .lines, - ); - } - if let Some(log_message) = &breakpoint.log_message { - lines.extend( - Text::styled(log_message, info.add_modifier(Modifier::UNDERLINED)) - .lines, - ); - } - } - } - } + // let line = doc.text().char_to_line(cursor); + // let breakpoint = doc + // .path() + // .and_then(|path| all_breakpoints.get(path)) + // .and_then(|breakpoints| { + // breakpoints + // .iter() + // .find(|breakpoint| breakpoint.line == line) + // }); + + // if let Some(breakpoint) = breakpoint { + // if let Some(condition) = &breakpoint.condition { + // lines.extend( + // Text::styled(condition, warning.add_modifier(Modifier::UNDERLINED)).lines, + // ); + // } + // if let Some(log_message) = &breakpoint.log_message { + // lines.extend( + // Text::styled(log_message, info.add_modifier(Modifier::UNDERLINED)).lines, + // ); + // } + // } let paragraph = Paragraph::new(lines) .alignment(Alignment::Right) -- cgit v1.2.3-70-g09d2