summaryrefslogtreecommitdiff
path: root/support/texlab/src/hover/bibtex_entry_type.rs
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
committerNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
commitb8d4bb76703bcb15578e2b23c5d256532180b894 (patch)
treebedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/src/hover/bibtex_entry_type.rs
parent02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff)
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/src/hover/bibtex_entry_type.rs')
-rw-r--r--support/texlab/src/hover/bibtex_entry_type.rs111
1 files changed, 111 insertions, 0 deletions
diff --git a/support/texlab/src/hover/bibtex_entry_type.rs b/support/texlab/src/hover/bibtex_entry_type.rs
new file mode 100644
index 0000000000..adf833b689
--- /dev/null
+++ b/support/texlab/src/hover/bibtex_entry_type.rs
@@ -0,0 +1,111 @@
+use crate::range::RangeExt;
+use crate::syntax::*;
+use crate::workspace::*;
+use futures_boxed::boxed;
+use lsp_types::*;
+
+#[derive(Debug, PartialEq, Eq, Clone)]
+pub struct BibtexEntryTypeHoverProvider;
+
+impl FeatureProvider for BibtexEntryTypeHoverProvider {
+ type Params = TextDocumentPositionParams;
+ type Output = Option<Hover>;
+
+ #[boxed]
+ async fn execute<'a>(
+ &'a self,
+ request: &'a FeatureRequest<TextDocumentPositionParams>,
+ ) -> Option<Hover> {
+ if let SyntaxTree::Bibtex(tree) = &request.document().tree {
+ for entry in tree.entries() {
+ if entry.ty.range().contains(request.params.position) {
+ let ty = &entry.ty.text()[1..];
+ if let Some(documentation) = LANGUAGE_DATA.entry_type_documentation(ty) {
+ return Some(Hover {
+ contents: HoverContents::Markup(MarkupContent {
+ kind: MarkupKind::Markdown,
+ value: documentation.into(),
+ }),
+ range: None,
+ });
+ }
+ }
+ }
+ }
+ None
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use lsp_types::Position;
+
+ #[test]
+ fn test_known_entry_type() {
+ let hover = test_feature(
+ BibtexEntryTypeHoverProvider,
+ FeatureSpec {
+ files: vec![FeatureSpec::file("foo.bib", "@article{foo,}")],
+ main_file: "foo.bib",
+ position: Position::new(0, 3),
+ ..FeatureSpec::default()
+ },
+ );
+ assert_eq!(
+ hover,
+ Some(Hover {
+ contents: HoverContents::Markup(MarkupContent {
+ kind: MarkupKind::Markdown,
+ value: LANGUAGE_DATA
+ .entry_type_documentation("article")
+ .unwrap()
+ .into(),
+ }),
+ range: None,
+ })
+ );
+ }
+
+ #[test]
+ fn test_unknown_entry_type() {
+ let hover = test_feature(
+ BibtexEntryTypeHoverProvider,
+ FeatureSpec {
+ files: vec![FeatureSpec::file("foo.bib", "@foo{bar,}")],
+ main_file: "foo.bib",
+ position: Position::new(0, 3),
+ ..FeatureSpec::default()
+ },
+ );
+ assert_eq!(hover, None);
+ }
+
+ #[test]
+ fn test_entry_key() {
+ let hover = test_feature(
+ BibtexEntryTypeHoverProvider,
+ FeatureSpec {
+ files: vec![FeatureSpec::file("foo.bib", "@article{foo,}")],
+ main_file: "foo.bib",
+ position: Position::new(0, 11),
+ ..FeatureSpec::default()
+ },
+ );
+ assert_eq!(hover, None);
+ }
+
+ #[test]
+ fn test_latex() {
+ let hover = test_feature(
+ BibtexEntryTypeHoverProvider,
+ FeatureSpec {
+ files: vec![FeatureSpec::file("foo.tex", "\\foo")],
+ main_file: "foo.tex",
+ position: Position::new(0, 3),
+ ..FeatureSpec::default()
+ },
+ );
+ assert_eq!(hover, None);
+ }
+}