diff --git a/core/src/buffer.rs b/core/src/buffer.rs index 983510db..2f4245b9 100644 --- a/core/src/buffer.rs +++ b/core/src/buffer.rs @@ -11,8 +11,8 @@ use druid::{Env, PaintCtx}; use git2::Repository; use language::{new_highlight_config, new_parser, LapceLanguage}; -use lsp_types::SemanticTokensLegend; use lsp_types::SemanticTokensServerCapabilities; +use lsp_types::{CallHierarchyOptions, SemanticTokensLegend}; use lsp_types::{ CodeActionResponse, Position, Range, TextDocumentContentChangeEvent, }; @@ -200,6 +200,7 @@ pub struct BufferNew { pub loaded: bool, pub local: bool, update_sender: Arc>, + pub line_changes: HashMap, revs: Vec, cur_undo: usize, @@ -241,6 +242,7 @@ pub fn new(path: PathBuf, update_sender: Arc>) -> Self { dirty: false, update_sender, local: false, + line_changes: HashMap::new(), revs: vec![Revision { max_undo_so_far: 0, diff --git a/core/src/command.rs b/core/src/command.rs index 475a6518..e8b39f98 100644 --- a/core/src/command.rs +++ b/core/src/command.rs @@ -274,6 +274,7 @@ pub enum LapceUICommand { tree: Tree, }, CenterOfWindow, + UpdateBufferLineChanges(BufferId, u64, HashMap), UpdateLineChanges(BufferId), PublishDiagnostics(PublishDiagnosticsParams), UpdateDiffFiles(Vec), diff --git a/core/src/editor.rs b/core/src/editor.rs index 72bd9472..e2d8c9be 100644 --- a/core/src/editor.rs +++ b/core/src/editor.rs @@ -854,7 +854,7 @@ fn paint_code_actions_hint( let height = 16.0; let rect = Size::new(width, height).to_rect().with_origin(Point::new( - self.width + 5.0, + self.width + 7.6171875 + 3.0, (line_height - height) / 2.0 + line_height * line as f64 - data.editor.scroll_offset.y, )); @@ -930,7 +930,7 @@ fn layout( let last_line = data.buffer.last_line() + 1; let width = 7.6171875; self.width = (width * last_line.to_string().len() as f64).ceil(); - let width = self.width + 26.0; + let width = self.width + 16.0 + width * 2.0; Size::new(width, bc.max().height) } @@ -974,6 +974,33 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { .build() .unwrap(); ctx.draw_text(&text_layout, pos); + + if let Some(line_change) = data.buffer.line_changes.get(&line) { + let x = self.width + width; + let y = line as f64 * line_height - scroll_offset.y; + let origin = Point::new(x, y); + let size = Size::new(3.0, line_height); + let rect = Rect::ZERO.with_origin(origin).with_size(size); + match line_change { + 'm' => { + ctx.fill(rect, &Color::rgba8(1, 132, 188, 180)); + } + '+' => { + ctx.fill(rect, &Color::rgba8(80, 161, 79, 180)); + } + '-' => { + let size = Size::new(3.0, 10.0); + let x = self.width + width; + let y = line as f64 * line_height + - size.height / 2.0 + - scroll_offset.y; + let origin = Point::new(x, y); + let rect = Rect::ZERO.with_origin(origin).with_size(size); + ctx.fill(rect, &Color::rgba8(228, 86, 73, 180)); + } + _ => {} + } + } } if *data.main_split.active == self.view_id { diff --git a/core/src/proxy.rs b/core/src/proxy.rs index 162419e1..d4745b01 100644 --- a/core/src/proxy.rs +++ b/core/src/proxy.rs @@ -572,7 +572,17 @@ fn handle_notification( buffer_id, line_changes, rev, - } => {} + } => { + self.event_sink.submit_command( + LAPCE_UI_COMMAND, + LapceUICommand::UpdateBufferLineChanges( + buffer_id, + rev, + line_changes, + ), + Target::Widget(self.tab_id), + ); + } Notification::ReloadBuffer { buffer_id, new_content, diff --git a/core/src/tab.rs b/core/src/tab.rs index d9109c8e..54755cfe 100644 --- a/core/src/tab.rs +++ b/core/src/tab.rs @@ -346,6 +346,22 @@ fn event( } ctx.set_handled(); } + LapceUICommand::UpdateBufferLineChanges( + id, + rev, + line_changes, + ) => { + for (_, buffer) in data.main_split.open_files.iter_mut() { + if &buffer.id == id { + if buffer.rev == *rev { + let buffer = Arc::make_mut(buffer); + buffer.line_changes = line_changes.to_owned(); + } + break; + } + } + ctx.set_handled(); + } LapceUICommand::UpdateSemanticTokens(id, path, rev, tokens) => { let buffer = data.main_split.open_files.get_mut(path).unwrap();