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.
This commit is contained in:
Michael Davis 2025-03-25 08:52:46 -04:00
parent 04d1180a0c
commit d43de14807
No known key found for this signature in database

View file

@ -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(())
});