aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/syntax_highlighting.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-12-19 14:10:47 +0000
committerAleksey Kladov <[email protected]>2020-12-19 14:10:47 +0000
commita13947abe62a44c4ffa802be54e041a3d18e7f2b (patch)
tree7675fa96ea2df477f30d7e6acb060ed379b86ef1 /crates/ide/src/syntax_highlighting.rs
parentbd270cbc024f56596c315061d10732ebbe16eef9 (diff)
Use more Rustic highlighting specifiers
*Method* works for OO languages, but in rust we can also have associated constants & types, so let's move this to a modifier.
Diffstat (limited to 'crates/ide/src/syntax_highlighting.rs')
-rw-r--r--crates/ide/src/syntax_highlighting.rs31
1 files changed, 21 insertions, 10 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 7f98aa316..67ad7c63d 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -736,7 +736,8 @@ fn highlight_method_call(
736 method_call: &ast::MethodCallExpr, 736 method_call: &ast::MethodCallExpr,
737) -> Option<Highlight> { 737) -> Option<Highlight> {
738 let func = sema.resolve_method_call(&method_call)?; 738 let func = sema.resolve_method_call(&method_call)?;
739 let mut h = HighlightTag::Method.into(); 739 let mut h = HighlightTag::Symbol(SymbolKind::Function).into();
740 h |= HighlightModifier::Associated;
740 if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) { 741 if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) {
741 h |= HighlightModifier::Unsafe; 742 h |= HighlightModifier::Unsafe;
742 } 743 }
@@ -765,15 +766,13 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
765 Definition::ModuleDef(def) => match def { 766 Definition::ModuleDef(def) => match def {
766 hir::ModuleDef::Module(_) => HighlightTag::Symbol(SymbolKind::Module), 767 hir::ModuleDef::Module(_) => HighlightTag::Symbol(SymbolKind::Module),
767 hir::ModuleDef::Function(func) => { 768 hir::ModuleDef::Function(func) => {
768 let mut h = if func.as_assoc_item(db).is_some() { 769 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Function));
770 if func.as_assoc_item(db).is_some() {
771 h |= HighlightModifier::Associated;
769 if func.self_param(db).is_none() { 772 if func.self_param(db).is_none() {
770 Highlight::from(HighlightTag::Method) | HighlightModifier::Static 773 h |= HighlightModifier::Static
771 } else {
772 HighlightTag::Method.into()
773 } 774 }
774 } else { 775 }
775 HighlightTag::Symbol(SymbolKind::Function).into()
776 };
777 if func.is_unsafe(db) { 776 if func.is_unsafe(db) {
778 h |= HighlightModifier::Unsafe; 777 h |= HighlightModifier::Unsafe;
779 } 778 }
@@ -783,9 +782,21 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
783 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum), 782 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum),
784 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union), 783 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union),
785 hir::ModuleDef::EnumVariant(_) => HighlightTag::Symbol(SymbolKind::Variant), 784 hir::ModuleDef::EnumVariant(_) => HighlightTag::Symbol(SymbolKind::Variant),
786 hir::ModuleDef::Const(_) => HighlightTag::Symbol(SymbolKind::Const), 785 hir::ModuleDef::Const(konst) => {
786 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Const));
787 if konst.as_assoc_item(db).is_some() {
788 h |= HighlightModifier::Associated
789 }
790 return h;
791 }
787 hir::ModuleDef::Trait(_) => HighlightTag::Symbol(SymbolKind::Trait), 792 hir::ModuleDef::Trait(_) => HighlightTag::Symbol(SymbolKind::Trait),
788 hir::ModuleDef::TypeAlias(_) => HighlightTag::Symbol(SymbolKind::TypeAlias), 793 hir::ModuleDef::TypeAlias(type_) => {
794 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::TypeAlias));
795 if type_.as_assoc_item(db).is_some() {
796 h |= HighlightModifier::Associated
797 }
798 return h;
799 }
789 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, 800 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
790 hir::ModuleDef::Static(s) => { 801 hir::ModuleDef::Static(s) => {
791 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Static)); 802 let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Static));