sync_lsp/text_document/
document_link.rs1use crate::TypeProvider;
10use crate::{Server, connection::Endpoint};
11use crate::connection::Callback;
12use serde::{Deserialize, Serialize};
13use super::{TextDocumentIdentifer, Range, DocumentUri};
14
15#[derive(Serialize, Clone)]
16#[serde(rename_all = "camelCase")]
17pub(crate) struct DocumentLinkOptions {
18 resolve_provider: bool
19}
20
21#[derive(Serialize, Clone, Default)]
22#[serde(rename_all = "camelCase")]
23pub(crate) struct DocumentLinkResolveOptions;
24
25#[derive(Deserialize)]
26#[serde(rename_all = "camelCase")]
27struct DocumentLinkParams {
28 text_document: TextDocumentIdentifer,
29}
30
31#[derive(Serialize, Deserialize, Debug)]
33pub struct DocumentLink {
34 pub range: Range,
36 #[serde(skip_serializing_if = "Option::is_none")]
38 pub target: Option<DocumentUri>
39}
40
41impl DocumentLinkOptions {
42 pub(crate) const METHOD: &'static str = "textDocument/documentLink";
43
44 pub(super) fn endpoint<T: TypeProvider>() -> Endpoint<T, DocumentLinkOptions> {
45 Endpoint::new(Callback::request(|_, _: DocumentLinkParams| Vec::<DocumentLink>::new()))
46 }
47}
48
49impl DocumentLinkResolveOptions {
50 pub(crate) const METHOD: &'static str = "documentLink/resolve";
51
52 pub(super) fn endpoint<T: TypeProvider>() -> Endpoint<T, DocumentLinkResolveOptions> {
53 Endpoint::new(Callback::request(|_, lens: DocumentLink| lens))
54 }
55}
56
57impl<T: TypeProvider> Server<T> {
58
59 pub fn on_document_link(&mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer) -> Vec<DocumentLink>) {
68 self.text_document.document_link.set_callback(Callback::request(move |server, params: DocumentLinkParams| {
69 callback(server, params.text_document)
70 }));
71 }
72
73 pub fn on_document_link_resolve(&mut self, callback: fn(&mut Server<T>, DocumentLink) -> DocumentLink) {
82 self.text_document.resolve_document_link.set_callback(Callback::request(move |server, params| {
83 callback(server, params)
84 }));
85 }
86}
87
88impl Default for DocumentLinkOptions {
89 fn default() -> Self {
90 Self {
91 resolve_provider: false
92 }
93 }
94}