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

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

#[derive(Debug)]
pub struct DefinitionParams<'db> {
    pub workspace: &'db Workspace,
    pub document: &'db Document,
    pub offset: TextSize,
}

#[derive(Debug, PartialEq, Eq, Clone)]
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: Vec<DefinitionResult<'db>>,
}

pub fn goto_definition<'db>(params: DefinitionParams<'db>) -> Vec<DefinitionResult<'db>> {
    let project = params.workspace.project(params.document);
    let mut context = DefinitionContext {
        params,
        project,
        results: Vec::new(),
    };

    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;