diff options
author | Aleksey Kladov <[email protected]> | 2021-01-09 11:44:01 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-01-09 11:44:01 +0000 |
commit | 64a6ee45351a71cdeb1d1dddc8fc746abdcff07b (patch) | |
tree | 1bcbd575286076950bf71719f8944e2d4322f939 /crates/ide/src/syntax_highlighting | |
parent | 6fb52af521ab8ca2fdd3ea7cfa95eaebd0cba1fc (diff) |
Shorten frequent names
Diffstat (limited to 'crates/ide/src/syntax_highlighting')
-rw-r--r-- | crates/ide/src/syntax_highlighting/format.rs | 10 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlights.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/injection.rs | 10 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/macro_rules.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 134 |
5 files changed, 81 insertions, 81 deletions
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index ab66b406c..94cecd97f 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs | |||
@@ -4,7 +4,7 @@ use syntax::{ | |||
4 | AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, | 4 | AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use crate::{HighlightTag, HighlightedRange, SymbolKind}; | 7 | use crate::{HighlightedRange, HlTag, SymbolKind}; |
8 | 8 | ||
9 | use super::highlights::Highlights; | 9 | use super::highlights::Highlights; |
10 | 10 | ||
@@ -57,7 +57,7 @@ impl FormatStringHighlighter { | |||
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> { | 60 | fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HlTag> { |
61 | Some(match kind { | 61 | Some(match kind { |
62 | FormatSpecifier::Open | 62 | FormatSpecifier::Open |
63 | | FormatSpecifier::Close | 63 | | FormatSpecifier::Close |
@@ -69,8 +69,8 @@ fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> { | |||
69 | | FormatSpecifier::DollarSign | 69 | | FormatSpecifier::DollarSign |
70 | | FormatSpecifier::Dot | 70 | | FormatSpecifier::Dot |
71 | | FormatSpecifier::Asterisk | 71 | | FormatSpecifier::Asterisk |
72 | | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier, | 72 | | FormatSpecifier::QuestionMark => HlTag::FormatSpecifier, |
73 | FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral, | 73 | FormatSpecifier::Integer | FormatSpecifier::Zero => HlTag::NumericLiteral, |
74 | FormatSpecifier::Identifier => HighlightTag::Symbol(SymbolKind::Local), | 74 | FormatSpecifier::Identifier => HlTag::Symbol(SymbolKind::Local), |
75 | }) | 75 | }) |
76 | } | 76 | } |
diff --git a/crates/ide/src/syntax_highlighting/highlights.rs b/crates/ide/src/syntax_highlighting/highlights.rs index 7ff1593ae..f52076509 100644 --- a/crates/ide/src/syntax_highlighting/highlights.rs +++ b/crates/ide/src/syntax_highlighting/highlights.rs | |||
@@ -4,7 +4,7 @@ use std::{cmp::Ordering, iter}; | |||
4 | use stdx::equal_range_by; | 4 | use stdx::equal_range_by; |
5 | use syntax::TextRange; | 5 | use syntax::TextRange; |
6 | 6 | ||
7 | use crate::{HighlightTag, HighlightedRange}; | 7 | use crate::{HighlightedRange, HlTag}; |
8 | 8 | ||
9 | pub(super) struct Highlights { | 9 | pub(super) struct Highlights { |
10 | root: Node, | 10 | root: Node, |
@@ -20,7 +20,7 @@ impl Highlights { | |||
20 | Highlights { | 20 | Highlights { |
21 | root: Node::new(HighlightedRange { | 21 | root: Node::new(HighlightedRange { |
22 | range, | 22 | range, |
23 | highlight: HighlightTag::None.into(), | 23 | highlight: HlTag::None.into(), |
24 | binding_hash: None, | 24 | binding_hash: None, |
25 | }), | 25 | }), |
26 | } | 26 | } |
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs index 98ee03e0d..a6941234e 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; | |||
7 | use itertools::Itertools; | 7 | use itertools::Itertools; |
8 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; | 8 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; |
9 | 9 | ||
10 | use crate::{Analysis, HighlightModifier, HighlightTag, HighlightedRange, RootDatabase}; | 10 | use crate::{Analysis, HighlightedRange, HlMod, HlTag, RootDatabase}; |
11 | 11 | ||
12 | use super::{highlights::Highlights, injector::Injector}; | 12 | use super::{highlights::Highlights, injector::Injector}; |
13 | 13 | ||
@@ -28,7 +28,7 @@ pub(super) fn highlight_injection( | |||
28 | if let Some(range) = literal.open_quote_text_range() { | 28 | if let Some(range) = literal.open_quote_text_range() { |
29 | acc.add(HighlightedRange { | 29 | acc.add(HighlightedRange { |
30 | range, | 30 | range, |
31 | highlight: HighlightTag::StringLiteral.into(), | 31 | highlight: HlTag::StringLiteral.into(), |
32 | binding_hash: None, | 32 | binding_hash: None, |
33 | }) | 33 | }) |
34 | } | 34 | } |
@@ -44,7 +44,7 @@ pub(super) fn highlight_injection( | |||
44 | if let Some(range) = literal.close_quote_text_range() { | 44 | if let Some(range) = literal.close_quote_text_range() { |
45 | acc.add(HighlightedRange { | 45 | acc.add(HighlightedRange { |
46 | range, | 46 | range, |
47 | highlight: HighlightTag::StringLiteral.into(), | 47 | highlight: HlTag::StringLiteral.into(), |
48 | binding_hash: None, | 48 | binding_hash: None, |
49 | }) | 49 | }) |
50 | } | 50 | } |
@@ -171,7 +171,7 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted | |||
171 | range.start(), | 171 | range.start(), |
172 | range.start() + TextSize::try_from(pos).unwrap(), | 172 | range.start() + TextSize::try_from(pos).unwrap(), |
173 | ), | 173 | ), |
174 | highlight: HighlightTag::Comment | HighlightModifier::Documentation, | 174 | highlight: HlTag::Comment | HlMod::Documentation, |
175 | binding_hash: None, | 175 | binding_hash: None, |
176 | }); | 176 | }); |
177 | line_start += range.len() - TextSize::try_from(pos).unwrap(); | 177 | line_start += range.len() - TextSize::try_from(pos).unwrap(); |
@@ -209,7 +209,7 @@ pub(super) fn highlight_doc_comment( | |||
209 | for r in inj.map_range_up(h.range) { | 209 | for r in inj.map_range_up(h.range) { |
210 | stack.add(HighlightedRange { | 210 | stack.add(HighlightedRange { |
211 | range: r, | 211 | range: r, |
212 | highlight: h.highlight | HighlightModifier::Injected, | 212 | highlight: h.highlight | HlMod::Injected, |
213 | binding_hash: h.binding_hash, | 213 | binding_hash: h.binding_hash, |
214 | }); | 214 | }); |
215 | } | 215 | } |
diff --git a/crates/ide/src/syntax_highlighting/macro_rules.rs b/crates/ide/src/syntax_highlighting/macro_rules.rs index 4462af47e..71dd1ccc5 100644 --- a/crates/ide/src/syntax_highlighting/macro_rules.rs +++ b/crates/ide/src/syntax_highlighting/macro_rules.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Syntax highlighting for macro_rules!. | 1 | //! Syntax highlighting for macro_rules!. |
2 | use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; | 2 | use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; |
3 | 3 | ||
4 | use crate::{HighlightTag, HighlightedRange}; | 4 | use crate::{HighlightedRange, HlTag}; |
5 | 5 | ||
6 | #[derive(Default)] | 6 | #[derive(Default)] |
7 | pub(super) struct MacroRulesHighlighter { | 7 | pub(super) struct MacroRulesHighlighter { |
@@ -25,7 +25,7 @@ impl MacroRulesHighlighter { | |||
25 | if let Some(range) = is_metavariable(element) { | 25 | if let Some(range) = is_metavariable(element) { |
26 | return Some(HighlightedRange { | 26 | return Some(HighlightedRange { |
27 | range, | 27 | range, |
28 | highlight: HighlightTag::UnresolvedReference.into(), | 28 | highlight: HlTag::UnresolvedReference.into(), |
29 | binding_hash: None, | 29 | binding_hash: None, |
30 | }); | 30 | }); |
31 | } | 31 | } |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 07c788b50..2f39bcc8e 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -7,15 +7,15 @@ use crate::SymbolKind; | |||
7 | 7 | ||
8 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 8 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
9 | pub struct Highlight { | 9 | pub struct Highlight { |
10 | pub tag: HighlightTag, | 10 | pub tag: HlTag, |
11 | pub modifiers: HighlightModifiers, | 11 | pub mods: HlMods, |
12 | } | 12 | } |
13 | 13 | ||
14 | #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 14 | #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
15 | pub struct HighlightModifiers(u32); | 15 | pub struct HlMods(u32); |
16 | 16 | ||
17 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 17 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
18 | pub enum HighlightTag { | 18 | pub enum HlTag { |
19 | Symbol(SymbolKind), | 19 | Symbol(SymbolKind), |
20 | 20 | ||
21 | BoolLiteral, | 21 | BoolLiteral, |
@@ -39,7 +39,7 @@ pub enum HighlightTag { | |||
39 | 39 | ||
40 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 40 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
41 | #[repr(u8)] | 41 | #[repr(u8)] |
42 | pub enum HighlightModifier { | 42 | pub enum HlMod { |
43 | /// Used to differentiate individual elements within attributes. | 43 | /// Used to differentiate individual elements within attributes. |
44 | Attribute = 0, | 44 | Attribute = 0, |
45 | /// Used with keywords like `if` and `break`. | 45 | /// Used with keywords like `if` and `break`. |
@@ -61,10 +61,10 @@ pub enum HighlightModifier { | |||
61 | Unsafe, | 61 | Unsafe, |
62 | } | 62 | } |
63 | 63 | ||
64 | impl HighlightTag { | 64 | impl HlTag { |
65 | fn as_str(self) -> &'static str { | 65 | fn as_str(self) -> &'static str { |
66 | match self { | 66 | match self { |
67 | HighlightTag::Symbol(symbol) => match symbol { | 67 | HlTag::Symbol(symbol) => match symbol { |
68 | SymbolKind::Const => "constant", | 68 | SymbolKind::Const => "constant", |
69 | SymbolKind::Static => "static", | 69 | SymbolKind::Static => "static", |
70 | SymbolKind::Enum => "enum", | 70 | SymbolKind::Enum => "enum", |
@@ -86,59 +86,59 @@ impl HighlightTag { | |||
86 | SymbolKind::SelfParam => "self_keyword", | 86 | SymbolKind::SelfParam => "self_keyword", |
87 | SymbolKind::Impl => "self_type", | 87 | SymbolKind::Impl => "self_type", |
88 | }, | 88 | }, |
89 | HighlightTag::Attribute => "attribute", | 89 | HlTag::Attribute => "attribute", |
90 | HighlightTag::BoolLiteral => "bool_literal", | 90 | HlTag::BoolLiteral => "bool_literal", |
91 | HighlightTag::BuiltinType => "builtin_type", | 91 | HlTag::BuiltinType => "builtin_type", |
92 | HighlightTag::ByteLiteral => "byte_literal", | 92 | HlTag::ByteLiteral => "byte_literal", |
93 | HighlightTag::CharLiteral => "char_literal", | 93 | HlTag::CharLiteral => "char_literal", |
94 | HighlightTag::Comment => "comment", | 94 | HlTag::Comment => "comment", |
95 | HighlightTag::EscapeSequence => "escape_sequence", | 95 | HlTag::EscapeSequence => "escape_sequence", |
96 | HighlightTag::FormatSpecifier => "format_specifier", | 96 | HlTag::FormatSpecifier => "format_specifier", |
97 | HighlightTag::Keyword => "keyword", | 97 | HlTag::Keyword => "keyword", |
98 | HighlightTag::Punctuation => "punctuation", | 98 | HlTag::Punctuation => "punctuation", |
99 | HighlightTag::NumericLiteral => "numeric_literal", | 99 | HlTag::NumericLiteral => "numeric_literal", |
100 | HighlightTag::Operator => "operator", | 100 | HlTag::Operator => "operator", |
101 | HighlightTag::StringLiteral => "string_literal", | 101 | HlTag::StringLiteral => "string_literal", |
102 | HighlightTag::UnresolvedReference => "unresolved_reference", | 102 | HlTag::UnresolvedReference => "unresolved_reference", |
103 | HighlightTag::None => "none", | 103 | HlTag::None => "none", |
104 | } | 104 | } |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | impl fmt::Display for HighlightTag { | 108 | impl fmt::Display for HlTag { |
109 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 109 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
110 | fmt::Display::fmt(self.as_str(), f) | 110 | fmt::Display::fmt(self.as_str(), f) |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | impl HighlightModifier { | 114 | impl HlMod { |
115 | const ALL: &'static [HighlightModifier; HighlightModifier::Unsafe as u8 as usize + 1] = &[ | 115 | const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[ |
116 | HighlightModifier::Attribute, | 116 | HlMod::Attribute, |
117 | HighlightModifier::ControlFlow, | 117 | HlMod::ControlFlow, |
118 | HighlightModifier::Definition, | 118 | HlMod::Definition, |
119 | HighlightModifier::Documentation, | 119 | HlMod::Documentation, |
120 | HighlightModifier::Injected, | 120 | HlMod::Injected, |
121 | HighlightModifier::Mutable, | 121 | HlMod::Mutable, |
122 | HighlightModifier::Consuming, | 122 | HlMod::Consuming, |
123 | HighlightModifier::Callable, | 123 | HlMod::Callable, |
124 | HighlightModifier::Static, | 124 | HlMod::Static, |
125 | HighlightModifier::Associated, | 125 | HlMod::Associated, |
126 | HighlightModifier::Unsafe, | 126 | HlMod::Unsafe, |
127 | ]; | 127 | ]; |
128 | 128 | ||
129 | fn as_str(self) -> &'static str { | 129 | fn as_str(self) -> &'static str { |
130 | match self { | 130 | match self { |
131 | HighlightModifier::Attribute => "attribute", | 131 | HlMod::Attribute => "attribute", |
132 | HighlightModifier::ControlFlow => "control", | 132 | HlMod::ControlFlow => "control", |
133 | HighlightModifier::Definition => "declaration", | 133 | HlMod::Definition => "declaration", |
134 | HighlightModifier::Documentation => "documentation", | 134 | HlMod::Documentation => "documentation", |
135 | HighlightModifier::Injected => "injected", | 135 | HlMod::Injected => "injected", |
136 | HighlightModifier::Mutable => "mutable", | 136 | HlMod::Mutable => "mutable", |
137 | HighlightModifier::Consuming => "consuming", | 137 | HlMod::Consuming => "consuming", |
138 | HighlightModifier::Unsafe => "unsafe", | 138 | HlMod::Unsafe => "unsafe", |
139 | HighlightModifier::Callable => "callable", | 139 | HlMod::Callable => "callable", |
140 | HighlightModifier::Static => "static", | 140 | HlMod::Static => "static", |
141 | HighlightModifier::Associated => "associated", | 141 | HlMod::Associated => "associated", |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
@@ -147,7 +147,7 @@ impl HighlightModifier { | |||
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | impl fmt::Display for HighlightModifier { | 150 | impl fmt::Display for HlMod { |
151 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 151 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
152 | fmt::Display::fmt(self.as_str(), f) | 152 | fmt::Display::fmt(self.as_str(), f) |
153 | } | 153 | } |
@@ -156,63 +156,63 @@ impl fmt::Display for HighlightModifier { | |||
156 | impl fmt::Display for Highlight { | 156 | impl fmt::Display for Highlight { |
157 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 157 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
158 | write!(f, "{}", self.tag)?; | 158 | write!(f, "{}", self.tag)?; |
159 | for modifier in self.modifiers.iter() { | 159 | for modifier in self.mods.iter() { |
160 | write!(f, ".{}", modifier)? | 160 | write!(f, ".{}", modifier)? |
161 | } | 161 | } |
162 | Ok(()) | 162 | Ok(()) |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | impl From<HighlightTag> for Highlight { | 166 | impl From<HlTag> for Highlight { |
167 | fn from(tag: HighlightTag) -> Highlight { | 167 | fn from(tag: HlTag) -> Highlight { |
168 | Highlight::new(tag) | 168 | Highlight::new(tag) |
169 | } | 169 | } |
170 | } | 170 | } |
171 | 171 | ||
172 | impl Highlight { | 172 | impl Highlight { |
173 | pub(crate) fn new(tag: HighlightTag) -> Highlight { | 173 | pub(crate) fn new(tag: HlTag) -> Highlight { |
174 | Highlight { tag, modifiers: HighlightModifiers::default() } | 174 | Highlight { tag, mods: HlMods::default() } |
175 | } | 175 | } |
176 | pub fn is_empty(&self) -> bool { | 176 | pub fn is_empty(&self) -> bool { |
177 | self.tag == HighlightTag::None && self.modifiers == HighlightModifiers::default() | 177 | self.tag == HlTag::None && self.mods == HlMods::default() |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | impl ops::BitOr<HighlightModifier> for HighlightTag { | 181 | impl ops::BitOr<HlMod> for HlTag { |
182 | type Output = Highlight; | 182 | type Output = Highlight; |
183 | 183 | ||
184 | fn bitor(self, rhs: HighlightModifier) -> Highlight { | 184 | fn bitor(self, rhs: HlMod) -> Highlight { |
185 | Highlight::new(self) | rhs | 185 | Highlight::new(self) | rhs |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | impl ops::BitOrAssign<HighlightModifier> for HighlightModifiers { | 189 | impl ops::BitOrAssign<HlMod> for HlMods { |
190 | fn bitor_assign(&mut self, rhs: HighlightModifier) { | 190 | fn bitor_assign(&mut self, rhs: HlMod) { |
191 | self.0 |= rhs.mask(); | 191 | self.0 |= rhs.mask(); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | impl ops::BitOrAssign<HighlightModifier> for Highlight { | 195 | impl ops::BitOrAssign<HlMod> for Highlight { |
196 | fn bitor_assign(&mut self, rhs: HighlightModifier) { | 196 | fn bitor_assign(&mut self, rhs: HlMod) { |
197 | self.modifiers |= rhs; | 197 | self.mods |= rhs; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | 200 | ||
201 | impl ops::BitOr<HighlightModifier> for Highlight { | 201 | impl ops::BitOr<HlMod> for Highlight { |
202 | type Output = Highlight; | 202 | type Output = Highlight; |
203 | 203 | ||
204 | fn bitor(mut self, rhs: HighlightModifier) -> Highlight { | 204 | fn bitor(mut self, rhs: HlMod) -> Highlight { |
205 | self |= rhs; | 205 | self |= rhs; |
206 | self | 206 | self |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | impl HighlightModifiers { | 210 | impl HlMods { |
211 | pub fn contains(self, m: HighlightModifier) -> bool { | 211 | pub fn contains(self, m: HlMod) -> bool { |
212 | self.0 & m.mask() == m.mask() | 212 | self.0 & m.mask() == m.mask() |
213 | } | 213 | } |
214 | 214 | ||
215 | pub fn iter(self) -> impl Iterator<Item = HighlightModifier> { | 215 | pub fn iter(self) -> impl Iterator<Item = HlMod> { |
216 | HighlightModifier::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask()) | 216 | HlMod::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask()) |
217 | } | 217 | } |
218 | } | 218 | } |