mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Shorten frequent names
This commit is contained in:
parent
6fb52af521
commit
64a6ee4535
8 changed files with 222 additions and 246 deletions
|
@ -4,7 +4,7 @@ use syntax::{
|
|||
AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange,
|
||||
};
|
||||
|
||||
use crate::{HighlightTag, HighlightedRange, SymbolKind};
|
||||
use crate::{HighlightedRange, HlTag, SymbolKind};
|
||||
|
||||
use super::highlights::Highlights;
|
||||
|
||||
|
@ -57,7 +57,7 @@ impl FormatStringHighlighter {
|
|||
}
|
||||
}
|
||||
|
||||
fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> {
|
||||
fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HlTag> {
|
||||
Some(match kind {
|
||||
FormatSpecifier::Open
|
||||
| FormatSpecifier::Close
|
||||
|
@ -69,8 +69,8 @@ fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> {
|
|||
| FormatSpecifier::DollarSign
|
||||
| FormatSpecifier::Dot
|
||||
| FormatSpecifier::Asterisk
|
||||
| FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier,
|
||||
FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral,
|
||||
FormatSpecifier::Identifier => HighlightTag::Symbol(SymbolKind::Local),
|
||||
| FormatSpecifier::QuestionMark => HlTag::FormatSpecifier,
|
||||
FormatSpecifier::Integer | FormatSpecifier::Zero => HlTag::NumericLiteral,
|
||||
FormatSpecifier::Identifier => HlTag::Symbol(SymbolKind::Local),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{cmp::Ordering, iter};
|
|||
use stdx::equal_range_by;
|
||||
use syntax::TextRange;
|
||||
|
||||
use crate::{HighlightTag, HighlightedRange};
|
||||
use crate::{HighlightedRange, HlTag};
|
||||
|
||||
pub(super) struct Highlights {
|
||||
root: Node,
|
||||
|
@ -20,7 +20,7 @@ impl Highlights {
|
|||
Highlights {
|
||||
root: Node::new(HighlightedRange {
|
||||
range,
|
||||
highlight: HighlightTag::None.into(),
|
||||
highlight: HlTag::None.into(),
|
||||
binding_hash: None,
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use ide_db::call_info::ActiveParameter;
|
|||
use itertools::Itertools;
|
||||
use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize};
|
||||
|
||||
use crate::{Analysis, HighlightModifier, HighlightTag, HighlightedRange, RootDatabase};
|
||||
use crate::{Analysis, HighlightedRange, HlMod, HlTag, RootDatabase};
|
||||
|
||||
use super::{highlights::Highlights, injector::Injector};
|
||||
|
||||
|
@ -28,7 +28,7 @@ pub(super) fn highlight_injection(
|
|||
if let Some(range) = literal.open_quote_text_range() {
|
||||
acc.add(HighlightedRange {
|
||||
range,
|
||||
highlight: HighlightTag::StringLiteral.into(),
|
||||
highlight: HlTag::StringLiteral.into(),
|
||||
binding_hash: None,
|
||||
})
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub(super) fn highlight_injection(
|
|||
if let Some(range) = literal.close_quote_text_range() {
|
||||
acc.add(HighlightedRange {
|
||||
range,
|
||||
highlight: HighlightTag::StringLiteral.into(),
|
||||
highlight: HlTag::StringLiteral.into(),
|
||||
binding_hash: None,
|
||||
})
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted
|
|||
range.start(),
|
||||
range.start() + TextSize::try_from(pos).unwrap(),
|
||||
),
|
||||
highlight: HighlightTag::Comment | HighlightModifier::Documentation,
|
||||
highlight: HlTag::Comment | HlMod::Documentation,
|
||||
binding_hash: None,
|
||||
});
|
||||
line_start += range.len() - TextSize::try_from(pos).unwrap();
|
||||
|
@ -209,7 +209,7 @@ pub(super) fn highlight_doc_comment(
|
|||
for r in inj.map_range_up(h.range) {
|
||||
stack.add(HighlightedRange {
|
||||
range: r,
|
||||
highlight: h.highlight | HighlightModifier::Injected,
|
||||
highlight: h.highlight | HlMod::Injected,
|
||||
binding_hash: h.binding_hash,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Syntax highlighting for macro_rules!.
|
||||
use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T};
|
||||
|
||||
use crate::{HighlightTag, HighlightedRange};
|
||||
use crate::{HighlightedRange, HlTag};
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct MacroRulesHighlighter {
|
||||
|
@ -25,7 +25,7 @@ impl MacroRulesHighlighter {
|
|||
if let Some(range) = is_metavariable(element) {
|
||||
return Some(HighlightedRange {
|
||||
range,
|
||||
highlight: HighlightTag::UnresolvedReference.into(),
|
||||
highlight: HlTag::UnresolvedReference.into(),
|
||||
binding_hash: None,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,15 +7,15 @@ use crate::SymbolKind;
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Highlight {
|
||||
pub tag: HighlightTag,
|
||||
pub modifiers: HighlightModifiers,
|
||||
pub tag: HlTag,
|
||||
pub mods: HlMods,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct HighlightModifiers(u32);
|
||||
pub struct HlMods(u32);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum HighlightTag {
|
||||
pub enum HlTag {
|
||||
Symbol(SymbolKind),
|
||||
|
||||
BoolLiteral,
|
||||
|
@ -39,7 +39,7 @@ pub enum HighlightTag {
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
#[repr(u8)]
|
||||
pub enum HighlightModifier {
|
||||
pub enum HlMod {
|
||||
/// Used to differentiate individual elements within attributes.
|
||||
Attribute = 0,
|
||||
/// Used with keywords like `if` and `break`.
|
||||
|
@ -61,10 +61,10 @@ pub enum HighlightModifier {
|
|||
Unsafe,
|
||||
}
|
||||
|
||||
impl HighlightTag {
|
||||
impl HlTag {
|
||||
fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
HighlightTag::Symbol(symbol) => match symbol {
|
||||
HlTag::Symbol(symbol) => match symbol {
|
||||
SymbolKind::Const => "constant",
|
||||
SymbolKind::Static => "static",
|
||||
SymbolKind::Enum => "enum",
|
||||
|
@ -86,59 +86,59 @@ impl HighlightTag {
|
|||
SymbolKind::SelfParam => "self_keyword",
|
||||
SymbolKind::Impl => "self_type",
|
||||
},
|
||||
HighlightTag::Attribute => "attribute",
|
||||
HighlightTag::BoolLiteral => "bool_literal",
|
||||
HighlightTag::BuiltinType => "builtin_type",
|
||||
HighlightTag::ByteLiteral => "byte_literal",
|
||||
HighlightTag::CharLiteral => "char_literal",
|
||||
HighlightTag::Comment => "comment",
|
||||
HighlightTag::EscapeSequence => "escape_sequence",
|
||||
HighlightTag::FormatSpecifier => "format_specifier",
|
||||
HighlightTag::Keyword => "keyword",
|
||||
HighlightTag::Punctuation => "punctuation",
|
||||
HighlightTag::NumericLiteral => "numeric_literal",
|
||||
HighlightTag::Operator => "operator",
|
||||
HighlightTag::StringLiteral => "string_literal",
|
||||
HighlightTag::UnresolvedReference => "unresolved_reference",
|
||||
HighlightTag::None => "none",
|
||||
HlTag::Attribute => "attribute",
|
||||
HlTag::BoolLiteral => "bool_literal",
|
||||
HlTag::BuiltinType => "builtin_type",
|
||||
HlTag::ByteLiteral => "byte_literal",
|
||||
HlTag::CharLiteral => "char_literal",
|
||||
HlTag::Comment => "comment",
|
||||
HlTag::EscapeSequence => "escape_sequence",
|
||||
HlTag::FormatSpecifier => "format_specifier",
|
||||
HlTag::Keyword => "keyword",
|
||||
HlTag::Punctuation => "punctuation",
|
||||
HlTag::NumericLiteral => "numeric_literal",
|
||||
HlTag::Operator => "operator",
|
||||
HlTag::StringLiteral => "string_literal",
|
||||
HlTag::UnresolvedReference => "unresolved_reference",
|
||||
HlTag::None => "none",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for HighlightTag {
|
||||
impl fmt::Display for HlTag {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(self.as_str(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl HighlightModifier {
|
||||
const ALL: &'static [HighlightModifier; HighlightModifier::Unsafe as u8 as usize + 1] = &[
|
||||
HighlightModifier::Attribute,
|
||||
HighlightModifier::ControlFlow,
|
||||
HighlightModifier::Definition,
|
||||
HighlightModifier::Documentation,
|
||||
HighlightModifier::Injected,
|
||||
HighlightModifier::Mutable,
|
||||
HighlightModifier::Consuming,
|
||||
HighlightModifier::Callable,
|
||||
HighlightModifier::Static,
|
||||
HighlightModifier::Associated,
|
||||
HighlightModifier::Unsafe,
|
||||
impl HlMod {
|
||||
const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[
|
||||
HlMod::Attribute,
|
||||
HlMod::ControlFlow,
|
||||
HlMod::Definition,
|
||||
HlMod::Documentation,
|
||||
HlMod::Injected,
|
||||
HlMod::Mutable,
|
||||
HlMod::Consuming,
|
||||
HlMod::Callable,
|
||||
HlMod::Static,
|
||||
HlMod::Associated,
|
||||
HlMod::Unsafe,
|
||||
];
|
||||
|
||||
fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
HighlightModifier::Attribute => "attribute",
|
||||
HighlightModifier::ControlFlow => "control",
|
||||
HighlightModifier::Definition => "declaration",
|
||||
HighlightModifier::Documentation => "documentation",
|
||||
HighlightModifier::Injected => "injected",
|
||||
HighlightModifier::Mutable => "mutable",
|
||||
HighlightModifier::Consuming => "consuming",
|
||||
HighlightModifier::Unsafe => "unsafe",
|
||||
HighlightModifier::Callable => "callable",
|
||||
HighlightModifier::Static => "static",
|
||||
HighlightModifier::Associated => "associated",
|
||||
HlMod::Attribute => "attribute",
|
||||
HlMod::ControlFlow => "control",
|
||||
HlMod::Definition => "declaration",
|
||||
HlMod::Documentation => "documentation",
|
||||
HlMod::Injected => "injected",
|
||||
HlMod::Mutable => "mutable",
|
||||
HlMod::Consuming => "consuming",
|
||||
HlMod::Unsafe => "unsafe",
|
||||
HlMod::Callable => "callable",
|
||||
HlMod::Static => "static",
|
||||
HlMod::Associated => "associated",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ impl HighlightModifier {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for HighlightModifier {
|
||||
impl fmt::Display for HlMod {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(self.as_str(), f)
|
||||
}
|
||||
|
@ -156,63 +156,63 @@ impl fmt::Display for HighlightModifier {
|
|||
impl fmt::Display for Highlight {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.tag)?;
|
||||
for modifier in self.modifiers.iter() {
|
||||
for modifier in self.mods.iter() {
|
||||
write!(f, ".{}", modifier)?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HighlightTag> for Highlight {
|
||||
fn from(tag: HighlightTag) -> Highlight {
|
||||
impl From<HlTag> for Highlight {
|
||||
fn from(tag: HlTag) -> Highlight {
|
||||
Highlight::new(tag)
|
||||
}
|
||||
}
|
||||
|
||||
impl Highlight {
|
||||
pub(crate) fn new(tag: HighlightTag) -> Highlight {
|
||||
Highlight { tag, modifiers: HighlightModifiers::default() }
|
||||
pub(crate) fn new(tag: HlTag) -> Highlight {
|
||||
Highlight { tag, mods: HlMods::default() }
|
||||
}
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.tag == HighlightTag::None && self.modifiers == HighlightModifiers::default()
|
||||
self.tag == HlTag::None && self.mods == HlMods::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::BitOr<HighlightModifier> for HighlightTag {
|
||||
impl ops::BitOr<HlMod> for HlTag {
|
||||
type Output = Highlight;
|
||||
|
||||
fn bitor(self, rhs: HighlightModifier) -> Highlight {
|
||||
fn bitor(self, rhs: HlMod) -> Highlight {
|
||||
Highlight::new(self) | rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::BitOrAssign<HighlightModifier> for HighlightModifiers {
|
||||
fn bitor_assign(&mut self, rhs: HighlightModifier) {
|
||||
impl ops::BitOrAssign<HlMod> for HlMods {
|
||||
fn bitor_assign(&mut self, rhs: HlMod) {
|
||||
self.0 |= rhs.mask();
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::BitOrAssign<HighlightModifier> for Highlight {
|
||||
fn bitor_assign(&mut self, rhs: HighlightModifier) {
|
||||
self.modifiers |= rhs;
|
||||
impl ops::BitOrAssign<HlMod> for Highlight {
|
||||
fn bitor_assign(&mut self, rhs: HlMod) {
|
||||
self.mods |= rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::BitOr<HighlightModifier> for Highlight {
|
||||
impl ops::BitOr<HlMod> for Highlight {
|
||||
type Output = Highlight;
|
||||
|
||||
fn bitor(mut self, rhs: HighlightModifier) -> Highlight {
|
||||
fn bitor(mut self, rhs: HlMod) -> Highlight {
|
||||
self |= rhs;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl HighlightModifiers {
|
||||
pub fn contains(self, m: HighlightModifier) -> bool {
|
||||
impl HlMods {
|
||||
pub fn contains(self, m: HlMod) -> bool {
|
||||
self.0 & m.mask() == m.mask()
|
||||
}
|
||||
|
||||
pub fn iter(self) -> impl Iterator<Item = HighlightModifier> {
|
||||
HighlightModifier::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask())
|
||||
pub fn iter(self) -> impl Iterator<Item = HlMod> {
|
||||
HlMod::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue