mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Better names
This commit is contained in:
parent
8a0bd50036
commit
d4fb7476ef
3 changed files with 24 additions and 23 deletions
|
@ -74,7 +74,7 @@ pub(crate) fn highlight(
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
|
let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
|
||||||
let mut stack = highlights::Highlights::new(range_to_highlight);
|
let mut hl = highlights::Highlights::new(range_to_highlight);
|
||||||
|
|
||||||
let mut current_macro_call: Option<ast::MacroCall> = None;
|
let mut current_macro_call: Option<ast::MacroCall> = None;
|
||||||
let mut current_macro_rules: Option<ast::MacroRules> = None;
|
let mut current_macro_rules: Option<ast::MacroRules> = None;
|
||||||
|
@ -98,7 +98,7 @@ pub(crate) fn highlight(
|
||||||
match event.clone().map(|it| it.into_node().and_then(ast::MacroCall::cast)) {
|
match event.clone().map(|it| it.into_node().and_then(ast::MacroCall::cast)) {
|
||||||
WalkEvent::Enter(Some(mc)) => {
|
WalkEvent::Enter(Some(mc)) => {
|
||||||
if let Some(range) = macro_call_range(&mc) {
|
if let Some(range) = macro_call_range(&mc) {
|
||||||
stack.add(HlRange {
|
hl.add(HlRange {
|
||||||
range,
|
range,
|
||||||
highlight: HlTag::Symbol(SymbolKind::Macro).into(),
|
highlight: HlTag::Symbol(SymbolKind::Macro).into(),
|
||||||
binding_hash: None,
|
binding_hash: None,
|
||||||
|
@ -136,7 +136,7 @@ pub(crate) fn highlight(
|
||||||
inside_attribute = false
|
inside_attribute = false
|
||||||
}
|
}
|
||||||
if let Some((new_comments, inj)) = injection::extract_doc_comments(node) {
|
if let Some((new_comments, inj)) = injection::extract_doc_comments(node) {
|
||||||
injection::highlight_doc_comment(new_comments, inj, &mut stack);
|
injection::highlight_doc_comment(new_comments, inj, &mut hl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WalkEvent::Enter(NodeOrToken::Node(node)) if ast::Attr::can_cast(node.kind()) => {
|
WalkEvent::Enter(NodeOrToken::Node(node)) if ast::Attr::can_cast(node.kind()) => {
|
||||||
|
@ -181,7 +181,7 @@ pub(crate) fn highlight(
|
||||||
if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) {
|
if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) {
|
||||||
if token.is_raw() {
|
if token.is_raw() {
|
||||||
let expanded = element_to_highlight.as_token().unwrap().clone();
|
let expanded = element_to_highlight.as_token().unwrap().clone();
|
||||||
if injection::highlight_injection(&mut stack, &sema, token, expanded).is_some() {
|
if injection::highlight_injection(&mut hl, &sema, token, expanded).is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,18 +198,18 @@ pub(crate) fn highlight(
|
||||||
}
|
}
|
||||||
|
|
||||||
if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() {
|
if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() {
|
||||||
stack.add(HlRange { range, highlight, binding_hash });
|
hl.add(HlRange { range, highlight, binding_hash });
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(string) =
|
if let Some(string) =
|
||||||
element_to_highlight.as_token().cloned().and_then(ast::String::cast)
|
element_to_highlight.as_token().cloned().and_then(ast::String::cast)
|
||||||
{
|
{
|
||||||
format_string_highlighter.highlight_format_string(&mut stack, &string, range);
|
format_string_highlighter.highlight_format_string(&mut hl, &string, range);
|
||||||
// Highlight escape sequences
|
// Highlight escape sequences
|
||||||
if let Some(char_ranges) = string.char_ranges() {
|
if let Some(char_ranges) = string.char_ranges() {
|
||||||
for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) {
|
for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) {
|
||||||
if string.text()[piece_range.start().into()..].starts_with('\\') {
|
if string.text()[piece_range.start().into()..].starts_with('\\') {
|
||||||
stack.add(HlRange {
|
hl.add(HlRange {
|
||||||
range: piece_range + range.start(),
|
range: piece_range + range.start(),
|
||||||
highlight: HlTag::EscapeSequence.into(),
|
highlight: HlTag::EscapeSequence.into(),
|
||||||
binding_hash: None,
|
binding_hash: None,
|
||||||
|
@ -221,7 +221,7 @@ pub(crate) fn highlight(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.to_vec()
|
hl.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
|
fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
|
||||||
|
|
|
@ -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 text = parse.tree().syntax().to_string();
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
buf.push_str(&STYLE);
|
buf.push_str(&STYLE);
|
||||||
buf.push_str("<pre><code>");
|
buf.push_str("<pre><code>");
|
||||||
for range in &ranges {
|
for r in &hl_ranges {
|
||||||
let curr = &text[range.range];
|
let chunk = html_escape(&text[r.range]);
|
||||||
if range.highlight.is_empty() {
|
if r.highlight.is_empty() {
|
||||||
format_to!(buf, "{}", html_escape(curr));
|
format_to!(buf, "{}", chunk);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let class = range.highlight.to_string().replace('.', " ");
|
let class = r.highlight.to_string().replace('.', " ");
|
||||||
let color = match (rainbow, range.binding_hash) {
|
let color = match (rainbow, r.binding_hash) {
|
||||||
(true, Some(hash)) => {
|
(true, Some(hash)) => {
|
||||||
format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
|
format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
|
||||||
}
|
}
|
||||||
_ => "".into(),
|
_ => "".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.push_str("</code></pre>");
|
||||||
buf
|
buf
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{Analysis, HlMod, HlRange, HlTag, RootDatabase};
|
||||||
use super::{highlights::Highlights, injector::Injector};
|
use super::{highlights::Highlights, injector::Injector};
|
||||||
|
|
||||||
pub(super) fn highlight_injection(
|
pub(super) fn highlight_injection(
|
||||||
acc: &mut Highlights,
|
hl: &mut Highlights,
|
||||||
sema: &Semantics<RootDatabase>,
|
sema: &Semantics<RootDatabase>,
|
||||||
literal: ast::String,
|
literal: ast::String,
|
||||||
expanded: SyntaxToken,
|
expanded: SyntaxToken,
|
||||||
|
@ -21,24 +21,25 @@ pub(super) fn highlight_injection(
|
||||||
if !active_parameter.name.starts_with("ra_fixture") {
|
if !active_parameter.name.starts_with("ra_fixture") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = literal.value()?;
|
let value = literal.value()?;
|
||||||
let marker_info = MarkerInfo::new(&*value);
|
let marker_info = MarkerInfo::new(&*value);
|
||||||
let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone());
|
let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone());
|
||||||
|
|
||||||
if let Some(range) = literal.open_quote_text_range() {
|
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() {
|
for mut hl_range in analysis.highlight(tmp_file_id).unwrap() {
|
||||||
let range = marker_info.map_range_up(h.range);
|
let range = marker_info.map_range_up(hl_range.range);
|
||||||
if let Some(range) = literal.map_range_up(range) {
|
if let Some(range) = literal.map_range_up(range) {
|
||||||
h.range = range;
|
hl_range.range = range;
|
||||||
acc.add(h);
|
hl.add(hl_range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(range) = literal.close_quote_text_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(())
|
Some(())
|
||||||
|
|
Loading…
Reference in a new issue