aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/syntax_highlighting.rs16
-rw-r--r--crates/ide/src/syntax_highlighting/html.rs16
-rw-r--r--crates/ide/src/syntax_highlighting/injection.rs15
3 files changed, 24 insertions, 23 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 8bb7acb82..3ba91b3f5 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -74,7 +74,7 @@ pub(crate) fn highlight(
74 }; 74 };
75 75
76 let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default(); 76 let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
77 let mut stack = highlights::Highlights::new(range_to_highlight); 77 let mut hl = highlights::Highlights::new(range_to_highlight);
78 78
79 let mut current_macro_call: Option<ast::MacroCall> = None; 79 let mut current_macro_call: Option<ast::MacroCall> = None;
80 let mut current_macro_rules: Option<ast::MacroRules> = None; 80 let mut current_macro_rules: Option<ast::MacroRules> = None;
@@ -98,7 +98,7 @@ pub(crate) fn highlight(
98 match event.clone().map(|it| it.into_node().and_then(ast::MacroCall::cast)) { 98 match event.clone().map(|it| it.into_node().and_then(ast::MacroCall::cast)) {
99 WalkEvent::Enter(Some(mc)) => { 99 WalkEvent::Enter(Some(mc)) => {
100 if let Some(range) = macro_call_range(&mc) { 100 if let Some(range) = macro_call_range(&mc) {
101 stack.add(HlRange { 101 hl.add(HlRange {
102 range, 102 range,
103 highlight: HlTag::Symbol(SymbolKind::Macro).into(), 103 highlight: HlTag::Symbol(SymbolKind::Macro).into(),
104 binding_hash: None, 104 binding_hash: None,
@@ -136,7 +136,7 @@ pub(crate) fn highlight(
136 inside_attribute = false 136 inside_attribute = false
137 } 137 }
138 if let Some((new_comments, inj)) = injection::extract_doc_comments(node) { 138 if let Some((new_comments, inj)) = injection::extract_doc_comments(node) {
139 injection::highlight_doc_comment(new_comments, inj, &mut stack); 139 injection::highlight_doc_comment(new_comments, inj, &mut hl);
140 } 140 }
141 } 141 }
142 WalkEvent::Enter(NodeOrToken::Node(node)) if ast::Attr::can_cast(node.kind()) => { 142 WalkEvent::Enter(NodeOrToken::Node(node)) if ast::Attr::can_cast(node.kind()) => {
@@ -181,7 +181,7 @@ pub(crate) fn highlight(
181 if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) { 181 if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) {
182 if token.is_raw() { 182 if token.is_raw() {
183 let expanded = element_to_highlight.as_token().unwrap().clone(); 183 let expanded = element_to_highlight.as_token().unwrap().clone();
184 if injection::highlight_injection(&mut stack, &sema, token, expanded).is_some() { 184 if injection::highlight_injection(&mut hl, &sema, token, expanded).is_some() {
185 continue; 185 continue;
186 } 186 }
187 } 187 }
@@ -198,18 +198,18 @@ pub(crate) fn highlight(
198 } 198 }
199 199
200 if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() { 200 if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() {
201 stack.add(HlRange { range, highlight, binding_hash }); 201 hl.add(HlRange { range, highlight, binding_hash });
202 } 202 }
203 203
204 if let Some(string) = 204 if let Some(string) =
205 element_to_highlight.as_token().cloned().and_then(ast::String::cast) 205 element_to_highlight.as_token().cloned().and_then(ast::String::cast)
206 { 206 {
207 format_string_highlighter.highlight_format_string(&mut stack, &string, range); 207 format_string_highlighter.highlight_format_string(&mut hl, &string, range);
208 // Highlight escape sequences 208 // Highlight escape sequences
209 if let Some(char_ranges) = string.char_ranges() { 209 if let Some(char_ranges) = string.char_ranges() {
210 for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) { 210 for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) {
211 if string.text()[piece_range.start().into()..].starts_with('\\') { 211 if string.text()[piece_range.start().into()..].starts_with('\\') {
212 stack.add(HlRange { 212 hl.add(HlRange {
213 range: piece_range + range.start(), 213 range: piece_range + range.start(),
214 highlight: HlTag::EscapeSequence.into(), 214 highlight: HlTag::EscapeSequence.into(),
215 binding_hash: None, 215 binding_hash: None,
@@ -221,7 +221,7 @@ pub(crate) fn highlight(
221 } 221 }
222 } 222 }
223 223
224 stack.to_vec() 224 hl.to_vec()
225} 225}
226 226
227fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> { 227fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs
index 44f611b25..0ee7bc96e 100644
--- a/crates/ide/src/syntax_highlighting/html.rs
+++ b/crates/ide/src/syntax_highlighting/html.rs
@@ -20,26 +20,26 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
20 ) 20 )
21 } 21 }
22 22
23 let ranges = highlight(db, file_id, None, false); 23 let hl_ranges = highlight(db, file_id, None, false);
24 let text = parse.tree().syntax().to_string(); 24 let text = parse.tree().syntax().to_string();
25 let mut buf = String::new(); 25 let mut buf = String::new();
26 buf.push_str(&STYLE); 26 buf.push_str(&STYLE);
27 buf.push_str("<pre><code>"); 27 buf.push_str("<pre><code>");
28 for range in &ranges { 28 for r in &hl_ranges {
29 let curr = &text[range.range]; 29 let chunk = html_escape(&text[r.range]);
30 if range.highlight.is_empty() { 30 if r.highlight.is_empty() {
31 format_to!(buf, "{}", html_escape(curr)); 31 format_to!(buf, "{}", chunk);
32 continue; 32 continue;
33 } 33 }
34 34
35 let class = range.highlight.to_string().replace('.', " "); 35 let class = r.highlight.to_string().replace('.', " ");
36 let color = match (rainbow, range.binding_hash) { 36 let color = match (rainbow, r.binding_hash) {
37 (true, Some(hash)) => { 37 (true, Some(hash)) => {
38 format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)) 38 format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
39 } 39 }
40 _ => "".into(), 40 _ => "".into(),
41 }; 41 };
42 format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, html_escape(curr)); 42 format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, chunk);
43 } 43 }
44 buf.push_str("</code></pre>"); 44 buf.push_str("</code></pre>");
45 buf 45 buf
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs
index 13dde1dc4..22d7f601a 100644
--- a/crates/ide/src/syntax_highlighting/injection.rs
+++ b/crates/ide/src/syntax_highlighting/injection.rs
@@ -12,7 +12,7 @@ use crate::{Analysis, HlMod, HlRange, HlTag, RootDatabase};
12use super::{highlights::Highlights, injector::Injector}; 12use super::{highlights::Highlights, injector::Injector};
13 13
14pub(super) fn highlight_injection( 14pub(super) fn highlight_injection(
15 acc: &mut Highlights, 15 hl: &mut Highlights,
16 sema: &Semantics<RootDatabase>, 16 sema: &Semantics<RootDatabase>,
17 literal: ast::String, 17 literal: ast::String,
18 expanded: SyntaxToken, 18 expanded: SyntaxToken,
@@ -21,24 +21,25 @@ pub(super) fn highlight_injection(
21 if !active_parameter.name.starts_with("ra_fixture") { 21 if !active_parameter.name.starts_with("ra_fixture") {
22 return None; 22 return None;
23 } 23 }
24
24 let value = literal.value()?; 25 let value = literal.value()?;
25 let marker_info = MarkerInfo::new(&*value); 26 let marker_info = MarkerInfo::new(&*value);
26 let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone()); 27 let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone());
27 28
28 if let Some(range) = literal.open_quote_text_range() { 29 if let Some(range) = literal.open_quote_text_range() {
29 acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) 30 hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
30 } 31 }
31 32
32 for mut h in analysis.highlight(tmp_file_id).unwrap() { 33 for mut hl_range in analysis.highlight(tmp_file_id).unwrap() {
33 let range = marker_info.map_range_up(h.range); 34 let range = marker_info.map_range_up(hl_range.range);
34 if let Some(range) = literal.map_range_up(range) { 35 if let Some(range) = literal.map_range_up(range) {
35 h.range = range; 36 hl_range.range = range;
36 acc.add(h); 37 hl.add(hl_range);
37 } 38 }
38 } 39 }
39 40
40 if let Some(range) = literal.close_quote_text_range() { 41 if let Some(range) = literal.close_quote_text_range() {
41 acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) 42 hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
42 } 43 }
43 44
44 Some(()) 45 Some(())