summaryrefslogtreecommitdiff
path: root/support/texlab/crates/links/src/include.rs
blob: 2a049d0b14bd5b616e2f918e4c7891f4c3975c37 (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
use base_db::{
    deps::{self, EdgeData},
    DocumentLocation, FeatureParams,
};

pub(super) fn find_links<'a>(
    params: &FeatureParams<'a>,
    results: &mut Vec<DocumentLocation<'a>>,
) -> Option<()> {
    let document = params.document;
    let parent = *deps::parents(params.workspace, document)
        .iter()
        .next()
        .unwrap_or(&document);

    let graph = &params.workspace.graphs()[&parent.uri];

    for edge in &graph.edges {
        if edge.source == document.uri {
            if let EdgeData::DirectLink(data) = &edge.data {
                let target = params.workspace.lookup(&edge.target).unwrap();
                results.push(DocumentLocation::new(target, data.link.path.range));
            }
        }
    }

    Some(())
}