summaryrefslogtreecommitdiff
path: root/support/texlab/crates/definition/src/lib.rs
blob: e35a0fdcc18c0985f561a64b9de71775ca6e08dc (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mod citation;
mod command;
mod include;
mod label;
mod string_ref;

use base_db::{Document, FeatureParams};
use rowan::{TextRange, TextSize};
use rustc_hash::FxHashSet;

#[derive(Debug)]
pub struct DefinitionParams<'a> {
    pub feature: FeatureParams<'a>,
    pub offset: TextSize,
}

#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct DefinitionResult<'a> {
    pub origin_selection_range: TextRange,
    pub target: &'a Document,
    pub target_range: TextRange,
    pub target_selection_range: TextRange,
}

#[derive(Debug)]
struct DefinitionContext<'a, 'b> {
    params: &'b DefinitionParams<'a>,
    results: FxHashSet<DefinitionResult<'a>>,
}

pub fn goto_definition<'a>(params: &DefinitionParams<'a>) -> FxHashSet<DefinitionResult<'a>> {
    let mut context = DefinitionContext {
        params,
        results: FxHashSet::default(),
    };

    command::goto_definition(&mut context);
    include::goto_definition(&mut context);
    citation::goto_definition(&mut context);
    label::goto_definition(&mut context);
    string_ref::goto_definition(&mut context);
    context.results
}

#[cfg(test)]
mod tests;