summaryrefslogtreecommitdiff
path: root/support/texlab/crates/definition/src/citation.rs
blob: 1497711cf6e07550d80e2a2b4d17c344b899ad81 (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
25
26
27
28
29
30
use base_db::{
    semantics::bib,
    util::queries::{self, Object},
};

use crate::DefinitionContext;

use super::DefinitionResult;

pub(super) fn goto_definition<'db>(context: &mut DefinitionContext<'db>) -> Option<()> {
    let data = context.params.document.data.as_tex()?;

    let citation = queries::object_at_cursor(
        &data.semantics.citations,
        context.params.offset,
        queries::SearchMode::Full,
    )?;

    let name = citation.object.name_text();
    for (document, entry) in queries::objects_with_name::<bib::Entry>(&context.project, name) {
        context.results.push(DefinitionResult {
            origin_selection_range: citation.object.name_range(),
            target: document,
            target_range: entry.full_range,
            target_selection_range: entry.name.range,
        });
    }

    Some(())
}