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
51
52
|
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,
pub include_declaration: bool,
}
#[derive(Debug)]
struct ReferenceContext<'a, 'b> {
params: &'b ReferenceParams<'a>,
results: Vec<Reference<'a>>,
}
pub fn find_all<'a>(params: &ReferenceParams<'a>) -> Vec<DocumentLocation<'a>> {
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
.into_iter()
.filter(|r| r.kind == ReferenceKind::Reference || params.include_declaration)
.map(|reference| reference.location)
.collect()
}
#[cfg(test)]
mod tests;
|