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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! A reference site: where a unit names something.
use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::Language;
use super::id::{DefinitionId, ReferenceId, ResolutionUnitId};
use super::span::SourceSpan;
/// The closed vocabulary of references a report emits.
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "snake_case")]
pub enum ReferenceKind {
/// A module declaration naming another source.
Module,
/// An import, including a rename, a group member, a glob, or a re-export.
Import,
/// A call.
Call,
/// A type mentioned in a signature, a body, or a bound.
Type,
/// An implementation naming its type or its trait.
Implementation,
}
/// One reference site inside one resolution unit.
///
/// Two identical path texts at two locations are two references: the span, not
/// the text, is the site's identity.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct SymbolReference {
id: ReferenceId,
unit: ResolutionUnitId,
language: Language,
kind: ReferenceKind,
text: Arc<str>,
span: SourceSpan,
enclosing_definition: Option<DefinitionId>,
}
impl SymbolReference {
pub(crate) fn new(
id: ReferenceId,
unit: ResolutionUnitId,
language: Language,
kind: ReferenceKind,
text: Arc<str>,
span: SourceSpan,
enclosing_definition: Option<DefinitionId>,
) -> Self {
Self {
id,
unit,
language,
kind,
text,
span,
enclosing_definition,
}
}
/// This reference's identifier.
pub fn id(&self) -> ReferenceId {
self.id
}
/// The unit this reference occurs in.
pub fn unit(&self) -> ResolutionUnitId {
self.unit
}
/// The language of the unit this reference belongs to.
pub fn language(&self) -> Language {
self.language
}
/// What kind of reference this is.
pub fn kind(&self) -> ReferenceKind {
self.kind
}
/// The source text of the reference, alias and all.
pub fn text(&self) -> &str {
&self.text
}
/// Where the reference sits in the snapshotted source.
pub fn span(&self) -> &SourceSpan {
&self.span
}
/// The span, for a decoder interning the paths it just allocated.
pub(super) fn span_mut(&mut self) -> &mut SourceSpan {
&mut self.span
}
/// The definition this reference occurs inside, in the same unit.
pub fn enclosing_definition(&self) -> Option<DefinitionId> {
self.enclosing_definition
}
}