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
use std::collections::VecDeque;
use std::fmt::Display;
use std::ops::Range;
use rslint_parser::SyntaxToken;
use crate::rslint::convert_text_range;
#[derive(Debug)]
pub struct ScopeName {
pub(crate) components: VecDeque<NameComponent>,
}
impl ScopeName {
pub(crate) fn new() -> Self {
Self {
components: Default::default(),
}
}
pub fn components(&self) -> impl Iterator<Item = &NameComponent> + '_ {
self.components.iter()
}
}
impl Display for ScopeName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for c in self.components() {
f.write_str(c.text())?;
}
Ok(())
}
}
#[derive(Debug)]
pub struct NameComponent {
pub(crate) inner: NameComponentInner,
}
impl NameComponent {
pub fn text(&self) -> &str {
match &self.inner {
NameComponentInner::Interpolation(s) => s,
NameComponentInner::SourceIdentifierToken(t) => t.text().as_str(),
NameComponentInner::SourcePunctuationToken(_) => "",
}
}
pub fn range(&self) -> Option<Range<u32>> {
match &self.inner {
NameComponentInner::SourceIdentifierToken(t)
| NameComponentInner::SourcePunctuationToken(t) => {
Some(convert_text_range(t.text_range()))
}
_ => None,
}
}
pub(crate) fn interp(s: &'static str) -> Self {
Self {
inner: NameComponentInner::Interpolation(s),
}
}
pub(crate) fn ident(token: SyntaxToken) -> Self {
Self {
inner: NameComponentInner::SourceIdentifierToken(token),
}
}
pub(crate) fn punct(token: SyntaxToken) -> Self {
Self {
inner: NameComponentInner::SourcePunctuationToken(token),
}
}
}
#[derive(Debug)]
pub(crate) enum NameComponentInner {
Interpolation(&'static str),
SourceIdentifierToken(SyntaxToken),
SourcePunctuationToken(SyntaxToken),
}