diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-28 13:48:42 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-28 13:48:42 +0000 |
commit | 2995fd2c87bba98d4cb7957a182a58bee68d86ba (patch) | |
tree | 9c8a33d167dbea0ffd0cb1460914542746905cad /crates/ra_ide/src/syntax_highlighting.rs | |
parent | 7e5cfcd4fb708f5d20a244ef010eaf57c055310d (diff) | |
parent | 9464ca97c90dca4cad57d29cac4fccdd99235925 (diff) |
Merge #3363
3363: Cleanup highlighting tags r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index d7bca1193..30ca9d8b0 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -177,10 +177,11 @@ fn highlight_element( | |||
177 | } | 177 | } |
178 | }; | 178 | }; |
179 | 179 | ||
180 | match name_kind { | 180 | let h = match name_kind { |
181 | Some(name_kind) => highlight_name(db, name_kind), | 181 | Some(name_kind) => highlight_name(db, name_kind), |
182 | None => highlight_name_by_syntax(name), | 182 | None => highlight_name_by_syntax(name), |
183 | } | 183 | }; |
184 | h | HighlightModifier::Definition | ||
184 | } | 185 | } |
185 | 186 | ||
186 | // Highlight references like the definitions they resolve to | 187 | // Highlight references like the definitions they resolve to |
@@ -206,12 +207,13 @@ fn highlight_element( | |||
206 | 207 | ||
207 | // Simple token-based highlighting | 208 | // Simple token-based highlighting |
208 | COMMENT => HighlightTag::Comment.into(), | 209 | COMMENT => HighlightTag::Comment.into(), |
209 | STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::LiteralString.into(), | 210 | STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), |
210 | ATTR => HighlightTag::Attribute.into(), | 211 | ATTR => HighlightTag::Attribute.into(), |
211 | INT_NUMBER | FLOAT_NUMBER => HighlightTag::LiteralNumeric.into(), | 212 | INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), |
212 | BYTE => HighlightTag::LiteralByte.into(), | 213 | BYTE => HighlightTag::ByteLiteral.into(), |
213 | CHAR => HighlightTag::LiteralChar.into(), | 214 | CHAR => HighlightTag::CharLiteral.into(), |
214 | LIFETIME => HighlightTag::TypeLifetime.into(), | 215 | // FIXME: set Declaration for decls |
216 | LIFETIME => HighlightTag::Lifetime.into(), | ||
215 | 217 | ||
216 | k if k.is_keyword() => { | 218 | k if k.is_keyword() => { |
217 | let h = Highlight::new(HighlightTag::Keyword); | 219 | let h = Highlight::new(HighlightTag::Keyword); |
@@ -255,20 +257,21 @@ fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight { | |||
255 | NameDefinition::ModuleDef(def) => match def { | 257 | NameDefinition::ModuleDef(def) => match def { |
256 | hir::ModuleDef::Module(_) => HighlightTag::Module, | 258 | hir::ModuleDef::Module(_) => HighlightTag::Module, |
257 | hir::ModuleDef::Function(_) => HighlightTag::Function, | 259 | hir::ModuleDef::Function(_) => HighlightTag::Function, |
258 | hir::ModuleDef::Adt(_) => HighlightTag::Type, | 260 | hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, |
259 | hir::ModuleDef::EnumVariant(_) => HighlightTag::Constant, | 261 | hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum, |
262 | hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, | ||
263 | hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, | ||
260 | hir::ModuleDef::Const(_) => HighlightTag::Constant, | 264 | hir::ModuleDef::Const(_) => HighlightTag::Constant, |
261 | hir::ModuleDef::Static(_) => HighlightTag::Constant, | 265 | hir::ModuleDef::Static(_) => HighlightTag::Static, |
262 | hir::ModuleDef::Trait(_) => HighlightTag::Type, | 266 | hir::ModuleDef::Trait(_) => HighlightTag::Trait, |
263 | hir::ModuleDef::TypeAlias(_) => HighlightTag::Type, | 267 | hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, |
264 | hir::ModuleDef::BuiltinType(_) => { | 268 | hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, |
265 | return HighlightTag::Type | HighlightModifier::Builtin | ||
266 | } | ||
267 | }, | 269 | }, |
268 | NameDefinition::SelfType(_) => HighlightTag::TypeSelf, | 270 | NameDefinition::SelfType(_) => HighlightTag::SelfType, |
269 | NameDefinition::TypeParam(_) => HighlightTag::TypeParam, | 271 | NameDefinition::TypeParam(_) => HighlightTag::TypeParam, |
272 | // FIXME: distinguish between locals and parameters | ||
270 | NameDefinition::Local(local) => { | 273 | NameDefinition::Local(local) => { |
271 | let mut h = Highlight::new(HighlightTag::Variable); | 274 | let mut h = Highlight::new(HighlightTag::Local); |
272 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { | 275 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { |
273 | h |= HighlightModifier::Mutable; | 276 | h |= HighlightModifier::Mutable; |
274 | } | 277 | } |
@@ -287,7 +290,11 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { | |||
287 | }; | 290 | }; |
288 | 291 | ||
289 | match parent.kind() { | 292 | match parent.kind() { |
290 | STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => HighlightTag::Type.into(), | 293 | STRUCT_DEF => HighlightTag::Struct.into(), |
294 | ENUM_DEF => HighlightTag::Enum.into(), | ||
295 | UNION_KW => HighlightTag::Union.into(), | ||
296 | TRAIT_DEF => HighlightTag::Trait.into(), | ||
297 | TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(), | ||
291 | TYPE_PARAM => HighlightTag::TypeParam.into(), | 298 | TYPE_PARAM => HighlightTag::TypeParam.into(), |
292 | RECORD_FIELD_DEF => HighlightTag::Field.into(), | 299 | RECORD_FIELD_DEF => HighlightTag::Field.into(), |
293 | _ => default, | 300 | _ => default, |
@@ -312,7 +319,7 @@ fn highlight_injection( | |||
312 | if let Some(range) = literal.open_quote_text_range() { | 319 | if let Some(range) = literal.open_quote_text_range() { |
313 | acc.push(HighlightedRange { | 320 | acc.push(HighlightedRange { |
314 | range, | 321 | range, |
315 | highlight: HighlightTag::LiteralString.into(), | 322 | highlight: HighlightTag::StringLiteral.into(), |
316 | binding_hash: None, | 323 | binding_hash: None, |
317 | }) | 324 | }) |
318 | } | 325 | } |
@@ -327,7 +334,7 @@ fn highlight_injection( | |||
327 | if let Some(range) = literal.close_quote_text_range() { | 334 | if let Some(range) = literal.close_quote_text_range() { |
328 | acc.push(HighlightedRange { | 335 | acc.push(HighlightedRange { |
329 | range, | 336 | range, |
330 | highlight: HighlightTag::LiteralString.into(), | 337 | highlight: HighlightTag::StringLiteral.into(), |
331 | binding_hash: None, | 338 | binding_hash: None, |
332 | }) | 339 | }) |
333 | } | 340 | } |