mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
make it build again
This commit is contained in:
parent
2b200f6e1a
commit
5abcca516d
3 changed files with 28 additions and 14 deletions
|
@ -18,7 +18,7 @@ fn main() -> Result<()> {
|
||||||
.subcommand(SubCommand::with_name("symbols"))
|
.subcommand(SubCommand::with_name("symbols"))
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("highlight")
|
SubCommand::with_name("highlight")
|
||||||
.arg(Arg::with_name("rainbow").short("r").long("rainbow"))
|
.arg(Arg::with_name("rainbow").short("r").long("rainbow")),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("analysis-stats")
|
SubCommand::with_name("analysis-stats")
|
||||||
|
|
|
@ -85,13 +85,18 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
||||||
Some(SelfType(_)) => "type",
|
Some(SelfType(_)) => "type",
|
||||||
Some(Pat(ptr)) => {
|
Some(Pat(ptr)) => {
|
||||||
binding_hash = Some({
|
binding_hash = Some({
|
||||||
let text = ptr.syntax_node_ptr().to_node(&source_file.syntax()).text().to_smol_string();
|
let text = ptr
|
||||||
let shadow_count = bindings_shadow_count.entry(text.clone()).or_default();
|
.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)
|
calc_binding_hash(file_id, &text, *shadow_count)
|
||||||
});
|
});
|
||||||
|
|
||||||
"variable"
|
"variable"
|
||||||
},
|
}
|
||||||
Some(SelfParam(_)) => "type",
|
Some(SelfParam(_)) => "type",
|
||||||
Some(GenericParam(_)) => "type",
|
Some(GenericParam(_)) => "type",
|
||||||
None => "text",
|
None => "text",
|
||||||
|
@ -105,7 +110,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
||||||
if name.syntax().ancestors().any(|x| ast::BindPat::cast(x).is_some()) {
|
if name.syntax().ancestors().any(|x| ast::BindPat::cast(x).is_some()) {
|
||||||
binding_hash = Some({
|
binding_hash = Some({
|
||||||
let text = name.syntax().text().to_smol_string();
|
let text = name.syntax().text().to_smol_string();
|
||||||
let shadow_count = bindings_shadow_count.entry(text.clone()).or_insert(0);
|
let shadow_count =
|
||||||
|
bindings_shadow_count.entry(text.clone()).or_insert(0);
|
||||||
*shadow_count += 1;
|
*shadow_count += 1;
|
||||||
calc_binding_hash(file_id, &text, *shadow_count)
|
calc_binding_hash(file_id, &text, *shadow_count)
|
||||||
});
|
});
|
||||||
|
@ -161,7 +167,8 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
|
||||||
fn rainbowify(seed: u64) -> String {
|
fn rainbowify(seed: u64) -> String {
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
let mut rng = SmallRng::seed_from_u64(seed);
|
let mut rng = SmallRng::seed_from_u64(seed);
|
||||||
format!("hsl({h},{s}%,{l}%)",
|
format!(
|
||||||
|
"hsl({h},{s}%,{l}%)",
|
||||||
h = rng.gen_range::<u16, _, _>(0, 361),
|
h = rng.gen_range::<u16, _, _>(0, 361),
|
||||||
s = rng.gen_range::<u16, _, _>(42, 99),
|
s = rng.gen_range::<u16, _, _>(42, 99),
|
||||||
l = rng.gen_range::<u16, _, _>(40, 91),
|
l = rng.gen_range::<u16, _, _>(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::<Vec<_>>().join(" ");
|
let classes = ranges.iter().map(|x| x.tag).collect::<Vec<_>>().join(" ");
|
||||||
let binding_hash = ranges.first().and_then(|x| x.binding_hash);
|
let binding_hash = ranges.first().and_then(|x| x.binding_hash);
|
||||||
let color = match (rainbow, binding_hash) {
|
let color = match (rainbow, binding_hash) {
|
||||||
(true, Some(hash)) => format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)),
|
(true, Some(hash)) => format!(
|
||||||
_ => "".into()
|
" data-binding-hash=\"{}\" style=\"color: {};\"",
|
||||||
|
hash,
|
||||||
|
rainbowify(hash)
|
||||||
|
),
|
||||||
|
_ => "".into(),
|
||||||
};
|
};
|
||||||
buf.push_str(&format!("<span class=\"{}\"{}>{}</span>", classes, color, text));
|
buf.push_str(&format!("<span class=\"{}\"{}>{}</span>", classes, color, text));
|
||||||
}
|
}
|
||||||
|
@ -264,10 +275,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
unsafe { vec.set_len(0); }
|
unsafe { vec.set_len(0); }
|
||||||
}
|
}
|
||||||
"#.trim(),
|
"#
|
||||||
|
.trim(),
|
||||||
);
|
);
|
||||||
let dst_file = project_dir().join("crates/ra_ide_api/src/snapshots/highlighting.html");
|
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);
|
let expected_html = &read_text(&dst_file);
|
||||||
std::fs::write(dst_file, &actual_html).unwrap();
|
std::fs::write(dst_file, &actual_html).unwrap();
|
||||||
assert_eq_text!(expected_html, actual_html);
|
assert_eq_text!(expected_html, actual_html);
|
||||||
|
@ -285,10 +297,12 @@ fn main() {
|
||||||
let x = "other color please!";
|
let x = "other color please!";
|
||||||
let y = x.to_string();
|
let y = x.to_string();
|
||||||
}
|
}
|
||||||
"#.trim(),
|
"#
|
||||||
|
.trim(),
|
||||||
);
|
);
|
||||||
let dst_file = project_dir().join("crates/ra_ide_api/src/snapshots/rainbow_highlighting.html");
|
let dst_file =
|
||||||
let actual_html = &analysis.highlight_as_html(file_id).unwrap();
|
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);
|
let expected_html = &read_text(&dst_file);
|
||||||
std::fs::write(dst_file, &actual_html).unwrap();
|
std::fs::write(dst_file, &actual_html).unwrap();
|
||||||
assert_eq_text!(expected_html, actual_html);
|
assert_eq_text!(expected_html, actual_html);
|
||||||
|
|
|
@ -875,7 +875,7 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> {
|
||||||
.map(|h| Decoration {
|
.map(|h| Decoration {
|
||||||
range: h.range.conv_with(&line_index),
|
range: h.range.conv_with(&line_index),
|
||||||
tag: h.tag,
|
tag: h.tag,
|
||||||
id: h.id.map(|x| x.to_string()),
|
id: h.binding_hash.map(|x| x.to_string()),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue