summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/formatting
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-03-13 03:04:43 +0000
committerNorbert Preining <norbert@preining.info>2023-03-13 03:04:43 +0000
commite3c18c7072eebabaa706008b7fa42c73ec2ff83e (patch)
treebdd26a908e2baa0a97a38169346e53b9e6e51944 /support/texlab/src/features/formatting
parentb3d8df92a44aa1df24a0869d728b45b0baeaa54c (diff)
CTAN sync 202303130304
Diffstat (limited to 'support/texlab/src/features/formatting')
-rw-r--r--support/texlab/src/features/formatting/bibtex_internal.rs15
-rw-r--r--support/texlab/src/features/formatting/latexindent.rs18
2 files changed, 12 insertions, 21 deletions
diff --git a/support/texlab/src/features/formatting/bibtex_internal.rs b/support/texlab/src/features/formatting/bibtex_internal.rs
index 8447778d90..5026c512f2 100644
--- a/support/texlab/src/features/formatting/bibtex_internal.rs
+++ b/support/texlab/src/features/formatting/bibtex_internal.rs
@@ -2,7 +2,7 @@ use lsp_types::{FormattingOptions, TextEdit};
use rowan::{ast::AstNode, NodeOrToken};
use crate::{
- db::{Document, Workspace},
+ db::Document,
syntax::bibtex::{self, HasName, HasType, HasValue},
util::{line_index::LineIndex, line_index_ext::LineIndexExt},
Db,
@@ -23,18 +23,9 @@ pub fn format_bibtex_internal(
indent.push('\t');
}
- let line_length = Workspace::get(db)
- .options(db)
- .formatter_line_length
- .map_or(80, |value| {
- if value <= 0 {
- usize::MAX
- } else {
- value as usize
- }
- });
+ let line_length = db.config().formatting.line_length;
- let line_index = document.contents(db).line_index(db);
+ let line_index = document.line_index(db);
let data = document.parse(db).as_bib()?;
let mut edits = Vec::new();
diff --git a/support/texlab/src/features/formatting/latexindent.rs b/support/texlab/src/features/formatting/latexindent.rs
index 3dab10c923..087b8f0941 100644
--- a/support/texlab/src/features/formatting/latexindent.rs
+++ b/support/texlab/src/features/formatting/latexindent.rs
@@ -10,12 +10,12 @@ use tempfile::tempdir;
use crate::{
db::{Document, Language, Workspace},
util::line_index_ext::LineIndexExt,
- Db, LatexindentOptions,
+ Db, LatexIndentConfig,
};
pub fn format_with_latexindent(db: &dyn Db, document: Document) -> Option<Vec<TextEdit>> {
let workspace = Workspace::get(db);
- let options = workspace.options(db);
+ let config = db.config();
let target_dir = tempdir().ok()?;
let source_dir = workspace
.working_dir(db, document.directory(db))
@@ -29,9 +29,9 @@ pub fn format_with_latexindent(db: &dyn Db, document: Document) -> Option<Vec<Te
} else {
"file.tex"
});
- std::fs::write(&target_file, document.contents(db).text(db)).ok()?;
+ std::fs::write(&target_file, document.text(db)).ok()?;
- let args = build_arguments(&options.latexindent, &target_file);
+ let args = build_arguments(&config.formatting.latex_indent, &target_file);
log::debug!(
"Running latexindent in folder \"{}\" with args: {:?}",
@@ -48,12 +48,12 @@ pub fn format_with_latexindent(db: &dyn Db, document: Document) -> Option<Vec<Te
.output()
.ok()?;
- let old_text = document.contents(db).text(db);
+ let old_text = document.text(db);
let new_text = String::from_utf8_lossy(&output.stdout).into_owned();
if new_text.is_empty() {
None
} else {
- let line_index = document.contents(db).line_index(db);
+ let line_index = document.line_index(db);
Some(vec![TextEdit {
range: line_index.line_col_lsp_range(TextRange::new(0.into(), old_text.text_len())),
new_text,
@@ -61,15 +61,15 @@ pub fn format_with_latexindent(db: &dyn Db, document: Document) -> Option<Vec<Te
}
}
-fn build_arguments(options: &LatexindentOptions, target_file: &Path) -> Vec<String> {
+fn build_arguments(config: &LatexIndentConfig, target_file: &Path) -> Vec<String> {
let mut args = Vec::new();
- args.push(match &options.local {
+ args.push(match &config.local {
Some(yaml_file) => format!("--local={yaml_file}"),
None => "--local".to_string(),
});
- if options.modify_line_breaks {
+ if config.modify_line_breaks {
args.push("--modifylinebreaks".to_string());
}