diff options
Diffstat (limited to 'support/texlab/crates/base-db')
-rw-r--r-- | support/texlab/crates/base-db/Cargo.toml | 1 | ||||
-rw-r--r-- | support/texlab/crates/base-db/src/semantics/bib.rs | 23 | ||||
-rw-r--r-- | support/texlab/crates/base-db/src/workspace.rs | 6 |
3 files changed, 29 insertions, 1 deletions
diff --git a/support/texlab/crates/base-db/Cargo.toml b/support/texlab/crates/base-db/Cargo.toml index fa015b24cc..0ae198db7b 100644 --- a/support/texlab/crates/base-db/Cargo.toml +++ b/support/texlab/crates/base-db/Cargo.toml @@ -21,6 +21,7 @@ rustc-hash = "1.1.0" syntax = { path = "../syntax" } text-size = "1.1.1" url = "=2.3.1" +bibtex-utils = { path = "../bibtex-utils" } [lib] doctest = false diff --git a/support/texlab/crates/base-db/src/semantics/bib.rs b/support/texlab/crates/base-db/src/semantics/bib.rs index 22017d3c03..29f9477896 100644 --- a/support/texlab/crates/base-db/src/semantics/bib.rs +++ b/support/texlab/crates/base-db/src/semantics/bib.rs @@ -1,7 +1,11 @@ +use bibtex_utils::field::text::TextFieldData; +use itertools::Itertools; use rowan::ast::AstNode; -use syntax::bibtex::{self, HasName}; +use syntax::bibtex::{self, HasName, HasType, HasValue}; use text_size::TextRange; +use crate::data::{BibtexEntryType, BibtexEntryTypeCategory}; + use super::Span; #[derive(Debug, Clone, Default)] @@ -23,12 +27,27 @@ impl Semantics { fn process_entry(&mut self, entry: bibtex::Entry) { if let Some(name) = entry.name_token() { + let type_token = entry.type_token().unwrap(); + let category = BibtexEntryType::find(&type_token.text()[1..]) + .map_or(BibtexEntryTypeCategory::Misc, |ty| ty.category); + + let field_values = entry + .fields() + .filter_map(|field| Some(TextFieldData::parse(&field.value()?)?.text)); + + let keywords = [name.text().into(), type_token.text().into()] + .into_iter() + .chain(field_values) + .join(" "); + self.entries.push(Entry { name: Span { range: name.text_range(), text: name.text().into(), }, full_range: entry.syntax().text_range(), + category, + keywords, }); } } @@ -50,6 +69,8 @@ impl Semantics { pub struct Entry { pub name: Span, pub full_range: TextRange, + pub keywords: String, + pub category: BibtexEntryTypeCategory, } #[derive(Debug, Clone)] diff --git a/support/texlab/crates/base-db/src/workspace.rs b/support/texlab/crates/base-db/src/workspace.rs index 9308c2401d..35e3904d75 100644 --- a/support/texlab/crates/base-db/src/workspace.rs +++ b/support/texlab/crates/base-db/src/workspace.rs @@ -75,6 +75,12 @@ impl Workspace { Cow::Owned(text) => text, }; + if let Some(document) = self.lookup_path(path) { + if document.text == text { + return Ok(()); + } + } + self.open(uri, text, language, owner, LineCol { line: 0, col: 0 }); Ok(()) } |