sync_lsp/text_document/
did_close.rs

1//! implementation of the `textDocument/didClose` notification
2//! 
3//! # Usage
4//! Whenever a document is closed, [`Server::on_close`] is invoked.
5//! The client should only send this if it claimed ownership of the document
6//! via [`Server::on_open`] before.
7
8use crate::{Server, TypeProvider};
9use crate::connection::{Callback, Endpoint};
10use serde::Deserialize;
11use super::TextDocumentIdentifer;
12
13#[derive(Default, Clone)]
14pub(crate) struct DidCloseOptions;
15
16#[derive(Deserialize)]
17#[serde(rename_all = "camelCase")]
18struct DidCloseTextDocumentParams {
19    text_document: TextDocumentIdentifer,
20}
21
22
23impl DidCloseOptions {
24
25    pub(crate) const METHOD: &'static str = "textDocument/didClose";
26
27    pub(crate) fn endpoint<T: TypeProvider>() -> Endpoint<T, DidCloseOptions> {
28        Endpoint::new(Callback::notification(|_, _: DidCloseTextDocumentParams| {
29
30        }))
31    }
32}
33
34impl<T: TypeProvider> Server<T> {
35
36    /// Sets the callback that will be called if a [file is closed](self).
37    /// 
38    /// # Argument
39    /// * `callback` - A callback which is called with the following parameters as soon as a file is closed:
40    ///     * The server instance receiving the response.
41    ///     * The [`TextDocumentIdentifer`] of the document that has been closed.
42    
43    pub fn on_close(&mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer)) {
44        self.text_document.did_close.set_callback(Callback::notification(move |server, params: DidCloseTextDocumentParams| {
45            callback(server, params.text_document)
46        }))
47    }
48}