aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-05-24 19:29:48 +0100
committerJonas Schievink <[email protected]>2021-05-24 19:29:48 +0100
commit489ae7a800b02dbdacc1f949c067fa557333e7a1 (patch)
tree05fd003ccc166e52cf81e305a1073d56aed572ff
parent27bf62b70eeb6f4cb620be5630c4c4506be3539f (diff)
Make `TokenTextRange` private
-rw-r--r--crates/hir_expand/src/db.rs2
-rw-r--r--crates/hir_expand/src/hygiene.rs2
-rw-r--r--crates/hir_expand/src/lib.rs4
-rw-r--r--crates/mbe/src/tests/expand.rs5
-rw-r--r--crates/mbe/src/token_map.rs8
5 files changed, 10 insertions, 11 deletions
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs
index 5c769c1bf..03637878b 100644
--- a/crates/hir_expand/src/db.rs
+++ b/crates/hir_expand/src/db.rs
@@ -155,7 +155,7 @@ pub fn expand_hypothetical(
155 mbe::token_tree_to_syntax_node(&hypothetical_expansion.value, fragment_kind).ok()?; 155 mbe::token_tree_to_syntax_node(&hypothetical_expansion.value, fragment_kind).ok()?;
156 156
157 let token_id = macro_def.map_id_down(token_id); 157 let token_id = macro_def.map_id_down(token_id);
158 let range = tmap_2.range_by_token(token_id)?.by_kind(token_to_map.kind())?; 158 let range = tmap_2.range_by_token(token_id, token_to_map.kind())?;
159 let token = node.syntax_node().covering_element(range).into_token()?; 159 let token = node.syntax_node().covering_element(range).into_token()?;
160 Some((node.syntax_node(), token)) 160 Some((node.syntax_node(), token))
161} 161}
diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs
index 38e09fdd4..d98913907 100644
--- a/crates/hir_expand/src/hygiene.rs
+++ b/crates/hir_expand/src/hygiene.rs
@@ -154,7 +154,7 @@ impl HygieneInfo {
154 }, 154 },
155 }; 155 };
156 156
157 let range = token_map.range_by_token(token_id)?.by_kind(SyntaxKind::IDENT)?; 157 let range = token_map.range_by_token(token_id, SyntaxKind::IDENT)?;
158 Some((tt.with_value(range + tt.value), origin)) 158 Some((tt.with_value(range + tt.value), origin))
159 } 159 }
160} 160}
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 92c679dd2..6be4516a3 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -329,7 +329,7 @@ impl ExpansionInfo {
329 let token_id = self.macro_arg.1.token_by_range(range)?; 329 let token_id = self.macro_arg.1.token_by_range(range)?;
330 let token_id = self.macro_def.map_id_down(token_id); 330 let token_id = self.macro_def.map_id_down(token_id);
331 331
332 let range = self.exp_map.range_by_token(token_id)?.by_kind(token.value.kind())?; 332 let range = self.exp_map.range_by_token(token_id, token.value.kind())?;
333 333
334 let token = self.expanded.value.covering_element(range).into_token()?; 334 let token = self.expanded.value.covering_element(range).into_token()?;
335 335
@@ -354,7 +354,7 @@ impl ExpansionInfo {
354 }, 354 },
355 }; 355 };
356 356
357 let range = token_map.range_by_token(token_id)?.by_kind(token.value.kind())?; 357 let range = token_map.range_by_token(token_id, token.value.kind())?;
358 let token = 358 let token =
359 tt.value.covering_element(range + tt.value.text_range().start()).into_token()?; 359 tt.value.covering_element(range + tt.value.text_range().start()).into_token()?;
360 Some((tt.with_value(token), origin)) 360 Some((tt.with_value(token), origin))
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 3a1d840ea..5f173f513 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -58,9 +58,8 @@ macro_rules! foobar {
58 let (node, token_map) = token_tree_to_syntax_node(&expanded, FragmentKind::Items).unwrap(); 58 let (node, token_map) = token_tree_to_syntax_node(&expanded, FragmentKind::Items).unwrap();
59 let content = node.syntax_node().to_string(); 59 let content = node.syntax_node().to_string();
60 60
61 let get_text = |id, kind| -> String { 61 let get_text =
62 content[token_map.range_by_token(id).unwrap().by_kind(kind).unwrap()].to_string() 62 |id, kind| -> String { content[token_map.range_by_token(id, kind).unwrap()].to_string() };
63 };
64 63
65 assert_eq!(expanded.token_trees.len(), 4); 64 assert_eq!(expanded.token_trees.len(), 4);
66 // {($e:ident) => { fn $e() {} }} 65 // {($e:ident) => { fn $e() {} }}
diff --git a/crates/mbe/src/token_map.rs b/crates/mbe/src/token_map.rs
index 58c9f5aa5..0567475be 100644
--- a/crates/mbe/src/token_map.rs
+++ b/crates/mbe/src/token_map.rs
@@ -2,13 +2,13 @@ use parser::{SyntaxKind, T};
2use syntax::{TextRange, TextSize}; 2use syntax::{TextRange, TextSize};
3 3
4#[derive(Debug, PartialEq, Eq, Clone, Copy)] 4#[derive(Debug, PartialEq, Eq, Clone, Copy)]
5pub enum TokenTextRange { 5enum TokenTextRange {
6 Token(TextRange), 6 Token(TextRange),
7 Delimiter(TextRange), 7 Delimiter(TextRange),
8} 8}
9 9
10impl TokenTextRange { 10impl TokenTextRange {
11 pub fn by_kind(self, kind: SyntaxKind) -> Option<TextRange> { 11 fn by_kind(self, kind: SyntaxKind) -> Option<TextRange> {
12 match self { 12 match self {
13 TokenTextRange::Token(it) => Some(it), 13 TokenTextRange::Token(it) => Some(it),
14 TokenTextRange::Delimiter(it) => match kind { 14 TokenTextRange::Delimiter(it) => match kind {
@@ -42,9 +42,9 @@ impl TokenMap {
42 Some(token_id) 42 Some(token_id)
43 } 43 }
44 44
45 pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TokenTextRange> { 45 pub fn range_by_token(&self, token_id: tt::TokenId, kind: SyntaxKind) -> Option<TextRange> {
46 let &(_, range) = self.entries.iter().find(|(tid, _)| *tid == token_id)?; 46 let &(_, range) = self.entries.iter().find(|(tid, _)| *tid == token_id)?;
47 Some(range) 47 range.by_kind(kind)
48 } 48 }
49 49
50 pub(crate) fn shrink_to_fit(&mut self) { 50 pub(crate) fn shrink_to_fit(&mut self) {