summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/reference.rs
blob: 54a5fefb2789f2744030d3139b357ecc8dc11b8a (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 entry;
mod label;
mod string;

use lsp_types::{Location, Position, ReferenceContext, Url};
use rowan::TextRange;

use crate::{
    db::Document,
    util::{cursor::CursorContext, line_index_ext::LineIndexExt},
    Db,
};

pub fn find_all(
    db: &dyn Db,
    uri: &Url,
    position: Position,
    params: &ReferenceContext,
) -> Option<Vec<Location>> {
    let mut results = Vec::new();
    let context = CursorContext::new(db, uri, position, params)?;
    log::debug!("[References] Cursor: {:?}", context.cursor);
    label::find_all_references(&context, &mut results);
    entry::find_all_references(&context, &mut results);
    string::find_all_references(&context, &mut results);

    let locations = results
        .into_iter()
        .map(|result| Location {
            uri: result.document.location(db).uri(db).clone(),
            range: result
                .document
                .contents(db)
                .line_index(db)
                .line_col_lsp_range(result.range),
        })
        .collect();

    Some(locations)
}

#[derive(Debug, Clone)]
struct ReferenceResult {
    document: Document,
    range: TextRange,
}