summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/formatting.rs
blob: c7c2dc410a51b6f37d9d2fb7d8bf154cacc1ea99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mod bibtex_internal;
mod latexindent;

use cancellation::CancellationToken;
use lsp_types::{DocumentFormattingParams, TextEdit};

use crate::{BibtexFormatter, LatexFormatter};

use self::{bibtex_internal::format_bibtex_internal, latexindent::format_with_latexindent};

use super::FeatureRequest;

pub fn format_source_code(
    request: FeatureRequest<DocumentFormattingParams>,
    cancellation_token: &CancellationToken,
) -> Option<Vec<TextEdit>> {
    let mut edits = None;
    if request.context.options.read().unwrap().bibtex_formatter == BibtexFormatter::Texlab {
        edits = edits.or_else(|| format_bibtex_internal(&request, cancellation_token));
    }

    if request.context.options.read().unwrap().latex_formatter == LatexFormatter::Texlab {
        edits = edits.or_else(|| Some(vec![]));
    }

    edits = edits.or_else(|| format_with_latexindent(&request, cancellation_token));
    edits
}