From 80d520f46966e7cb34d0dccb7270ea72e2e3d4fd Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Sun, 3 Mar 2024 23:13:22 +0100 Subject: [PATCH] refactor DocumentDidChange events in the past DocumentDidChange and SelectionDidChange events were implemented in a simplistic manner to get a simple prototype out. However, if you want to use these events in more complex scenarios with interdependencies between the two handlers the system fell short. The `SelectionDidChange` event was dispatched before the DocumentDidChange (and not at all if the selection wasn't manually set) so any handlers that wants to track selection was not able to map their ranges yet. The reason for this was actually the way that apply_impl was structured. The function was slightly refactored to address these problems and enable moving other range mappings to event handlers. --- helix-term/src/handlers/signature_help.rs | 2 +- helix-view/src/document.rs | 2 ++ helix-view/src/events.rs | 10 ++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/helix-term/src/handlers/signature_help.rs b/helix-term/src/handlers/signature_help.rs index aaa97b9a0..823ea3aaf 100644 --- a/helix-term/src/handlers/signature_help.rs +++ b/helix-term/src/handlers/signature_help.rs @@ -354,7 +354,7 @@ pub(super) fn register_hooks(handlers: &Handlers) { let tx = handlers.signature_hints.clone(); register_hook!(move |event: &mut DocumentDidChange<'_>| { - if event.doc.config.load().lsp.auto_signature_help { + if event.doc.config.load().lsp.auto_signature_help && !event.ghost_transaction { send_blocking(&tx, SignatureHelpEvent::ReTrigger); } Ok(()) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 489555112..2b2c8ace5 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1360,6 +1360,8 @@ impl Document { doc: self, view: view_id, old_text: &old_doc, + changes, + ghost_transaction: !emit_lsp_notification, }); // if specified, the current selection should instead be replaced by transaction.selection diff --git a/helix-view/src/events.rs b/helix-view/src/events.rs index 881412495..136d60c51 100644 --- a/helix-view/src/events.rs +++ b/helix-view/src/events.rs @@ -1,10 +1,16 @@ -use helix_core::Rope; +use helix_core::{ChangeSet, Rope}; use helix_event::events; use crate::{Document, DocumentId, Editor, ViewId}; events! { - DocumentDidChange<'a> { doc: &'a mut Document, view: ViewId, old_text: &'a Rope } + DocumentDidChange<'a> { + doc: &'a mut Document, + view: ViewId, + old_text: &'a Rope, + changes: &'a ChangeSet, + ghost_transaction: bool + } SelectionDidChange<'a> { doc: &'a mut Document, view: ViewId } DiagnosticsDidChange<'a> { editor: &'a mut Editor, doc: DocumentId } }