mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-08-04 10:49:55 +00:00
Run "cargo fmt"
This commit is contained in:
parent
a06002f28b
commit
1d0844b29a
5 changed files with 46 additions and 21 deletions
|
@ -1,8 +1,8 @@
|
|||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct BibtexEntryType<'a> {
|
||||
pub name: &'a str,
|
||||
pub category: BibtexEntryTypeCategory,
|
||||
pub documentation: Option<&'a str>,
|
||||
pub name: &'a str,
|
||||
pub category: BibtexEntryTypeCategory,
|
||||
pub documentation: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||
|
@ -18,23 +18,28 @@ pub enum BibtexEntryTypeCategory {
|
|||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct BibtexFieldType<'a> {
|
||||
pub name: &'a str,
|
||||
pub documentation: &'a str,
|
||||
pub name: &'a str,
|
||||
pub documentation: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> BibtexEntryType<'a> {
|
||||
pub fn find(name: &str) -> Option<Self> {
|
||||
BIBTEX_ENTRY_TYPES.iter().find(|ty| ty.name.eq_ignore_ascii_case(name)).copied()
|
||||
BIBTEX_ENTRY_TYPES
|
||||
.iter()
|
||||
.find(|ty| ty.name.eq_ignore_ascii_case(name))
|
||||
.copied()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> BibtexFieldType<'a> {
|
||||
pub fn find(name: &str) -> Option<Self> {
|
||||
BIBTEX_FIELD_TYPES.iter().find(|ty| ty.name.eq_ignore_ascii_case(name)).copied()
|
||||
BIBTEX_FIELD_TYPES
|
||||
.iter()
|
||||
.find(|ty| ty.name.eq_ignore_ascii_case(name))
|
||||
.copied()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub static BIBTEX_ENTRY_TYPES: &[BibtexEntryType<'static>] = &[
|
||||
BibtexEntryType {
|
||||
name: "@preamble",
|
||||
|
@ -887,5 +892,5 @@ pub static BIBTEX_FIELD_TYPES: &[BibtexFieldType<'static>] = &[
|
|||
BibtexFieldType {
|
||||
name: "school",
|
||||
documentation: "An alias for `institution`, provided for BibTeX compatibility. The `institution` field is used by traditional BibTeX for technical reports whereas the `school` field holds the institution associated with theses. The `biblatex` package employs the generic field name `institution` in both cases.",
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use bibtex_utils::field::text::TextFieldData;
|
||||
use itertools::Itertools;
|
||||
use rowan::{ast::AstNode, TextRange};
|
||||
use syntax::bibtex::{self, HasName, HasType, HasValue};
|
||||
use rustc_hash::FxHashMap;
|
||||
use syntax::bibtex::{self, HasName, HasType, HasValue};
|
||||
|
||||
use crate::data::{BibtexEntryType, BibtexEntryTypeCategory};
|
||||
|
||||
|
@ -33,9 +33,9 @@ impl Semantics {
|
|||
let category = BibtexEntryType::find(type_token.text())
|
||||
.map_or(BibtexEntryTypeCategory::Misc, |ty| ty.category);
|
||||
|
||||
let field_values = entry
|
||||
.fields()
|
||||
.filter_map(|field| Some(TextFieldData::parse(&field.value()?, &self.expanded_defs)?.text));
|
||||
let field_values = entry.fields().filter_map(|field| {
|
||||
Some(TextFieldData::parse(&field.value()?, &self.expanded_defs)?.text)
|
||||
});
|
||||
|
||||
let keywords = [name.text().into(), type_token.text().into()]
|
||||
.into_iter()
|
||||
|
|
|
@ -6,4 +6,4 @@ pub mod number;
|
|||
pub mod text;
|
||||
|
||||
/// A cache used to accelerate related field parses.
|
||||
pub type FieldParseCache = FxHashMap<String, String>;
|
||||
pub type FieldParseCache = FxHashMap<String, String>;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use rowan::{ast::AstNode, NodeOrToken};
|
||||
|
||||
use syntax::bibtex::{
|
||||
Accent, Command, CurlyGroup, HasAccentName, HasCommandName, HasName, HasWord, Join,
|
||||
Literal, QuoteGroup, SyntaxKind::*, SyntaxToken, Value,
|
||||
Accent, Command, CurlyGroup, HasAccentName, HasCommandName, HasName, HasWord, Join, Literal,
|
||||
QuoteGroup, SyntaxKind::*, SyntaxToken, Value,
|
||||
};
|
||||
|
||||
use super::FieldParseCache;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use base_db::semantics::bib::Semantics;
|
||||
use bibtex_utils::field::{
|
||||
author::{AuthorField, AuthorFieldData},
|
||||
date::{DateField, DateFieldData},
|
||||
|
@ -5,7 +6,6 @@ use bibtex_utils::field::{
|
|||
text::{TextField, TextFieldData},
|
||||
FieldParseCache,
|
||||
};
|
||||
use base_db::semantics::bib::Semantics;
|
||||
use rustc_hash::FxHashMap;
|
||||
use syntax::bibtex::{Entry, Field, HasName, HasType, HasValue, Value};
|
||||
|
||||
|
@ -133,28 +133,48 @@ impl EntryData {
|
|||
.or_else(|| self.parse_text_field(name, &value, expanded_defs))
|
||||
}
|
||||
|
||||
fn parse_author_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
|
||||
fn parse_author_field(
|
||||
&mut self,
|
||||
name: &str,
|
||||
value: &Value,
|
||||
expanded_defs: &FieldParseCache,
|
||||
) -> Option<()> {
|
||||
let name = AuthorField::parse(name)?;
|
||||
let data = AuthorFieldData::parse(value, expanded_defs)?;
|
||||
self.author.insert(name, data);
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn parse_date_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
|
||||
fn parse_date_field(
|
||||
&mut self,
|
||||
name: &str,
|
||||
value: &Value,
|
||||
expanded_defs: &FieldParseCache,
|
||||
) -> Option<()> {
|
||||
let name = DateField::parse(name)?;
|
||||
let data = DateFieldData::parse(value, expanded_defs)?;
|
||||
self.date.insert(name, data);
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn parse_number_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
|
||||
fn parse_number_field(
|
||||
&mut self,
|
||||
name: &str,
|
||||
value: &Value,
|
||||
expanded_defs: &FieldParseCache,
|
||||
) -> Option<()> {
|
||||
let name = NumberField::parse(name)?;
|
||||
let data = NumberFieldData::parse(value, expanded_defs)?;
|
||||
self.number.insert(name, data);
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn parse_text_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
|
||||
fn parse_text_field(
|
||||
&mut self,
|
||||
name: &str,
|
||||
value: &Value,
|
||||
expanded_defs: &FieldParseCache,
|
||||
) -> Option<()> {
|
||||
let name = TextField::parse(name).unwrap_or(TextField::Unknown);
|
||||
let data = TextFieldData::parse(value, expanded_defs)?;
|
||||
self.text.insert(name, data);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue