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_cli/src/main.rs | 2 +- crates/ra_ide_api/src/syntax_highlighting.rs | 38 ++++++++++++++++++-------- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) (limited to 'crates') diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index bdc7a76c6..84a1564ce 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -18,7 +18,7 @@ fn main() -> Result<()> { .subcommand(SubCommand::with_name("symbols")) .subcommand( SubCommand::with_name("highlight") - .arg(Arg::with_name("rainbow").short("r").long("rainbow")) + .arg(Arg::with_name("rainbow").short("r").long("rainbow")), ) .subcommand( SubCommand::with_name("analysis-stats") 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); diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5dfd64ed4..1df8224ba 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -875,7 +875,7 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result> { .map(|h| Decoration { range: h.range.conv_with(&line_index), tag: h.tag, - id: h.id.map(|x| x.to_string()), + id: h.binding_hash.map(|x| x.to_string()), }) .collect(); Ok(res) -- cgit v1.2.3