summaryrefslogtreecommitdiff
path: root/support/texlab/crates/texlab/src/features/hover/field.rs
blob: d16bea6157b1c418a50a583bfd3200ab980e9e23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use base_db::data::BibtexFieldType;
use lsp_types::MarkupKind;
use rowan::ast::AstNode;
use syntax::bibtex;

use crate::util::cursor::CursorContext;

use super::HoverResult;

pub(super) fn find_hover(context: &CursorContext) -> Option<HoverResult> {
    let name = context
        .cursor
        .as_bib()
        .filter(|token| token.kind() == bibtex::NAME)?;

    bibtex::Field::cast(name.parent()?)?;

    let docs = BibtexFieldType::find(name.text())?.documentation;
    Some(HoverResult {
        range: name.text_range(),
        value: docs.into(),
        value_kind: MarkupKind::Markdown,
    })
}