From 5abcca516d3563416d3fba9f2e4b8b024d10f846 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Sun, 26 May 2019 11:56:31 +0200 Subject: make it build again --- crates/ra_ide_api/src/syntax_highlighting.rs | 38 +++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index e46686ab9..dcefb0513 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -85,13 +85,18 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "type", Some(Pat(ptr)) => { binding_hash = Some({ - let text = ptr.syntax_node_ptr().to_node(&source_file.syntax()).text().to_smol_string(); - let shadow_count = bindings_shadow_count.entry(text.clone()).or_default(); + let text = ptr + .syntax_node_ptr() + .to_node(&source_file.syntax()) + .text() + .to_smol_string(); + let shadow_count = + bindings_shadow_count.entry(text.clone()).or_default(); calc_binding_hash(file_id, &text, *shadow_count) }); "variable" - }, + } Some(SelfParam(_)) => "type", Some(GenericParam(_)) => "type", None => "text", @@ -105,7 +110,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec String { use rand::prelude::*; let mut rng = SmallRng::seed_from_u64(seed); - format!("hsl({h},{s}%,{l}%)", + format!( + "hsl({h},{s}%,{l}%)", h = rng.gen_range::(0, 361), s = rng.gen_range::(42, 99), l = rng.gen_range::(40, 91), @@ -199,8 +206,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo let classes = ranges.iter().map(|x| x.tag).collect::>().join(" "); let binding_hash = ranges.first().and_then(|x| x.binding_hash); let color = match (rainbow, binding_hash) { - (true, Some(hash)) => format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)), - _ => "".into() + (true, Some(hash)) => format!( + " data-binding-hash=\"{}\" style=\"color: {};\"", + hash, + rainbowify(hash) + ), + _ => "".into(), }; buf.push_str(&format!("{}", classes, color, text)); } @@ -264,10 +275,11 @@ fn main() { } unsafe { vec.set_len(0); } } -"#.trim(), +"# + .trim(), ); let dst_file = project_dir().join("crates/ra_ide_api/src/snapshots/highlighting.html"); - let actual_html = &analysis.highlight_as_html(file_id).unwrap(); + let actual_html = &analysis.highlight_as_html(file_id, true).unwrap(); let expected_html = &read_text(&dst_file); std::fs::write(dst_file, &actual_html).unwrap(); assert_eq_text!(expected_html, actual_html); @@ -285,10 +297,12 @@ fn main() { let x = "other color please!"; let y = x.to_string(); } -"#.trim(), +"# + .trim(), ); - let dst_file = project_dir().join("crates/ra_ide_api/src/snapshots/rainbow_highlighting.html"); - let actual_html = &analysis.highlight_as_html(file_id).unwrap(); + let dst_file = + project_dir().join("crates/ra_ide_api/src/snapshots/rainbow_highlighting.html"); + let actual_html = &analysis.highlight_as_html(file_id, true).unwrap(); let expected_html = &read_text(&dst_file); std::fs::write(dst_file, &actual_html).unwrap(); assert_eq_text!(expected_html, actual_html); -- cgit v1.2.3