sync_lsp/text_document/
will_save.rs1use crate::{Server, TypeProvider};
8use crate::connection::{Callback, Endpoint};
9use serde::Deserialize;
10use serde_repr::Deserialize_repr;
11use super::TextDocumentIdentifer;
12
13#[derive(Default, Clone)]
14pub(crate) struct WillSaveOptions;
15
16#[repr(i32)]
18#[derive(Deserialize_repr, Debug)]
19pub enum TextDocumentSaveReason {
20 Manual = 1,
21 AfterDelay = 2,
22 FocusOut = 3
23}
24
25#[derive(Deserialize)]
26#[serde(rename_all = "camelCase")]
27struct WillSaveTextDocumentParams {
28 text_document: TextDocumentIdentifer,
29 reason: TextDocumentSaveReason
30}
31
32impl WillSaveOptions {
33
34 pub(crate) const METHOD: &'static str = "textDocument/willSave";
35
36 pub(super) fn endpoint<T: TypeProvider>() -> Endpoint<T, WillSaveOptions> {
37 Endpoint::new(Callback::notification(|_, _: WillSaveTextDocumentParams| ()))
38 }
39}
40
41impl<T: TypeProvider> Server<T> {
42
43 pub fn on_will_save(&mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, TextDocumentSaveReason)) {
52 self.text_document.will_save.set_callback(Callback::notification(move |server, params: WillSaveTextDocumentParams| {
53 callback(server, params.text_document, params.reason)
54 }))
55 }
56}