sync_lsp/text_document/
did_open.rs1use crate::{Server, TypeProvider};
7use crate::connection::{Callback, Endpoint};
8use serde::Deserialize;
9use super::DocumentUri;
10
11#[derive(Default, Clone)]
12pub(crate) struct DidOpenOptions;
13
14#[derive(Deserialize, Debug)]
16#[serde(rename_all = "camelCase")]
17pub struct TextDocumentItem {
18 pub uri: DocumentUri,
20 pub language_id: String,
22 pub version: i32,
24 pub text: String,
26}
27
28#[derive(Deserialize)]
29#[serde(rename_all = "camelCase")]
30struct DidOpenParams {
31 text_document: TextDocumentItem,
32}
33
34impl DidOpenOptions {
35
36 pub(crate) const METHOD: &'static str = "textDocument/didOpen";
37
38 pub(super) fn endpoint<T: TypeProvider>() -> Endpoint<T, DidOpenOptions> {
39 Endpoint::new(Callback::notification(|_, _: DidOpenParams| ()))
40 }
41}
42
43impl<T: TypeProvider> Server<T> {
44
45 pub fn on_open(&mut self, callback: fn(&mut Server<T>, TextDocumentItem)) {
54 self.text_document.did_open.set_callback(Callback::notification(move |server, params: DidOpenParams| {
55 callback(server, params.text_document)
56 }))
57 }
58}