aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/syntax_highlighting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/syntax_highlighting.rs')
-rw-r--r--crates/ide/src/syntax_highlighting.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index e25b698e0..9df8d21af 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -5,7 +5,7 @@ mod injector;
5 5
6mod highlight; 6mod highlight;
7mod format; 7mod format;
8mod macro_rules; 8mod macro_;
9mod inject; 9mod inject;
10 10
11mod html; 11mod html;
@@ -24,8 +24,8 @@ use syntax::{
24 24
25use crate::{ 25use crate::{
26 syntax_highlighting::{ 26 syntax_highlighting::{
27 format::highlight_format_string, highlights::Highlights, 27 format::highlight_format_string, highlights::Highlights, macro_::MacroHighlighter,
28 macro_rules::MacroRulesHighlighter, tags::Highlight, 28 tags::Highlight,
29 }, 29 },
30 FileId, HlMod, HlTag, 30 FileId, HlMod, HlTag,
31}; 31};
@@ -48,6 +48,9 @@ pub struct HlRange {
48// 48//
49// The general rule is that a reference to an entity gets colored the same way as the entity itself. 49// The general rule is that a reference to an entity gets colored the same way as the entity itself.
50// We also give special modifier for `mut` and `&mut` local variables. 50// We also give special modifier for `mut` and `&mut` local variables.
51//
52// image::https://user-images.githubusercontent.com/48062697/113164457-06cfb980-9239-11eb-819b-0f93e646acf8.png[]
53// image::https://user-images.githubusercontent.com/48062697/113187625-f7f50100-9250-11eb-825e-91c58f236071.png[]
51pub(crate) fn highlight( 54pub(crate) fn highlight(
52 db: &RootDatabase, 55 db: &RootDatabase,
53 file_id: FileId, 56 file_id: FileId,
@@ -93,8 +96,8 @@ fn traverse(
93 let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default(); 96 let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
94 97
95 let mut current_macro_call: Option<ast::MacroCall> = None; 98 let mut current_macro_call: Option<ast::MacroCall> = None;
96 let mut current_macro_rules: Option<ast::MacroRules> = None; 99 let mut current_macro: Option<ast::Macro> = None;
97 let mut macro_rules_highlighter = MacroRulesHighlighter::default(); 100 let mut macro_highlighter = MacroHighlighter::default();
98 let mut inside_attribute = false; 101 let mut inside_attribute = false;
99 102
100 // Walk all nodes, keeping track of whether we are inside a macro or not. 103 // Walk all nodes, keeping track of whether we are inside a macro or not.
@@ -129,16 +132,16 @@ fn traverse(
129 _ => (), 132 _ => (),
130 } 133 }
131 134
132 match event.clone().map(|it| it.into_node().and_then(ast::MacroRules::cast)) { 135 match event.clone().map(|it| it.into_node().and_then(ast::Macro::cast)) {
133 WalkEvent::Enter(Some(mac)) => { 136 WalkEvent::Enter(Some(mac)) => {
134 macro_rules_highlighter.init(); 137 macro_highlighter.init();
135 current_macro_rules = Some(mac); 138 current_macro = Some(mac);
136 continue; 139 continue;
137 } 140 }
138 WalkEvent::Leave(Some(mac)) => { 141 WalkEvent::Leave(Some(mac)) => {
139 assert_eq!(current_macro_rules, Some(mac)); 142 assert_eq!(current_macro, Some(mac));
140 current_macro_rules = None; 143 current_macro = None;
141 macro_rules_highlighter = MacroRulesHighlighter::default(); 144 macro_highlighter = MacroHighlighter::default();
142 } 145 }
143 _ => (), 146 _ => (),
144 } 147 }
@@ -164,9 +167,9 @@ fn traverse(
164 167
165 let range = element.text_range(); 168 let range = element.text_range();
166 169
167 if current_macro_rules.is_some() { 170 if current_macro.is_some() {
168 if let Some(tok) = element.as_token() { 171 if let Some(tok) = element.as_token() {
169 macro_rules_highlighter.advance(tok); 172 macro_highlighter.advance(tok);
170 } 173 }
171 } 174 }
172 175
@@ -200,7 +203,7 @@ fn traverse(
200 } 203 }
201 } 204 }
202 205
203 if let Some(_) = macro_rules_highlighter.highlight(element_to_highlight.clone()) { 206 if let Some(_) = macro_highlighter.highlight(element_to_highlight.clone()) {
204 continue; 207 continue;
205 } 208 }
206 209