summaryrefslogtreecommitdiff
path: root/support/texlab/crates/references/src/lib.rs
blob: c223ad8eba9d79fa765b2602dec06cf557af0caa (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
mod entry;
mod label;
mod string_def;

use base_db::{DocumentLocation, FeatureParams};
use rowan::TextSize;

#[derive(Debug)]
pub struct Reference<'a> {
    pub location: DocumentLocation<'a>,
    pub kind: ReferenceKind,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub enum ReferenceKind {
    Definition,
    Reference,
}

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

#[derive(Debug)]
struct ReferenceContext<'a> {
    params: ReferenceParams<'a>,
    results: Vec<Reference<'a>>,
}

pub fn find_all(params: ReferenceParams) -> Vec<Reference<'_>> {
    let mut context = ReferenceContext {
        params,
        results: Vec::new(),
    };

    entry::find_all(&mut context);
    label::find_all(&mut context);
    string_def::find_all(&mut context);
    context.results
}

#[cfg(test)]
mod tests;