aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-01-09 11:44:01 +0000
committerAleksey Kladov <[email protected]>2021-01-09 11:44:01 +0000
commit64a6ee45351a71cdeb1d1dddc8fc746abdcff07b (patch)
tree1bcbd575286076950bf71719f8944e2d4322f939 /crates/ide
parent6fb52af521ab8ca2fdd3ea7cfa95eaebd0cba1fc (diff)
Shorten frequent names
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/lib.rs2
-rw-r--r--crates/ide/src/syntax_highlighting.rs239
-rw-r--r--crates/ide/src/syntax_highlighting/format.rs10
-rw-r--r--crates/ide/src/syntax_highlighting/highlights.rs4
-rw-r--r--crates/ide/src/syntax_highlighting/injection.rs10
-rw-r--r--crates/ide/src/syntax_highlighting/macro_rules.rs4
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs134
7 files changed, 192 insertions, 211 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index cea2a13c8..674c72c23 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -76,7 +76,7 @@ pub use crate::{
76 references::{rename::RenameError, Declaration, ReferenceSearchResult}, 76 references::{rename::RenameError, Declaration, ReferenceSearchResult},
77 runnables::{Runnable, RunnableKind, TestId}, 77 runnables::{Runnable, RunnableKind, TestId},
78 syntax_highlighting::{ 78 syntax_highlighting::{
79 tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}, 79 tags::{Highlight, HlMod, HlMods, HlTag},
80 HighlightedRange, 80 HighlightedRange,
81 }, 81 },
82}; 82};
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 2eb63a0b7..d73ddf35b 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -26,7 +26,7 @@ use crate::{
26 syntax_highlighting::{ 26 syntax_highlighting::{
27 format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter, tags::Highlight, 27 format::FormatStringHighlighter, macro_rules::MacroRulesHighlighter, tags::Highlight,
28 }, 28 },
29 FileId, HighlightModifier, HighlightTag, SymbolKind, 29 FileId, HlMod, HlTag, SymbolKind,
30}; 30};
31 31
32pub(crate) use html::highlight_as_html; 32pub(crate) use html::highlight_as_html;
@@ -98,7 +98,7 @@ pub(crate) fn highlight(
98 if let Some(range) = macro_call_range(&mc) { 98 if let Some(range) = macro_call_range(&mc) {
99 stack.add(HighlightedRange { 99 stack.add(HighlightedRange {
100 range, 100 range,
101 highlight: HighlightTag::Symbol(SymbolKind::Macro).into(), 101 highlight: HlTag::Symbol(SymbolKind::Macro).into(),
102 binding_hash: None, 102 binding_hash: None,
103 }); 103 });
104 } 104 }
@@ -192,7 +192,7 @@ pub(crate) fn highlight(
192 element_to_highlight.clone(), 192 element_to_highlight.clone(),
193 ) { 193 ) {
194 if inside_attribute { 194 if inside_attribute {
195 highlight = highlight | HighlightModifier::Attribute; 195 highlight = highlight | HlMod::Attribute;
196 } 196 }
197 197
198 if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() { 198 if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() {
@@ -209,7 +209,7 @@ pub(crate) fn highlight(
209 if string.text()[piece_range.start().into()..].starts_with('\\') { 209 if string.text()[piece_range.start().into()..].starts_with('\\') {
210 stack.add(HighlightedRange { 210 stack.add(HighlightedRange {
211 range: piece_range + range.start(), 211 range: piece_range + range.start(),
212 highlight: HighlightTag::EscapeSequence.into(), 212 highlight: HlTag::EscapeSequence.into(),
213 binding_hash: None, 213 binding_hash: None,
214 }); 214 });
215 } 215 }
@@ -292,22 +292,20 @@ fn highlight_element(
292 }; 292 };
293 293
294 match name_kind { 294 match name_kind {
295 Some(NameClass::ExternCrate(_)) => HighlightTag::Symbol(SymbolKind::Module).into(), 295 Some(NameClass::ExternCrate(_)) => HlTag::Symbol(SymbolKind::Module).into(),
296 Some(NameClass::Definition(def)) => { 296 Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition,
297 highlight_def(db, def) | HighlightModifier::Definition
298 }
299 Some(NameClass::ConstReference(def)) => highlight_def(db, def), 297 Some(NameClass::ConstReference(def)) => highlight_def(db, def),
300 Some(NameClass::PatFieldShorthand { field_ref, .. }) => { 298 Some(NameClass::PatFieldShorthand { field_ref, .. }) => {
301 let mut h = HighlightTag::Symbol(SymbolKind::Field).into(); 299 let mut h = HlTag::Symbol(SymbolKind::Field).into();
302 if let Definition::Field(field) = field_ref { 300 if let Definition::Field(field) = field_ref {
303 if let VariantDef::Union(_) = field.parent_def(db) { 301 if let VariantDef::Union(_) = field.parent_def(db) {
304 h |= HighlightModifier::Unsafe; 302 h |= HlMod::Unsafe;
305 } 303 }
306 } 304 }
307 305
308 h 306 h
309 } 307 }
310 None => highlight_name_by_syntax(name) | HighlightModifier::Definition, 308 None => highlight_name_by_syntax(name) | HlMod::Definition,
311 } 309 }
312 } 310 }
313 311
@@ -315,16 +313,14 @@ fn highlight_element(
315 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => { 313 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => {
316 // even though we track whether we are in an attribute or not we still need this special case 314 // even though we track whether we are in an attribute or not we still need this special case
317 // as otherwise we would emit unresolved references for name refs inside attributes 315 // as otherwise we would emit unresolved references for name refs inside attributes
318 Highlight::from(HighlightTag::Symbol(SymbolKind::Function)) 316 Highlight::from(HlTag::Symbol(SymbolKind::Function))
319 } 317 }
320 NAME_REF => { 318 NAME_REF => {
321 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); 319 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
322 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| { 320 highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| {
323 match NameRefClass::classify(sema, &name_ref) { 321 match NameRefClass::classify(sema, &name_ref) {
324 Some(name_kind) => match name_kind { 322 Some(name_kind) => match name_kind {
325 NameRefClass::ExternCrate(_) => { 323 NameRefClass::ExternCrate(_) => HlTag::Symbol(SymbolKind::Module).into(),
326 HighlightTag::Symbol(SymbolKind::Module).into()
327 }
328 NameRefClass::Definition(def) => { 324 NameRefClass::Definition(def) => {
329 if let Definition::Local(local) = &def { 325 if let Definition::Local(local) = &def {
330 if let Some(name) = local.name(db) { 326 if let Some(name) = local.name(db) {
@@ -338,7 +334,7 @@ fn highlight_element(
338 334
339 if let Definition::Local(local) = &def { 335 if let Definition::Local(local) = &def {
340 if is_consumed_lvalue(name_ref.syntax().clone().into(), local, db) { 336 if is_consumed_lvalue(name_ref.syntax().clone().into(), local, db) {
341 h |= HighlightModifier::Consuming; 337 h |= HlMod::Consuming;
342 } 338 }
343 } 339 }
344 340
@@ -346,7 +342,7 @@ fn highlight_element(
346 if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { 342 if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) {
347 if let Definition::Field(field) = def { 343 if let Definition::Field(field) = def {
348 if let VariantDef::Union(_) = field.parent_def(db) { 344 if let VariantDef::Union(_) = field.parent_def(db) {
349 h |= HighlightModifier::Unsafe; 345 h |= HlMod::Unsafe;
350 } 346 }
351 } 347 }
352 } 348 }
@@ -355,13 +351,13 @@ fn highlight_element(
355 h 351 h
356 } 352 }
357 NameRefClass::FieldShorthand { .. } => { 353 NameRefClass::FieldShorthand { .. } => {
358 HighlightTag::Symbol(SymbolKind::Field).into() 354 HlTag::Symbol(SymbolKind::Field).into()
359 } 355 }
360 }, 356 },
361 None if syntactic_name_ref_highlighting => { 357 None if syntactic_name_ref_highlighting => {
362 highlight_name_ref_by_syntax(name_ref, sema) 358 highlight_name_ref_by_syntax(name_ref, sema)
363 } 359 }
364 None => HighlightTag::UnresolvedReference.into(), 360 None => HlTag::UnresolvedReference.into(),
365 } 361 }
366 }) 362 })
367 } 363 }
@@ -369,60 +365,53 @@ fn highlight_element(
369 // Simple token-based highlighting 365 // Simple token-based highlighting
370 COMMENT => { 366 COMMENT => {
371 let comment = element.into_token().and_then(ast::Comment::cast)?; 367 let comment = element.into_token().and_then(ast::Comment::cast)?;
372 let h = HighlightTag::Comment; 368 let h = HlTag::Comment;
373 match comment.kind().doc { 369 match comment.kind().doc {
374 Some(_) => h | HighlightModifier::Documentation, 370 Some(_) => h | HlMod::Documentation,
375 None => h.into(), 371 None => h.into(),
376 } 372 }
377 } 373 }
378 STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), 374 STRING | BYTE_STRING => HlTag::StringLiteral.into(),
379 ATTR => HighlightTag::Attribute.into(), 375 ATTR => HlTag::Attribute.into(),
380 INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), 376 INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(),
381 BYTE => HighlightTag::ByteLiteral.into(), 377 BYTE => HlTag::ByteLiteral.into(),
382 CHAR => HighlightTag::CharLiteral.into(), 378 CHAR => HlTag::CharLiteral.into(),
383 QUESTION => Highlight::new(HighlightTag::Operator) | HighlightModifier::ControlFlow, 379 QUESTION => Highlight::new(HlTag::Operator) | HlMod::ControlFlow,
384 LIFETIME => { 380 LIFETIME => {
385 let lifetime = element.into_node().and_then(ast::Lifetime::cast).unwrap(); 381 let lifetime = element.into_node().and_then(ast::Lifetime::cast).unwrap();
386 382
387 match NameClass::classify_lifetime(sema, &lifetime) { 383 match NameClass::classify_lifetime(sema, &lifetime) {
388 Some(NameClass::Definition(def)) => { 384 Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition,
389 highlight_def(db, def) | HighlightModifier::Definition
390 }
391 None => match NameRefClass::classify_lifetime(sema, &lifetime) { 385 None => match NameRefClass::classify_lifetime(sema, &lifetime) {
392 Some(NameRefClass::Definition(def)) => highlight_def(db, def), 386 Some(NameRefClass::Definition(def)) => highlight_def(db, def),
393 _ => Highlight::new(HighlightTag::Symbol(SymbolKind::LifetimeParam)), 387 _ => Highlight::new(HlTag::Symbol(SymbolKind::LifetimeParam)),
394 }, 388 },
395 _ => { 389 _ => Highlight::new(HlTag::Symbol(SymbolKind::LifetimeParam)) | HlMod::Definition,
396 Highlight::new(HighlightTag::Symbol(SymbolKind::LifetimeParam))
397 | HighlightModifier::Definition
398 }
399 } 390 }
400 } 391 }
401 p if p.is_punct() => match p { 392 p if p.is_punct() => match p {
402 T![&] => { 393 T![&] => {
403 let h = HighlightTag::Operator.into(); 394 let h = HlTag::Operator.into();
404 let is_unsafe = element 395 let is_unsafe = element
405 .parent() 396 .parent()
406 .and_then(ast::RefExpr::cast) 397 .and_then(ast::RefExpr::cast)
407 .map(|ref_expr| sema.is_unsafe_ref_expr(&ref_expr)) 398 .map(|ref_expr| sema.is_unsafe_ref_expr(&ref_expr))
408 .unwrap_or(false); 399 .unwrap_or(false);
409 if is_unsafe { 400 if is_unsafe {
410 h | HighlightModifier::Unsafe 401 h | HlMod::Unsafe
411 } else { 402 } else {
412 h 403 h
413 } 404 }
414 } 405 }
415 T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.] => { 406 T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.] => HlTag::Operator.into(),
416 HighlightTag::Operator.into()
417 }
418 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { 407 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
419 HighlightTag::Symbol(SymbolKind::Macro).into() 408 HlTag::Symbol(SymbolKind::Macro).into()
420 } 409 }
421 T![!] if element.parent().and_then(ast::NeverType::cast).is_some() => { 410 T![!] if element.parent().and_then(ast::NeverType::cast).is_some() => {
422 HighlightTag::BuiltinType.into() 411 HlTag::BuiltinType.into()
423 } 412 }
424 T![*] if element.parent().and_then(ast::PtrType::cast).is_some() => { 413 T![*] if element.parent().and_then(ast::PtrType::cast).is_some() => {
425 HighlightTag::Keyword.into() 414 HlTag::Keyword.into()
426 } 415 }
427 T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 416 T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
428 let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; 417 let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
@@ -430,11 +419,11 @@ fn highlight_element(
430 let expr = prefix_expr.expr()?; 419 let expr = prefix_expr.expr()?;
431 let ty = sema.type_of_expr(&expr)?; 420 let ty = sema.type_of_expr(&expr)?;
432 if ty.is_raw_ptr() { 421 if ty.is_raw_ptr() {
433 HighlightTag::Operator | HighlightModifier::Unsafe 422 HlTag::Operator | HlMod::Unsafe
434 } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { 423 } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() {
435 HighlightTag::Operator.into() 424 HlTag::Operator.into()
436 } else { 425 } else {
437 HighlightTag::Punctuation.into() 426 HlTag::Punctuation.into()
438 } 427 }
439 } 428 }
440 T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 429 T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
@@ -442,34 +431,26 @@ fn highlight_element(
442 431
443 let expr = prefix_expr.expr()?; 432 let expr = prefix_expr.expr()?;
444 match expr { 433 match expr {
445 ast::Expr::Literal(_) => HighlightTag::NumericLiteral, 434 ast::Expr::Literal(_) => HlTag::NumericLiteral,
446 _ => HighlightTag::Operator, 435 _ => HlTag::Operator,
447 } 436 }
448 .into() 437 .into()
449 } 438 }
450 _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 439 _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
451 HighlightTag::Operator.into() 440 HlTag::Operator.into()
452 }
453 _ if element.parent().and_then(ast::BinExpr::cast).is_some() => {
454 HighlightTag::Operator.into()
455 } 441 }
442 _ if element.parent().and_then(ast::BinExpr::cast).is_some() => HlTag::Operator.into(),
456 _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { 443 _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => {
457 HighlightTag::Operator.into() 444 HlTag::Operator.into()
458 }
459 _ if element.parent().and_then(ast::RangePat::cast).is_some() => {
460 HighlightTag::Operator.into()
461 }
462 _ if element.parent().and_then(ast::RestPat::cast).is_some() => {
463 HighlightTag::Operator.into()
464 }
465 _ if element.parent().and_then(ast::Attr::cast).is_some() => {
466 HighlightTag::Attribute.into()
467 } 445 }
468 _ => HighlightTag::Punctuation.into(), 446 _ if element.parent().and_then(ast::RangePat::cast).is_some() => HlTag::Operator.into(),
447 _ if element.parent().and_then(ast::RestPat::cast).is_some() => HlTag::Operator.into(),
448 _ if element.parent().and_then(ast::Attr::cast).is_some() => HlTag::Attribute.into(),
449 _ => HlTag::Punctuation.into(),
469 }, 450 },
470 451
471 k if k.is_keyword() => { 452 k if k.is_keyword() => {
472 let h = Highlight::new(HighlightTag::Keyword); 453 let h = Highlight::new(HlTag::Keyword);
473 match k { 454 match k {
474 T![break] 455 T![break]
475 | T![continue] 456 | T![continue]
@@ -479,10 +460,10 @@ fn highlight_element(
479 | T![match] 460 | T![match]
480 | T![return] 461 | T![return]
481 | T![while] 462 | T![while]
482 | T![in] => h | HighlightModifier::ControlFlow, 463 | T![in] => h | HlMod::ControlFlow,
483 T![for] if !is_child_of_impl(&element) => h | HighlightModifier::ControlFlow, 464 T![for] if !is_child_of_impl(&element) => h | HlMod::ControlFlow,
484 T![unsafe] => h | HighlightModifier::Unsafe, 465 T![unsafe] => h | HlMod::Unsafe,
485 T![true] | T![false] => HighlightTag::BoolLiteral.into(), 466 T![true] | T![false] => HlTag::BoolLiteral.into(),
486 T![self] => { 467 T![self] => {
487 let self_param_is_mut = element 468 let self_param_is_mut = element
488 .parent() 469 .parent()
@@ -495,7 +476,7 @@ fn highlight_element(
495 .and_then(SyntaxNode::parent) 476 .and_then(SyntaxNode::parent)
496 .and_then(ast::Path::cast) 477 .and_then(ast::Path::cast)
497 .and_then(|p| sema.resolve_path(&p)); 478 .and_then(|p| sema.resolve_path(&p));
498 let mut h = HighlightTag::Symbol(SymbolKind::SelfParam).into(); 479 let mut h = HlTag::Symbol(SymbolKind::SelfParam).into();
499 if self_param_is_mut 480 if self_param_is_mut
500 || matches!(self_path, 481 || matches!(self_path,
501 Some(hir::PathResolution::Local(local)) 482 Some(hir::PathResolution::Local(local))
@@ -503,12 +484,12 @@ fn highlight_element(
503 && (local.is_mut(db) || local.ty(db).is_mutable_reference()) 484 && (local.is_mut(db) || local.ty(db).is_mutable_reference())
504 ) 485 )
505 { 486 {
506 h |= HighlightModifier::Mutable 487 h |= HlMod::Mutable
507 } 488 }
508 489
509 if let Some(hir::PathResolution::Local(local)) = self_path { 490 if let Some(hir::PathResolution::Local(local)) = self_path {
510 if is_consumed_lvalue(element, &local, db) { 491 if is_consumed_lvalue(element, &local, db) {
511 h |= HighlightModifier::Consuming; 492 h |= HlMod::Consuming;
512 } 493 }
513 } 494 }
514 495
@@ -519,7 +500,7 @@ fn highlight_element(
519 .and_then(ast::IdentPat::cast) 500 .and_then(ast::IdentPat::cast)
520 .and_then(|ident_pat| { 501 .and_then(|ident_pat| {
521 if sema.is_unsafe_ident_pat(&ident_pat) { 502 if sema.is_unsafe_ident_pat(&ident_pat) {
522 Some(HighlightModifier::Unsafe) 503 Some(HlMod::Unsafe)
523 } else { 504 } else {
524 None 505 None
525 } 506 }
@@ -568,21 +549,21 @@ fn highlight_method_call(
568 method_call: &ast::MethodCallExpr, 549 method_call: &ast::MethodCallExpr,
569) -> Option<Highlight> { 550) -> Option<Highlight> {
570 let func = sema.resolve_method_call(&method_call)?; 551 let func = sema.resolve_method_call(&method_call)?;
571 let mut h = HighlightTag::Symbol(SymbolKind::Function).into(); 552 let mut h = HlTag::Symbol(SymbolKind::Function).into();
572 h |= HighlightModifier::Associated; 553 h |= HlMod::Associated;
573 if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) { 554 if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) {
574 h |= HighlightModifier::Unsafe; 555 h |= HlMod::Unsafe;
575 } 556 }
576 if let Some(self_param) = func.self_param(sema.db) { 557 if let Some(self_param) = func.self_param(sema.db) {
577 match self_param.access(sema.db) { 558 match self_param.access(sema.db) {
578 hir::Access::Shared => (), 559 hir::Access::Shared => (),
579 hir::Access::Exclusive => h |= HighlightModifier::Mutable, 560 hir::Access::Exclusive => h |= HlMod::Mutable,
580 hir::Access::Owned => { 561 hir::Access::Owned => {
581 if let Some(receiver_ty) = 562 if let Some(receiver_ty) =
582 method_call.receiver().and_then(|it| sema.type_of_expr(&it)) 563 method_call.receiver().and_then(|it| sema.type_of_expr(&it))
583 { 564 {
584 if !receiver_ty.is_copy(sema.db) { 565 if !receiver_ty.is_copy(sema.db) {
585 h |= HighlightModifier::Consuming 566 h |= HlMod::Consuming
586 } 567 }
587 } 568 }
588 } 569 }
@@ -593,78 +574,78 @@ fn highlight_method_call(
593 574
594fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { 575fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
595 match def { 576 match def {
596 Definition::Macro(_) => HighlightTag::Symbol(SymbolKind::Macro), 577 Definition::Macro(_) => HlTag::Symbol(SymbolKind::Macro),
597 Definition::Field(_) => HighlightTag::Symbol(SymbolKind::Field), 578 Definition::Field(_) => HlTag::Symbol(SymbolKind::Field),
598 Definition::ModuleDef(def) => match def { 579 Definition::ModuleDef(def) => match def {
599 hir::ModuleDef::Module(_) => HighlightTag::Symbol(SymbolKind::Module), 580 hir::ModuleDef::Module(_) => HlTag::Symbol(SymbolKind::Module),
600 hir::ModuleDef::Function(func) => { 581 hir::ModuleDef::Function(func) => {
601 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Function)); 582 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function));
602 if func.as_assoc_item(db).is_some() { 583 if func.as_assoc_item(db).is_some() {
603 h |= HighlightModifier::Associated; 584 h |= HlMod::Associated;
604 if func.self_param(db).is_none() { 585 if func.self_param(db).is_none() {
605 h |= HighlightModifier::Static 586 h |= HlMod::Static
606 } 587 }
607 } 588 }
608 if func.is_unsafe(db) { 589 if func.is_unsafe(db) {
609 h |= HighlightModifier::Unsafe; 590 h |= HlMod::Unsafe;
610 } 591 }
611 return h; 592 return h;
612 } 593 }
613 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Symbol(SymbolKind::Struct), 594 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HlTag::Symbol(SymbolKind::Struct),
614 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum), 595 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HlTag::Symbol(SymbolKind::Enum),
615 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union), 596 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HlTag::Symbol(SymbolKind::Union),
616 hir::ModuleDef::Variant(_) => HighlightTag::Symbol(SymbolKind::Variant), 597 hir::ModuleDef::Variant(_) => HlTag::Symbol(SymbolKind::Variant),
617 hir::ModuleDef::Const(konst) => { 598 hir::ModuleDef::Const(konst) => {
618 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Const)); 599 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Const));
619 if konst.as_assoc_item(db).is_some() { 600 if konst.as_assoc_item(db).is_some() {
620 h |= HighlightModifier::Associated 601 h |= HlMod::Associated
621 } 602 }
622 return h; 603 return h;
623 } 604 }
624 hir::ModuleDef::Trait(_) => HighlightTag::Symbol(SymbolKind::Trait), 605 hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait),
625 hir::ModuleDef::TypeAlias(type_) => { 606 hir::ModuleDef::TypeAlias(type_) => {
626 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::TypeAlias)); 607 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias));
627 if type_.as_assoc_item(db).is_some() { 608 if type_.as_assoc_item(db).is_some() {
628 h |= HighlightModifier::Associated 609 h |= HlMod::Associated
629 } 610 }
630 return h; 611 return h;
631 } 612 }
632 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, 613 hir::ModuleDef::BuiltinType(_) => HlTag::BuiltinType,
633 hir::ModuleDef::Static(s) => { 614 hir::ModuleDef::Static(s) => {
634 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Static)); 615 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Static));
635 if s.is_mut(db) { 616 if s.is_mut(db) {
636 h |= HighlightModifier::Mutable; 617 h |= HlMod::Mutable;
637 h |= HighlightModifier::Unsafe; 618 h |= HlMod::Unsafe;
638 } 619 }
639 return h; 620 return h;
640 } 621 }
641 }, 622 },
642 Definition::SelfType(_) => HighlightTag::Symbol(SymbolKind::Impl), 623 Definition::SelfType(_) => HlTag::Symbol(SymbolKind::Impl),
643 Definition::TypeParam(_) => HighlightTag::Symbol(SymbolKind::TypeParam), 624 Definition::TypeParam(_) => HlTag::Symbol(SymbolKind::TypeParam),
644 Definition::ConstParam(_) => HighlightTag::Symbol(SymbolKind::ConstParam), 625 Definition::ConstParam(_) => HlTag::Symbol(SymbolKind::ConstParam),
645 Definition::Local(local) => { 626 Definition::Local(local) => {
646 let tag = if local.is_param(db) { 627 let tag = if local.is_param(db) {
647 HighlightTag::Symbol(SymbolKind::ValueParam) 628 HlTag::Symbol(SymbolKind::ValueParam)
648 } else { 629 } else {
649 HighlightTag::Symbol(SymbolKind::Local) 630 HlTag::Symbol(SymbolKind::Local)
650 }; 631 };
651 let mut h = Highlight::new(tag); 632 let mut h = Highlight::new(tag);
652 if local.is_mut(db) || local.ty(db).is_mutable_reference() { 633 if local.is_mut(db) || local.ty(db).is_mutable_reference() {
653 h |= HighlightModifier::Mutable; 634 h |= HlMod::Mutable;
654 } 635 }
655 if local.ty(db).as_callable(db).is_some() || local.ty(db).impls_fnonce(db) { 636 if local.ty(db).as_callable(db).is_some() || local.ty(db).impls_fnonce(db) {
656 h |= HighlightModifier::Callable; 637 h |= HlMod::Callable;
657 } 638 }
658 return h; 639 return h;
659 } 640 }
660 Definition::LifetimeParam(_) => HighlightTag::Symbol(SymbolKind::LifetimeParam), 641 Definition::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam),
661 Definition::Label(_) => HighlightTag::Symbol(SymbolKind::Label), 642 Definition::Label(_) => HlTag::Symbol(SymbolKind::Label),
662 } 643 }
663 .into() 644 .into()
664} 645}
665 646
666fn highlight_name_by_syntax(name: ast::Name) -> Highlight { 647fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
667 let default = HighlightTag::UnresolvedReference; 648 let default = HlTag::UnresolvedReference;
668 649
669 let parent = match name.syntax().parent() { 650 let parent = match name.syntax().parent() {
670 Some(it) => it, 651 Some(it) => it,
@@ -672,19 +653,19 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
672 }; 653 };
673 654
674 let tag = match parent.kind() { 655 let tag = match parent.kind() {
675 STRUCT => HighlightTag::Symbol(SymbolKind::Struct), 656 STRUCT => HlTag::Symbol(SymbolKind::Struct),
676 ENUM => HighlightTag::Symbol(SymbolKind::Enum), 657 ENUM => HlTag::Symbol(SymbolKind::Enum),
677 VARIANT => HighlightTag::Symbol(SymbolKind::Variant), 658 VARIANT => HlTag::Symbol(SymbolKind::Variant),
678 UNION => HighlightTag::Symbol(SymbolKind::Union), 659 UNION => HlTag::Symbol(SymbolKind::Union),
679 TRAIT => HighlightTag::Symbol(SymbolKind::Trait), 660 TRAIT => HlTag::Symbol(SymbolKind::Trait),
680 TYPE_ALIAS => HighlightTag::Symbol(SymbolKind::TypeAlias), 661 TYPE_ALIAS => HlTag::Symbol(SymbolKind::TypeAlias),
681 TYPE_PARAM => HighlightTag::Symbol(SymbolKind::TypeParam), 662 TYPE_PARAM => HlTag::Symbol(SymbolKind::TypeParam),
682 RECORD_FIELD => HighlightTag::Symbol(SymbolKind::Field), 663 RECORD_FIELD => HlTag::Symbol(SymbolKind::Field),
683 MODULE => HighlightTag::Symbol(SymbolKind::Module), 664 MODULE => HlTag::Symbol(SymbolKind::Module),
684 FN => HighlightTag::Symbol(SymbolKind::Function), 665 FN => HlTag::Symbol(SymbolKind::Function),
685 CONST => HighlightTag::Symbol(SymbolKind::Const), 666 CONST => HlTag::Symbol(SymbolKind::Const),
686 STATIC => HighlightTag::Symbol(SymbolKind::Static), 667 STATIC => HlTag::Symbol(SymbolKind::Static),
687 IDENT_PAT => HighlightTag::Symbol(SymbolKind::Local), 668 IDENT_PAT => HlTag::Symbol(SymbolKind::Local),
688 _ => default, 669 _ => default,
689 }; 670 };
690 671
@@ -692,7 +673,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
692} 673}
693 674
694fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabase>) -> Highlight { 675fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabase>) -> Highlight {
695 let default = HighlightTag::UnresolvedReference; 676 let default = HlTag::UnresolvedReference;
696 677
697 let parent = match name.syntax().parent() { 678 let parent = match name.syntax().parent() {
698 Some(it) => it, 679 Some(it) => it,
@@ -703,10 +684,10 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
703 METHOD_CALL_EXPR => { 684 METHOD_CALL_EXPR => {
704 return ast::MethodCallExpr::cast(parent) 685 return ast::MethodCallExpr::cast(parent)
705 .and_then(|method_call| highlight_method_call(sema, &method_call)) 686 .and_then(|method_call| highlight_method_call(sema, &method_call))
706 .unwrap_or_else(|| HighlightTag::Symbol(SymbolKind::Function).into()); 687 .unwrap_or_else(|| HlTag::Symbol(SymbolKind::Function).into());
707 } 688 }
708 FIELD_EXPR => { 689 FIELD_EXPR => {
709 let h = HighlightTag::Symbol(SymbolKind::Field); 690 let h = HlTag::Symbol(SymbolKind::Field);
710 let is_union = ast::FieldExpr::cast(parent) 691 let is_union = ast::FieldExpr::cast(parent)
711 .and_then(|field_expr| { 692 .and_then(|field_expr| {
712 let field = sema.resolve_field(&field_expr)?; 693 let field = sema.resolve_field(&field_expr)?;
@@ -718,7 +699,7 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
718 }) 699 })
719 .unwrap_or(false); 700 .unwrap_or(false);
720 if is_union { 701 if is_union {
721 h | HighlightModifier::Unsafe 702 h | HlMod::Unsafe
722 } else { 703 } else {
723 h.into() 704 h.into()
724 } 705 }
@@ -733,9 +714,9 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
733 _ => { 714 _ => {
734 // within path, decide whether it is module or adt by checking for uppercase name 715 // within path, decide whether it is module or adt by checking for uppercase name
735 return if name.text().chars().next().unwrap_or_default().is_uppercase() { 716 return if name.text().chars().next().unwrap_or_default().is_uppercase() {
736 HighlightTag::Symbol(SymbolKind::Struct) 717 HlTag::Symbol(SymbolKind::Struct)
737 } else { 718 } else {
738 HighlightTag::Symbol(SymbolKind::Module) 719 HlTag::Symbol(SymbolKind::Module)
739 } 720 }
740 .into(); 721 .into();
741 } 722 }
@@ -746,11 +727,11 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas
746 }; 727 };
747 728
748 match parent.kind() { 729 match parent.kind() {
749 CALL_EXPR => HighlightTag::Symbol(SymbolKind::Function).into(), 730 CALL_EXPR => HlTag::Symbol(SymbolKind::Function).into(),
750 _ => if name.text().chars().next().unwrap_or_default().is_uppercase() { 731 _ => if name.text().chars().next().unwrap_or_default().is_uppercase() {
751 HighlightTag::Symbol(SymbolKind::Struct) 732 HlTag::Symbol(SymbolKind::Struct)
752 } else { 733 } else {
753 HighlightTag::Symbol(SymbolKind::Const) 734 HlTag::Symbol(SymbolKind::Const)
754 } 735 }
755 .into(), 736 .into(),
756 } 737 }
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
7use crate::{HighlightTag, HighlightedRange, SymbolKind}; 7use crate::{HighlightedRange, HlTag, SymbolKind};
8 8
9use super::highlights::Highlights; 9use super::highlights::Highlights;
10 10
@@ -57,7 +57,7 @@ impl FormatStringHighlighter {
57 } 57 }
58} 58}
59 59
60fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> { 60fn 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};
4use stdx::equal_range_by; 4use stdx::equal_range_by;
5use syntax::TextRange; 5use syntax::TextRange;
6 6
7use crate::{HighlightTag, HighlightedRange}; 7use crate::{HighlightedRange, HlTag};
8 8
9pub(super) struct Highlights { 9pub(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;
7use itertools::Itertools; 7use itertools::Itertools;
8use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; 8use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize};
9 9
10use crate::{Analysis, HighlightModifier, HighlightTag, HighlightedRange, RootDatabase}; 10use crate::{Analysis, HighlightedRange, HlMod, HlTag, RootDatabase};
11 11
12use super::{highlights::Highlights, injector::Injector}; 12use 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!.
2use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; 2use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T};
3 3
4use crate::{HighlightTag, HighlightedRange}; 4use crate::{HighlightedRange, HlTag};
5 5
6#[derive(Default)] 6#[derive(Default)]
7pub(super) struct MacroRulesHighlighter { 7pub(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)]
9pub struct Highlight { 9pub 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)]
15pub struct HighlightModifiers(u32); 15pub 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)]
18pub enum HighlightTag { 18pub 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)]
42pub enum HighlightModifier { 42pub 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
64impl HighlightTag { 64impl 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
108impl fmt::Display for HighlightTag { 108impl 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
114impl HighlightModifier { 114impl 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
150impl fmt::Display for HighlightModifier { 150impl 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 {
156impl fmt::Display for Highlight { 156impl 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
166impl From<HighlightTag> for Highlight { 166impl 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
172impl Highlight { 172impl 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
181impl ops::BitOr<HighlightModifier> for HighlightTag { 181impl 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
189impl ops::BitOrAssign<HighlightModifier> for HighlightModifiers { 189impl 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
195impl ops::BitOrAssign<HighlightModifier> for Highlight { 195impl 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
201impl ops::BitOr<HighlightModifier> for Highlight { 201impl 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
210impl HighlightModifiers { 210impl 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}