Skip to content

Commit

Permalink
Organize BibTeX entry types into categories
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed Sep 26, 2019
1 parent 8b8e729 commit f5eb665
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 26 deletions.
14 changes: 12 additions & 2 deletions src/completion/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,22 @@ pub fn citation(

pub fn entry_type(
request: &FeatureRequest<CompletionParams>,
ty: &'static BibtexEntryTypeDoc,
ty: &BibtexEntryTypeDoc,
text_edit: TextEdit,
) -> CompletionItem {
let kind = match &ty.category {
BibtexEntryTypeCategory::Misc => CompletionItemKind::Interface,
BibtexEntryTypeCategory::String => CompletionItemKind::Text,
BibtexEntryTypeCategory::Article => CompletionItemKind::Event,
BibtexEntryTypeCategory::Book => CompletionItemKind::Struct,
BibtexEntryTypeCategory::Collection => CompletionItemKind::TypeParameter,
BibtexEntryTypeCategory::Part => CompletionItemKind::Operator,
BibtexEntryTypeCategory::Thesis => CompletionItemKind::Property,
};

CompletionItem {
label: (&ty.name).into(),
kind: Some(adjust_kind(request, CompletionItemKind::Interface)),
kind: Some(adjust_kind(request, kind)),
data: Some(CompletionItemData::EntryType.into()),
text_edit: Some(text_edit),
documentation: ty.documentation.as_ref().map(|doc| {
Expand Down
20 changes: 9 additions & 11 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,20 +551,18 @@ impl<C: LspClient + Send + Sync + 'static> jsonrpc::ActionHandler for LatexLspSe
}
}
}
Action::DetectChildren => {
loop {
let mut changed = false;
Action::DetectChildren => loop {
let mut changed = false;

let workspace = self.workspace_manager.get();
for path in workspace.unresolved_includes() {
changed |= self.workspace_manager.load(&path).is_ok();
}
let workspace = self.workspace_manager.get();
for path in workspace.unresolved_includes() {
changed |= self.workspace_manager.load(&path).is_ok();
}

if !changed {
break;
}
if !changed {
break;
}
}
},
Action::PublishDiagnostics => {
let workspace = self.workspace_manager.get();
for document in &workspace.documents {
Expand Down
9 changes: 7 additions & 2 deletions src/symbol/bibtex_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ impl FeatureProvider for BibtexEntrySymbolProvider {
.filter(|entry| !entry.is_comment())
.filter(|entry| entry.key.is_some())
{
let category = LANGUAGE_DATA
.find_entry_type(&entry.ty.text()[1..])
.map(|ty| ty.category)
.unwrap_or(BibtexEntryTypeCategory::Misc);

let key = entry.key.as_ref().unwrap();
let symbol = LatexSymbol {
name: key.text().to_owned(),
label: None,
kind: LatexSymbolKind::Entry,
kind: LatexSymbolKind::Entry(category),
deprecated: false,
full_range: entry.range(),
selection_range: key.range(),
Expand Down Expand Up @@ -80,7 +85,7 @@ mod tests {
vec![LatexSymbol {
name: "key".into(),
label: None,
kind: LatexSymbolKind::Entry,
kind: LatexSymbolKind::Entry(BibtexEntryTypeCategory::Article),
deprecated: false,
full_range: Range::new_simple(0, 0, 0, 35),
selection_range: Range::new_simple(0, 9, 0, 12),
Expand Down
13 changes: 10 additions & 3 deletions src/symbol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use self::bibtex_entry::BibtexEntrySymbolProvider;
use self::bibtex_string::BibtexStringSymbolProvider;
use self::latex_section::LatexSectionSymbolProvider;
use crate::capabilities::ClientCapabilitiesExt;
use crate::syntax::*;
use crate::workspace::*;
use futures_boxed::boxed;
use lsp_types::*;
Expand All @@ -26,7 +27,7 @@ pub enum LatexSymbolKind {
EnumerationItem,
Theorem,
Equation,
Entry,
Entry(BibtexEntryTypeCategory),
Field,
String,
}
Expand All @@ -40,7 +41,13 @@ impl Into<SymbolKind> for LatexSymbolKind {
Self::EnumerationItem => SymbolKind::EnumMember,
Self::Theorem => SymbolKind::Class,
Self::Equation => SymbolKind::Constant,
Self::Entry => SymbolKind::Interface,
Self::Entry(BibtexEntryTypeCategory::Misc) => SymbolKind::Interface,
Self::Entry(BibtexEntryTypeCategory::String) => SymbolKind::String,
Self::Entry(BibtexEntryTypeCategory::Article) => SymbolKind::Event,
Self::Entry(BibtexEntryTypeCategory::Book) => SymbolKind::Struct,
Self::Entry(BibtexEntryTypeCategory::Collection) => SymbolKind::TypeParameter,
Self::Entry(BibtexEntryTypeCategory::Part) => SymbolKind::Operator,
Self::Entry(BibtexEntryTypeCategory::Thesis) => SymbolKind::Property,
Self::Field => SymbolKind::Field,
Self::String => SymbolKind::String,
}
Expand Down Expand Up @@ -70,7 +77,7 @@ impl LatexSymbol {
LatexSymbolKind::EnumerationItem => "latex enumeration item",
LatexSymbolKind::Theorem => "latex math",
LatexSymbolKind::Equation => "latex math equation",
LatexSymbolKind::Entry => "bibtex entry",
LatexSymbolKind::Entry(_) => "bibtex entry",
LatexSymbolKind::Field => "bibtex field",
LatexSymbolKind::String => "bibtex string",
};
Expand Down
Loading

0 comments on commit f5eb665

Please sign in to comment.