helix/helix-view/src/handlers.rs
Hendrik Wolff 265608a3d8
Auto Save All Buffers After A Delay (#10899)
* auto save after delay

* configable

* clearer names

* init

* working with some odd behaviour

* working with greater consistency

* Apply reviewer suggestions

- Remove unneccessary field
- Remove blocking save

* Improve auto-save configuration

Auto save can be configured to trigger on focus loss:
```toml
auto-save.focus-lost = true|false
```

and after a time delay (in milli seconds) since last keypress:
```toml
auto-save.after-delay.enable = true|false
auto-save.after-delay.timeout = [0, u64::MAX] # default: 3000
```

* Remove boilerplate and unnecessary types

* Remove more useless types

* Update docs for auto-save.after-delay

* Fix wording of (doc) comments relating to auto-save

* book: Move auto-save descriptions to separate section

---------

Co-authored-by: Miguel Perez <miguelvojito@gmail.com>
Co-authored-by: Miguel Perez <perezoji@cs.fsu.edu>
2024-06-11 00:39:06 +02:00

42 lines
1.3 KiB
Rust

use helix_event::send_blocking;
use tokio::sync::mpsc::Sender;
use crate::handlers::lsp::SignatureHelpInvoked;
use crate::{DocumentId, Editor, ViewId};
pub mod dap;
pub mod lsp;
pub struct Handlers {
// only public because most of the actual implementation is in helix-term right now :/
pub completions: Sender<lsp::CompletionEvent>,
pub signature_hints: Sender<lsp::SignatureHelpEvent>,
pub auto_save: Sender<u64>,
}
impl Handlers {
/// Manually trigger completion (c-x)
pub fn trigger_completions(&self, trigger_pos: usize, doc: DocumentId, view: ViewId) {
send_blocking(
&self.completions,
lsp::CompletionEvent::ManualTrigger {
cursor: trigger_pos,
doc,
view,
},
);
}
pub fn trigger_signature_help(&self, invocation: SignatureHelpInvoked, editor: &Editor) {
let event = match invocation {
SignatureHelpInvoked::Automatic => {
if !editor.config().lsp.auto_signature_help {
return;
}
lsp::SignatureHelpEvent::Trigger
}
SignatureHelpInvoked::Manual => lsp::SignatureHelpEvent::Invoked,
};
send_blocking(&self.signature_hints, event)
}
}