aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorPascal Hertleif <[email protected]>2019-05-26 10:56:31 +0100
committerPascal Hertleif <[email protected]>2019-05-27 10:26:35 +0100
commit5abcca516d3563416d3fba9f2e4b8b024d10f846 (patch)
tree45e484435a5ee06d5a71ec7e5a9c525e7f9c7687 /crates
parent2b200f6e1a600e263f314efba5d8c3743095071b (diff)
make it build again
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_cli/src/main.rs2
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs38
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs2
3 files changed, 28 insertions, 14 deletions
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<()> {
18 .subcommand(SubCommand::with_name("symbols")) 18 .subcommand(SubCommand::with_name("symbols"))
19 .subcommand( 19 .subcommand(
20 SubCommand::with_name("highlight") 20 SubCommand::with_name("highlight")
21 .arg(Arg::with_name("rainbow").short("r").long("rainbow")) 21 .arg(Arg::with_name("rainbow").short("r").long("rainbow")),
22 ) 22 )
23 .subcommand( 23 .subcommand(
24 SubCommand::with_name("analysis-stats") 24 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<HighlightedRa
85 Some(SelfType(_)) => "type", 85 Some(SelfType(_)) => "type",
86 Some(Pat(ptr)) => { 86 Some(Pat(ptr)) => {
87 binding_hash = Some({ 87 binding_hash = Some({
88 let text = ptr.syntax_node_ptr().to_node(&source_file.syntax()).text().to_smol_string(); 88 let text = ptr
89 let shadow_count = bindings_shadow_count.entry(text.clone()).or_default(); 89 .syntax_node_ptr()
90 .to_node(&source_file.syntax())
91 .text()
92 .to_smol_string();
93 let shadow_count =
94 bindings_shadow_count.entry(text.clone()).or_default();
90 calc_binding_hash(file_id, &text, *shadow_count) 95 calc_binding_hash(file_id, &text, *shadow_count)
91 }); 96 });
92 97
93 "variable" 98 "variable"
94 }, 99 }
95 Some(SelfParam(_)) => "type", 100 Some(SelfParam(_)) => "type",
96 Some(GenericParam(_)) => "type", 101 Some(GenericParam(_)) => "type",
97 None => "text", 102 None => "text",
@@ -105,7 +110,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
105 if name.syntax().ancestors().any(|x| ast::BindPat::cast(x).is_some()) { 110 if name.syntax().ancestors().any(|x| ast::BindPat::cast(x).is_some()) {
106 binding_hash = Some({ 111 binding_hash = Some({
107 let text = name.syntax().text().to_smol_string(); 112 let text = name.syntax().text().to_smol_string();
108 let shadow_count = bindings_shadow_count.entry(text.clone()).or_insert(0); 113 let shadow_count =
114 bindings_shadow_count.entry(text.clone()).or_insert(0);
109 *shadow_count += 1; 115 *shadow_count += 1;
110 calc_binding_hash(file_id, &text, *shadow_count) 116 calc_binding_hash(file_id, &text, *shadow_count)
111 }); 117 });
@@ -161,7 +167,8 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
161 fn rainbowify(seed: u64) -> String { 167 fn rainbowify(seed: u64) -> String {
162 use rand::prelude::*; 168 use rand::prelude::*;
163 let mut rng = SmallRng::seed_from_u64(seed); 169 let mut rng = SmallRng::seed_from_u64(seed);
164 format!("hsl({h},{s}%,{l}%)", 170 format!(
171 "hsl({h},{s}%,{l}%)",
165 h = rng.gen_range::<u16, _, _>(0, 361), 172 h = rng.gen_range::<u16, _, _>(0, 361),
166 s = rng.gen_range::<u16, _, _>(42, 99), 173 s = rng.gen_range::<u16, _, _>(42, 99),
167 l = rng.gen_range::<u16, _, _>(40, 91), 174 l = rng.gen_range::<u16, _, _>(40, 91),
@@ -199,8 +206,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
199 let classes = ranges.iter().map(|x| x.tag).collect::<Vec<_>>().join(" "); 206 let classes = ranges.iter().map(|x| x.tag).collect::<Vec<_>>().join(" ");
200 let binding_hash = ranges.first().and_then(|x| x.binding_hash); 207 let binding_hash = ranges.first().and_then(|x| x.binding_hash);
201 let color = match (rainbow, binding_hash) { 208 let color = match (rainbow, binding_hash) {
202 (true, Some(hash)) => format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)), 209 (true, Some(hash)) => format!(
203 _ => "".into() 210 " data-binding-hash=\"{}\" style=\"color: {};\"",
211 hash,
212 rainbowify(hash)
213 ),
214 _ => "".into(),
204 }; 215 };
205 buf.push_str(&format!("<span class=\"{}\"{}>{}</span>", classes, color, text)); 216 buf.push_str(&format!("<span class=\"{}\"{}>{}</span>", classes, color, text));
206 } 217 }
@@ -264,10 +275,11 @@ fn main() {
264 } 275 }
265 unsafe { vec.set_len(0); } 276 unsafe { vec.set_len(0); }
266} 277}
267"#.trim(), 278"#
279 .trim(),
268 ); 280 );
269 let dst_file = project_dir().join("crates/ra_ide_api/src/snapshots/highlighting.html"); 281 let dst_file = project_dir().join("crates/ra_ide_api/src/snapshots/highlighting.html");
270 let actual_html = &analysis.highlight_as_html(file_id).unwrap(); 282 let actual_html = &analysis.highlight_as_html(file_id, true).unwrap();
271 let expected_html = &read_text(&dst_file); 283 let expected_html = &read_text(&dst_file);
272 std::fs::write(dst_file, &actual_html).unwrap(); 284 std::fs::write(dst_file, &actual_html).unwrap();
273 assert_eq_text!(expected_html, actual_html); 285 assert_eq_text!(expected_html, actual_html);
@@ -285,10 +297,12 @@ fn main() {
285 let x = "other color please!"; 297 let x = "other color please!";
286 let y = x.to_string(); 298 let y = x.to_string();
287} 299}
288"#.trim(), 300"#
301 .trim(),
289 ); 302 );
290 let dst_file = project_dir().join("crates/ra_ide_api/src/snapshots/rainbow_highlighting.html"); 303 let dst_file =
291 let actual_html = &analysis.highlight_as_html(file_id).unwrap(); 304 project_dir().join("crates/ra_ide_api/src/snapshots/rainbow_highlighting.html");
305 let actual_html = &analysis.highlight_as_html(file_id, true).unwrap();
292 let expected_html = &read_text(&dst_file); 306 let expected_html = &read_text(&dst_file);
293 std::fs::write(dst_file, &actual_html).unwrap(); 307 std::fs::write(dst_file, &actual_html).unwrap();
294 assert_eq_text!(expected_html, actual_html); 308 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<Vec<Decoration>> {
875 .map(|h| Decoration { 875 .map(|h| Decoration {
876 range: h.range.conv_with(&line_index), 876 range: h.range.conv_with(&line_index),
877 tag: h.tag, 877 tag: h.tag,
878 id: h.id.map(|x| x.to_string()), 878 id: h.binding_hash.map(|x| x.to_string()),
879 }) 879 })
880 .collect(); 880 .collect();
881 Ok(res) 881 Ok(res)