diff options
Diffstat (limited to 'support/texlab/src/features/formatting.rs')
-rw-r--r-- | support/texlab/src/features/formatting.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/support/texlab/src/features/formatting.rs b/support/texlab/src/features/formatting.rs index 1107e5fd38..66375bd576 100644 --- a/support/texlab/src/features/formatting.rs +++ b/support/texlab/src/features/formatting.rs @@ -1,26 +1,31 @@ mod bibtex_internal; mod latexindent; -use lsp_types::{DocumentFormattingParams, TextEdit}; +use lsp_types::{FormattingOptions, TextEdit, Url}; -use crate::{BibtexFormatter, LatexFormatter}; +use crate::{ + db::{Language, Workspace}, + BibtexFormatter, Db, LatexFormatter, +}; use self::{bibtex_internal::format_bibtex_internal, latexindent::format_with_latexindent}; -use super::FeatureRequest; - pub fn format_source_code( - request: FeatureRequest<DocumentFormattingParams>, + db: &dyn Db, + uri: &Url, + options: &FormattingOptions, ) -> Option<Vec<TextEdit>> { - let mut edits = None; - if request.workspace.environment.options.bibtex_formatter == BibtexFormatter::Texlab { - edits = edits.or_else(|| format_bibtex_internal(&request)); - } - - if request.workspace.environment.options.latex_formatter == LatexFormatter::Texlab { - edits = edits.or_else(|| Some(vec![])); + let workspace = Workspace::get(db); + let document = workspace.lookup_uri(db, uri)?; + match document.language(db) { + Language::Tex => match workspace.options(db).latex_formatter { + LatexFormatter::Texlab => None, + LatexFormatter::Latexindent => format_with_latexindent(db, document), + }, + Language::Bib => match workspace.options(db).bibtex_formatter { + BibtexFormatter::Texlab => format_bibtex_internal(db, document, options), + BibtexFormatter::Latexindent => format_with_latexindent(db, document), + }, + Language::Log => None, } - - edits = edits.or_else(|| format_with_latexindent(&request)); - edits } |