summaryrefslogtreecommitdiff
path: root/support/texlab/crates/definition/src/lib.rs
blob: 2c1614f04e8066e2bacf9bd7fc5cae290a2bf40f (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
47
48
49
50
mod citation;
mod command;
mod include;
mod label;
mod string_ref;

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

#[derive(Debug)]
pub struct DefinitionParams<'db> {
    pub workspace: &'db Workspace,
    pub document: &'db Document,
    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<'db> {
    params: DefinitionParams<'db>,
    project: Project<'db>,
    results: FxHashSet<DefinitionResult<'db>>,
}

pub fn goto_definition(params: DefinitionParams) -> FxHashSet<DefinitionResult> {
    let project = params.workspace.project(params.document);
    let mut context = DefinitionContext {
        params,
        project,
        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;