sync_lsp/text_document/
did_save.rs1use crate::{Server, TypeProvider};
10use crate::connection::{Callback, Endpoint};
11use serde::Deserialize;
12use super::TextDocumentIdentifer;
13use serde::Serialize;
14
15#[derive(Serialize, Default, Clone)]
16#[serde(rename_all = "camelCase")]
17pub(crate) struct DidSaveOptions {
18 include_text: bool
19}
20
21#[derive(Deserialize)]
22#[serde(rename_all = "camelCase")]
23struct DidSaveTextDocumentParams {
24 text_document: TextDocumentIdentifer,
25 text: Option<String>,
26}
27
28
29impl DidSaveOptions {
30
31 pub(crate) const METHOD: &'static str = "textDocument/didSave";
32
33 pub(super) fn endpoint<T: TypeProvider>() -> Endpoint<T, DidSaveOptions> {
34 Endpoint::new(Callback::notification(|_, _: DidSaveTextDocumentParams| ()))
35 }
36}
37
38impl<T: TypeProvider> Server<T> {
39
40 pub fn on_save(&mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Option<String>)) {
49 self.text_document.did_save.set_callback(Callback::notification(move |server, params: DidSaveTextDocumentParams| {
50 callback(server, params.text_document, params.text)
51 }))
52 }
53
54 pub fn set_save_include_text(&mut self, value: bool) {
60 self.text_document.did_save.options_mut().include_text = value;
61 }
62}