Unnamed repository; edit this file 'description' to name the repository.
LSP: Avoid requesting document colors for ghost transactions
The point of ghost transactions is to avoid notifying language servers about changes since the change is meant to be temporary. This is used for completion while selecting items in the menu: updating the language server would mess up incomplete completions. When a document is changed by a ghost transaction the language server will not be notified so its understanding of the document will not be synchronized and any positions it sends may be out-of-date. So we should avoid triggering a request for new document color information when a document is changed by a ghost transaction.
Michael Davis 11 months ago
parent 04d1180 · commit d43de14
-rw-r--r--helix-term/src/handlers/document_colors.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/helix-term/src/handlers/document_colors.rs b/helix-term/src/handlers/document_colors.rs
index cffe5688..956cecbf 100644
--- a/helix-term/src/handlers/document_colors.rs
+++ b/helix-term/src/handlers/document_colors.rs
@@ -167,10 +167,14 @@ pub(super) fn register_hooks(handlers: &Handlers) {
apply_color_swatch_changes(color_swatches_padding);
}
- // Cancel the ongoing request, if present.
- event.doc.color_swatch_controller.cancel();
-
- helix_event::send_blocking(&tx, DocumentColorsEvent(event.doc.id()));
+ // Avoid re-requesting document colors if the change is a ghost transaction (completion)
+ // because the language server will not know about the updates to the document and will
+ // give out-of-date locations.
+ if !event.ghost_transaction {
+ // Cancel the ongoing request, if present.
+ event.doc.color_swatch_controller.cancel();
+ helix_event::send_blocking(&tx, DocumentColorsEvent(event.doc.id()));
+ }
Ok(())
});