From 3dfa2768acdd6bbf0e6999cdc4eb5cf0718b95a4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 9 Jan 2021 14:48:15 +0300 Subject: Shorten names --- crates/ide/src/syntax_highlighting/format.rs | 4 +- crates/ide/src/syntax_highlighting/highlights.rs | 61 ++++++++++------------- crates/ide/src/syntax_highlighting/injection.rs | 22 +++----- crates/ide/src/syntax_highlighting/macro_rules.rs | 6 +-- 4 files changed, 38 insertions(+), 55 deletions(-) (limited to 'crates/ide/src/syntax_highlighting') diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index 94cecd97f..d807ad0ad 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs @@ -4,7 +4,7 @@ use syntax::{ AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, }; -use crate::{HighlightedRange, HlTag, SymbolKind}; +use crate::{HlRange, HlTag, SymbolKind}; use super::highlights::Highlights; @@ -46,7 +46,7 @@ impl FormatStringHighlighter { if self.format_string.as_ref() == Some(&SyntaxElement::from(string.syntax().clone())) { string.lex_format_specifier(|piece_range, kind| { if let Some(highlight) = highlight_format_specifier(kind) { - stack.add(HighlightedRange { + stack.add(HlRange { range: piece_range + range.start(), highlight: highlight.into(), binding_hash: None, diff --git a/crates/ide/src/syntax_highlighting/highlights.rs b/crates/ide/src/syntax_highlighting/highlights.rs index f52076509..11c11ed28 100644 --- a/crates/ide/src/syntax_highlighting/highlights.rs +++ b/crates/ide/src/syntax_highlighting/highlights.rs @@ -4,33 +4,29 @@ use std::{cmp::Ordering, iter}; use stdx::equal_range_by; use syntax::TextRange; -use crate::{HighlightedRange, HlTag}; +use crate::{HlRange, HlTag}; pub(super) struct Highlights { root: Node, } struct Node { - highlighted_range: HighlightedRange, + hl_range: HlRange, nested: Vec, } impl Highlights { pub(super) fn new(range: TextRange) -> Highlights { Highlights { - root: Node::new(HighlightedRange { - range, - highlight: HlTag::None.into(), - binding_hash: None, - }), + root: Node::new(HlRange { range, highlight: HlTag::None.into(), binding_hash: None }), } } - pub(super) fn add(&mut self, highlighted_range: HighlightedRange) { - self.root.add(highlighted_range); + pub(super) fn add(&mut self, hl_range: HlRange) { + self.root.add(hl_range); } - pub(super) fn to_vec(self) -> Vec { + pub(super) fn to_vec(self) -> Vec { let mut res = Vec::new(); self.root.flatten(&mut res); res @@ -38,59 +34,54 @@ impl Highlights { } impl Node { - fn new(highlighted_range: HighlightedRange) -> Node { - Node { highlighted_range, nested: Vec::new() } + fn new(hl_range: HlRange) -> Node { + Node { hl_range, nested: Vec::new() } } - fn add(&mut self, highlighted_range: HighlightedRange) { - assert!(self.highlighted_range.range.contains_range(highlighted_range.range)); + fn add(&mut self, hl_range: HlRange) { + assert!(self.hl_range.range.contains_range(hl_range.range)); // Fast path if let Some(last) = self.nested.last_mut() { - if last.highlighted_range.range.contains_range(highlighted_range.range) { - return last.add(highlighted_range); + if last.hl_range.range.contains_range(hl_range.range) { + return last.add(hl_range); } - if last.highlighted_range.range.end() <= highlighted_range.range.start() { - return self.nested.push(Node::new(highlighted_range)); + if last.hl_range.range.end() <= hl_range.range.start() { + return self.nested.push(Node::new(hl_range)); } } - let (start, len) = equal_range_by(&self.nested, |n| { - ordering(n.highlighted_range.range, highlighted_range.range) - }); + let (start, len) = + equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range)); - if len == 1 - && self.nested[start].highlighted_range.range.contains_range(highlighted_range.range) - { - return self.nested[start].add(highlighted_range); + if len == 1 && self.nested[start].hl_range.range.contains_range(hl_range.range) { + return self.nested[start].add(hl_range); } let nested = self .nested - .splice(start..start + len, iter::once(Node::new(highlighted_range))) + .splice(start..start + len, iter::once(Node::new(hl_range))) .collect::>(); self.nested[start].nested = nested; } - fn flatten(&self, acc: &mut Vec) { - let mut start = self.highlighted_range.range.start(); + fn flatten(&self, acc: &mut Vec) { + let mut start = self.hl_range.range.start(); let mut nested = self.nested.iter(); loop { let next = nested.next(); - let end = next.map_or(self.highlighted_range.range.end(), |it| { - it.highlighted_range.range.start() - }); + let end = next.map_or(self.hl_range.range.end(), |it| it.hl_range.range.start()); if start < end { - acc.push(HighlightedRange { + acc.push(HlRange { range: TextRange::new(start, end), - highlight: self.highlighted_range.highlight, - binding_hash: self.highlighted_range.binding_hash, + highlight: self.hl_range.highlight, + binding_hash: self.hl_range.binding_hash, }); } start = match next { Some(child) => { child.flatten(acc); - child.highlighted_range.range.end() + child.hl_range.range.end() } None => break, } diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs index a6941234e..13dde1dc4 100644 --- a/crates/ide/src/syntax_highlighting/injection.rs +++ b/crates/ide/src/syntax_highlighting/injection.rs @@ -7,7 +7,7 @@ use ide_db::call_info::ActiveParameter; use itertools::Itertools; use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; -use crate::{Analysis, HighlightedRange, HlMod, HlTag, RootDatabase}; +use crate::{Analysis, HlMod, HlRange, HlTag, RootDatabase}; use super::{highlights::Highlights, injector::Injector}; @@ -26,11 +26,7 @@ pub(super) fn highlight_injection( 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(HighlightedRange { - range, - highlight: HlTag::StringLiteral.into(), - binding_hash: None, - }) + acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) } for mut h in analysis.highlight(tmp_file_id).unwrap() { @@ -42,11 +38,7 @@ pub(super) fn highlight_injection( } if let Some(range) = literal.close_quote_text_range() { - acc.add(HighlightedRange { - range, - highlight: HlTag::StringLiteral.into(), - binding_hash: None, - }) + acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) } Some(()) @@ -116,7 +108,7 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[ /// Lastly, a vector of new comment highlight ranges (spanning only the /// comment prefix) is returned which is used in the syntax highlighting /// injection to replace the previous (line-spanning) comment ranges. -pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec, Injector)> { +pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec, Injector)> { let mut inj = Injector::default(); // wrap the doctest into function body to get correct syntax highlighting let prefix = "fn doctest() {\n"; @@ -166,7 +158,7 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec Option<(Vec, + new_comments: Vec, inj: Injector, stack: &mut Highlights, ) { @@ -207,7 +199,7 @@ pub(super) fn highlight_doc_comment( for h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() { for r in inj.map_range_up(h.range) { - stack.add(HighlightedRange { + stack.add(HlRange { range: r, highlight: h.highlight | HlMod::Injected, binding_hash: h.binding_hash, diff --git a/crates/ide/src/syntax_highlighting/macro_rules.rs b/crates/ide/src/syntax_highlighting/macro_rules.rs index 71dd1ccc5..21d8a9835 100644 --- a/crates/ide/src/syntax_highlighting/macro_rules.rs +++ b/crates/ide/src/syntax_highlighting/macro_rules.rs @@ -1,7 +1,7 @@ //! Syntax highlighting for macro_rules!. use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; -use crate::{HighlightedRange, HlTag}; +use crate::{HlRange, HlTag}; #[derive(Default)] pub(super) struct MacroRulesHighlighter { @@ -19,11 +19,11 @@ impl MacroRulesHighlighter { } } - pub(super) fn highlight(&self, element: SyntaxElement) -> Option { + pub(super) fn highlight(&self, element: SyntaxElement) -> Option { if let Some(state) = self.state.as_ref() { if matches!(state.rule_state, RuleState::Matcher | RuleState::Expander) { if let Some(range) = is_metavariable(element) { - return Some(HighlightedRange { + return Some(HlRange { range, highlight: HlTag::UnresolvedReference.into(), binding_hash: None, -- cgit v1.2.3