Skip to content

Commit

Permalink
Add LaTeX formatting via latexindent.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed Apr 11, 2020
1 parent c7a5d3a commit d030edf
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 205 deletions.
26 changes: 12 additions & 14 deletions src/completion/latex/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,19 @@ impl FeatureProvider for LatexArgumentCompletionProvider {
name: &name,
index: i,
}),
|ctx| {
async move {
let mut items = Vec::new();
for arg in &param.0 {
let text_edit = TextEdit::new(ctx.range, (&arg.name).into());
let item = factory::argument(
req,
&arg.name,
text_edit,
arg.image.as_ref().map(AsRef::as_ref),
);
items.push(item);
}
items
|ctx| async move {
let mut items = Vec::new();
for arg in &param.0 {
let text_edit = TextEdit::new(ctx.range, (&arg.name).into());
let item = factory::argument(
req,
&arg.name,
text_edit,
arg.image.as_ref().map(AsRef::as_ref),
);
items.push(item);
}
items
},
)
.await;
Expand Down
20 changes: 9 additions & 11 deletions src/completion/latex/begin_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ impl FeatureProvider for LatexBeginCommandCompletionProvider {

#[boxed]
async fn execute<'a>(&'a self, req: &'a FeatureRequest<Self::Params>) -> Self::Output {
combinators::command(req, |_| {
async move {
let snippet = factory::command_snippet(
req,
"begin",
None,
"begin{$1}\n\t$0\n\\end{$1}",
&LatexComponentId::kernel(),
);
vec![snippet]
}
combinators::command(req, |_| async move {
let snippet = factory::command_snippet(
req,
"begin",
None,
"begin{$1}\n\t$0\n\\end{$1}",
&LatexComponentId::kernel(),
);
vec![snippet]
})
.await
}
Expand Down
18 changes: 8 additions & 10 deletions src/completion/latex/citation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ impl FeatureProvider for LatexCitationCompletionProvider {
index: cmd.index,
});

combinators::argument(req, parameters, |ctx| {
async move {
let mut items = Vec::new();
for doc in req.related() {
if let DocumentContent::Bibtex(tree) = &doc.content {
for entry_node in tree.children(tree.root) {
if let Some(item) = Self::make_item(req, ctx, doc, tree, entry_node) {
items.push(item);
}
combinators::argument(req, parameters, |ctx| async move {
let mut items = Vec::new();
for doc in req.related() {
if let DocumentContent::Bibtex(tree) = &doc.content {
for entry_node in tree.children(tree.root) {
if let Some(item) = Self::make_item(req, ctx, doc, tree, entry_node) {
items.push(item);
}
}
}
items
}
items
})
.await
}
Expand Down
16 changes: 7 additions & 9 deletions src/completion/latex/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ impl FeatureProvider for LatexColorCompletionProvider {
index: cmd.index,
});

combinators::argument(req, parameters, |ctx| {
async move {
let mut items = Vec::new();
for name in &LANGUAGE_DATA.colors {
let text_edit = TextEdit::new(ctx.range, name.into());
let item = factory::color(req, name, text_edit);
items.push(item);
}
items
combinators::argument(req, parameters, |ctx| async move {
let mut items = Vec::new();
for name in &LANGUAGE_DATA.colors {
let text_edit = TextEdit::new(ctx.range, name.into());
let item = factory::color(req, name, text_edit);
items.push(item);
}
items
})
.await
}
Expand Down
16 changes: 7 additions & 9 deletions src/completion/latex/color_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ impl FeatureProvider for LatexColorModelCompletionProvider {
index: cmd.index,
});

combinators::argument(req, parameters, |ctx| {
async move {
let mut items = Vec::new();
for name in MODEL_NAMES {
let text_edit = TextEdit::new(ctx.range, (*name).into());
let item = factory::color_model(req, name, text_edit);
items.push(item);
}
items
combinators::argument(req, parameters, |ctx| async move {
let mut items = Vec::new();
for name in MODEL_NAMES {
let text_edit = TextEdit::new(ctx.range, (*name).into());
let item = factory::color_model(req, name, text_edit);
items.push(item);
}
items
})
.await
}
Expand Down
64 changes: 30 additions & 34 deletions src/completion/latex/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@ impl FeatureProvider for LatexComponentCommandCompletionProvider {

#[boxed]
async fn execute<'a>(&'a self, req: &'a FeatureRequest<Self::Params>) -> Self::Output {
combinators::command(req, |cmd_node| {
async move {
let table = req.current().content.as_latex().unwrap();
let cmd = table.tree.as_command(cmd_node).unwrap();
let range = cmd.short_name_range();
let mut items = Vec::new();
for comp in req.view.components() {
let file_names = comp.file_names.iter().map(AsRef::as_ref).collect();
let id = LatexComponentId::Component(file_names);
for cmd in &comp.commands {
let text_edit = TextEdit::new(range, (&cmd.name).into());
let item = factory::command(
req,
(&cmd.name).into(),
cmd.image.as_ref().map(AsRef::as_ref),
cmd.glyph.as_ref().map(AsRef::as_ref),
text_edit,
&id,
);
items.push(item);
}
combinators::command(req, |cmd_node| async move {
let table = req.current().content.as_latex().unwrap();
let cmd = table.tree.as_command(cmd_node).unwrap();
let range = cmd.short_name_range();
let mut items = Vec::new();
for comp in req.view.components() {
let file_names = comp.file_names.iter().map(AsRef::as_ref).collect();
let id = LatexComponentId::Component(file_names);
for cmd in &comp.commands {
let text_edit = TextEdit::new(range, (&cmd.name).into());
let item = factory::command(
req,
(&cmd.name).into(),
cmd.image.as_ref().map(AsRef::as_ref),
cmd.glyph.as_ref().map(AsRef::as_ref),
text_edit,
&id,
);
items.push(item);
}
items
}
items
})
.await
}
Expand All @@ -52,20 +50,18 @@ impl FeatureProvider for LatexComponentEnvironmentCompletionProvider {

#[boxed]
async fn execute<'a>(&'a self, req: &'a FeatureRequest<Self::Params>) -> Self::Output {
combinators::environment(req, |ctx| {
async move {
let mut items = Vec::new();
for comp in req.view.components() {
let file_names = comp.file_names.iter().map(AsRef::as_ref).collect();
let id = LatexComponentId::Component(file_names);
for env in &comp.environments {
let text_edit = TextEdit::new(ctx.range, env.into());
let item = factory::environment(req, env.into(), text_edit, &id);
items.push(item);
}
combinators::environment(req, |ctx| async move {
let mut items = Vec::new();
for comp in req.view.components() {
let file_names = comp.file_names.iter().map(AsRef::as_ref).collect();
let id = LatexComponentId::Component(file_names);
for env in &comp.environments {
let text_edit = TextEdit::new(ctx.range, env.into());
let item = factory::environment(req, env.into(), text_edit, &id);
items.push(item);
}
items
}
items
})
.await
}
Expand Down
40 changes: 19 additions & 21 deletions src/completion/latex/glossary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,31 @@ impl FeatureProvider for LatexGlossaryCompletionProvider {
index: cmd.index,
});

combinators::argument(req, parameters, |ctx| {
async move {
let cmd_kind = LANGUAGE_DATA
.glossary_entry_reference_commands
.iter()
.find(|cmd| cmd.name == ctx.parameter.name)
.unwrap()
.kind;
combinators::argument(req, parameters, |ctx| async move {
let cmd_kind = LANGUAGE_DATA
.glossary_entry_reference_commands
.iter()
.find(|cmd| cmd.name == ctx.parameter.name)
.unwrap()
.kind;

let mut items = Vec::new();
for doc in req.related() {
if let DocumentContent::Latex(table) = &doc.content {
for entry in &table.glossary_entries {
match (cmd_kind, entry.kind) {
(Acronym, Acronym) | (General, General) | (General, Acronym) => {
let label = entry.label(&table.tree).text().to_owned();
let text_edit = TextEdit::new(ctx.range, label.clone());
let item = factory::glossary_entry(req, label, text_edit);
items.push(item);
}
(Acronym, General) => {}
let mut items = Vec::new();
for doc in req.related() {
if let DocumentContent::Latex(table) = &doc.content {
for entry in &table.glossary_entries {
match (cmd_kind, entry.kind) {
(Acronym, Acronym) | (General, General) | (General, Acronym) => {
let label = entry.label(&table.tree).text().to_owned();
let text_edit = TextEdit::new(ctx.range, label.clone());
let item = factory::glossary_entry(req, label, text_edit);
items.push(item);
}
(Acronym, General) => {}
}
}
}
items
}
items
})
.await
}
Expand Down
30 changes: 14 additions & 16 deletions src/completion/latex/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,20 @@ where
index: cmd.index,
});

combinators::argument(req, parameters, |ctx| {
async move {
let resolver = req.distro.0.resolver().await;
COMPONENT_DATABASE
.components
.iter()
.flat_map(|comp| comp.file_names.iter())
.chain(resolver.files_by_name.keys())
.filter(|file_name| file_name.ends_with(extension))
.map(|file_name| {
let stem = &file_name[0..file_name.len() - 4];
let text_edit = TextEdit::new(ctx.range, stem.to_owned());
factory(req, stem.into(), text_edit)
})
.collect()
}
combinators::argument(req, parameters, |ctx| async move {
let resolver = req.distro.0.resolver().await;
COMPONENT_DATABASE
.components
.iter()
.flat_map(|comp| comp.file_names.iter())
.chain(resolver.files_by_name.keys())
.filter(|file_name| file_name.ends_with(extension))
.map(|file_name| {
let stem = &file_name[0..file_name.len() - 4];
let text_edit = TextEdit::new(ctx.range, stem.to_owned());
factory(req, stem.into(), text_edit)
})
.collect()
})
.await
}
Expand Down
18 changes: 8 additions & 10 deletions src/completion/latex/include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ impl FeatureProvider for LatexIncludeCompletionProvider {
index: cmd.index,
});

combinators::argument_word(req, parameters, |cmd_node, index| {
async move {
log::info!("Include!");
if !req.current().is_file() {
return Vec::new();
}

Self::make_items(req, cmd_node, index)
.await
.unwrap_or_default()
combinators::argument_word(req, parameters, |cmd_node, index| async move {
log::info!("Include!");
if !req.current().is_file() {
return Vec::new();
}

Self::make_items(req, cmd_node, index)
.await
.unwrap_or_default()
})
.await
}
Expand Down
Loading

0 comments on commit d030edf

Please sign in to comment.