aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs71
1 files changed, 34 insertions, 37 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 22d0ed3e6..1b6eb1174 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -72,41 +72,31 @@ pub(crate) fn highlight(
72 let mut in_macro_call = None; 72 let mut in_macro_call = None;
73 73
74 for event in root.preorder_with_tokens() { 74 for event in root.preorder_with_tokens() {
75 match event { 75 let event_range = match &event {
76 WalkEvent::Enter(node) => { 76 WalkEvent::Enter(it) => it.text_range(),
77 if node.text_range().intersection(&range_to_highlight).is_none() { 77 WalkEvent::Leave(it) => it.text_range(),
78 continue; 78 };
79 }
80 79
81 match node.kind() { 80 if event_range.intersection(&range_to_highlight).is_none() {
82 MACRO_CALL => { 81 continue;
83 in_macro_call = Some(node.clone()); 82 }
84 if let Some(range) = highlight_macro(node) { 83
85 res.push(HighlightedRange { 84 match event {
86 range, 85 WalkEvent::Enter(node) => match node.kind() {
87 highlight: HighlightTag::Macro.into(), 86 MACRO_CALL => {
88 binding_hash: None, 87 in_macro_call = Some(node.clone());
89 }); 88 if let Some(range) = highlight_macro(node) {
90 } 89 res.push(HighlightedRange {
91 } 90 range,
92 _ if in_macro_call.is_some() => { 91 highlight: HighlightTag::Macro.into(),
93 if let Some(token) = node.as_token() { 92 binding_hash: None,
94 if let Some((highlight, binding_hash)) = highlight_token_tree( 93 });
95 &sema,
96 &mut bindings_shadow_count,
97 token.clone(),
98 ) {
99 res.push(HighlightedRange {
100 range: node.text_range(),
101 highlight,
102 binding_hash,
103 });
104 }
105 }
106 } 94 }
107 _ => { 95 }
96 _ if in_macro_call.is_some() => {
97 if let Some(token) = node.as_token() {
108 if let Some((highlight, binding_hash)) = 98 if let Some((highlight, binding_hash)) =
109 highlight_node(&sema, &mut bindings_shadow_count, node.clone()) 99 highlight_token_tree(&sema, &mut bindings_shadow_count, token.clone())
110 { 100 {
111 res.push(HighlightedRange { 101 res.push(HighlightedRange {
112 range: node.text_range(), 102 range: node.text_range(),
@@ -116,12 +106,19 @@ pub(crate) fn highlight(
116 } 106 }
117 } 107 }
118 } 108 }
119 } 109 _ => {
120 WalkEvent::Leave(node) => { 110 if let Some((highlight, binding_hash)) =
121 if node.text_range().intersection(&range_to_highlight).is_none() { 111 highlight_node(&sema, &mut bindings_shadow_count, node.clone())
122 continue; 112 {
113 res.push(HighlightedRange {
114 range: node.text_range(),
115 highlight,
116 binding_hash,
117 });
118 }
123 } 119 }
124 120 },
121 WalkEvent::Leave(node) => {
125 if let Some(m) = in_macro_call.as_ref() { 122 if let Some(m) = in_macro_call.as_ref() {
126 if *m == node { 123 if *m == node {
127 in_macro_call = None; 124 in_macro_call = None;