mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Better names
This commit is contained in:
parent
8a0bd50036
commit
d4fb7476ef
3 changed files with 24 additions and 23 deletions
|
@ -20,26 +20,26 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
|
|||
)
|
||||
}
|
||||
|
||||
let ranges = highlight(db, file_id, None, false);
|
||||
let hl_ranges = highlight(db, file_id, None, false);
|
||||
let text = parse.tree().syntax().to_string();
|
||||
let mut buf = String::new();
|
||||
buf.push_str(&STYLE);
|
||||
buf.push_str("<pre><code>");
|
||||
for range in &ranges {
|
||||
let curr = &text[range.range];
|
||||
if range.highlight.is_empty() {
|
||||
format_to!(buf, "{}", html_escape(curr));
|
||||
for r in &hl_ranges {
|
||||
let chunk = html_escape(&text[r.range]);
|
||||
if r.highlight.is_empty() {
|
||||
format_to!(buf, "{}", chunk);
|
||||
continue;
|
||||
}
|
||||
|
||||
let class = range.highlight.to_string().replace('.', " ");
|
||||
let color = match (rainbow, range.binding_hash) {
|
||||
let class = r.highlight.to_string().replace('.', " ");
|
||||
let color = match (rainbow, r.binding_hash) {
|
||||
(true, Some(hash)) => {
|
||||
format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
|
||||
}
|
||||
_ => "".into(),
|
||||
};
|
||||
format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, html_escape(curr));
|
||||
format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, chunk);
|
||||
}
|
||||
buf.push_str("</code></pre>");
|
||||
buf
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{Analysis, HlMod, HlRange, HlTag, RootDatabase};
|
|||
use super::{highlights::Highlights, injector::Injector};
|
||||
|
||||
pub(super) fn highlight_injection(
|
||||
acc: &mut Highlights,
|
||||
hl: &mut Highlights,
|
||||
sema: &Semantics<RootDatabase>,
|
||||
literal: ast::String,
|
||||
expanded: SyntaxToken,
|
||||
|
@ -21,24 +21,25 @@ pub(super) fn highlight_injection(
|
|||
if !active_parameter.name.starts_with("ra_fixture") {
|
||||
return None;
|
||||
}
|
||||
|
||||
let value = literal.value()?;
|
||||
let marker_info = MarkerInfo::new(&*value);
|
||||
let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone());
|
||||
|
||||
if let Some(range) = literal.open_quote_text_range() {
|
||||
acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
|
||||
hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
|
||||
}
|
||||
|
||||
for mut h in analysis.highlight(tmp_file_id).unwrap() {
|
||||
let range = marker_info.map_range_up(h.range);
|
||||
for mut hl_range in analysis.highlight(tmp_file_id).unwrap() {
|
||||
let range = marker_info.map_range_up(hl_range.range);
|
||||
if let Some(range) = literal.map_range_up(range) {
|
||||
h.range = range;
|
||||
acc.add(h);
|
||||
hl_range.range = range;
|
||||
hl.add(hl_range);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(range) = literal.close_quote_text_range() {
|
||||
acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
|
||||
hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None })
|
||||
}
|
||||
|
||||
Some(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue