summaryrefslogtreecommitdiff
path: root/support/texlab/crates/texlab/src/features/formatting.rs
blob: 3fcd66e39bc406a487f73387cc842720b5f7452e (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
29
30
31
32
mod bibtex_internal;
mod latexindent;

use base_db::{Formatter, Workspace};
use distro::Language;

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

pub fn format_source_code(
    workspace: &Workspace,
    uri: &lsp_types::Url,
    options: &lsp_types::FormattingOptions,
) -> Option<Vec<lsp_types::TextEdit>> {
    let document = workspace.lookup(uri)?;
    match document.language {
        Language::Tex => match workspace.config().formatting.tex_formatter {
            Formatter::Null => None,
            Formatter::Server => None,
            Formatter::LatexIndent => format_with_latexindent(workspace, document),
        },
        Language::Bib => match workspace.config().formatting.bib_formatter {
            Formatter::Null => None,
            Formatter::Server => format_bibtex_internal(workspace, document, options),
            Formatter::LatexIndent => format_with_latexindent(workspace, document),
        },
        Language::Aux
        | Language::Log
        | Language::Root
        | Language::Latexmkrc
        | Language::Tectonic => None,
    }
}