sync_lsp/text_document/
range_formatting.rs1use crate::TypeProvider;
8use crate::{Server, connection::Endpoint};
9use crate::connection::Callback;
10use super::formatting::FormattingOptions;
11use super::{TextDocumentIdentifer, TextEdit, Range};
12use serde::Deserialize;
13
14#[derive(Default, Clone)]
15pub(crate) struct RangeFormattingOptions;
16
17#[derive(Deserialize)]
18#[serde(rename_all = "camelCase")]
19struct DocumentRangeFormattingParams {
20 text_document: TextDocumentIdentifer,
21 range: Range,
22 options: FormattingOptions
23}
24
25impl RangeFormattingOptions {
26
27 pub(crate) const METHOD: &'static str = "textDocument/rangeFormatting";
28
29 pub(super) fn endpoint<T: TypeProvider>() -> Endpoint<T, RangeFormattingOptions> {
30 Endpoint::new(Callback::request(|_, _: DocumentRangeFormattingParams| Vec::<TextEdit>::new()))
31 }
32}
33
34impl<T: TypeProvider> Server<T> {
35
36
37 pub fn on_range_formatting(&mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Range, FormattingOptions) -> Vec<TextEdit>) {
48 self.text_document.range_formatting.set_callback(Callback::request(move |server, params: DocumentRangeFormattingParams | {
49 callback(server, params.text_document, params.range, params.options)
50 }))
51 }
52}