From 701cf436063590c710cd7783032b5e7c3c41af22 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Feb 2020 12:06:54 +0100 Subject: Cleanup highlighting tags --- crates/ra_ide/src/syntax_highlighting.rs | 30 +++++---- crates/ra_ide/src/syntax_highlighting/tags.rs | 92 ++++++++++++++------------- 2 files changed, 64 insertions(+), 58 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index ae2163f9f..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( } }; - match name_kind { + let h = match name_kind { Some(name_kind) => highlight_name(db, name_kind), None => highlight_name_by_syntax(name), - } + }; + h | HighlightModifier::Definition } // Highlight references like the definitions they resolve to @@ -206,12 +207,13 @@ fn highlight_element( // Simple token-based highlighting COMMENT => HighlightTag::Comment.into(), - STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::LiteralString.into(), + STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), ATTR => HighlightTag::Attribute.into(), - INT_NUMBER | FLOAT_NUMBER => HighlightTag::LiteralNumeric.into(), - BYTE => HighlightTag::LiteralByte.into(), - CHAR => HighlightTag::LiteralChar.into(), - LIFETIME => HighlightTag::TypeLifetime.into(), + INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), + BYTE => HighlightTag::ByteLiteral.into(), + CHAR => HighlightTag::CharLiteral.into(), + // FIXME: set Declaration for decls + LIFETIME => HighlightTag::Lifetime.into(), k if k.is_keyword() => { let h = Highlight::new(HighlightTag::Keyword); @@ -258,17 +260,18 @@ fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight { hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum, hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, - hir::ModuleDef::EnumVariant(_) => HighlightTag::Constant, + hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, hir::ModuleDef::Const(_) => HighlightTag::Constant, - hir::ModuleDef::Static(_) => HighlightTag::Constant, + hir::ModuleDef::Static(_) => HighlightTag::Static, hir::ModuleDef::Trait(_) => HighlightTag::Trait, hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, }, - NameDefinition::SelfType(_) => HighlightTag::TypeSelf, + NameDefinition::SelfType(_) => HighlightTag::SelfType, NameDefinition::TypeParam(_) => HighlightTag::TypeParam, + // FIXME: distinguish between locals and parameters NameDefinition::Local(local) => { - let mut h = Highlight::new(HighlightTag::Variable); + let mut h = Highlight::new(HighlightTag::Local); if local.is_mut(db) || local.ty(db).is_mutable_reference() { h |= HighlightModifier::Mutable; } @@ -289,6 +292,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { match parent.kind() { STRUCT_DEF => HighlightTag::Struct.into(), ENUM_DEF => HighlightTag::Enum.into(), + UNION_KW => HighlightTag::Union.into(), TRAIT_DEF => HighlightTag::Trait.into(), TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(), TYPE_PARAM => HighlightTag::TypeParam.into(), @@ -315,7 +319,7 @@ fn highlight_injection( if let Some(range) = literal.open_quote_text_range() { acc.push(HighlightedRange { range, - highlight: HighlightTag::LiteralString.into(), + highlight: HighlightTag::StringLiteral.into(), binding_hash: None, }) } @@ -330,7 +334,7 @@ fn highlight_injection( if let Some(range) = literal.close_quote_text_range() { acc.push(HighlightedRange { range, - highlight: HighlightTag::LiteralString.into(), + highlight: HighlightTag::StringLiteral.into(), binding_hash: None, }) } diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index df2fc3c48..0b12bdef5 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -14,70 +14,71 @@ pub struct HighlightModifiers(u32); #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum HighlightTag { - Struct, - Enum, - Union, - Trait, - TypeAlias, + Attribute, BuiltinType, - + ByteLiteral, + CharLiteral, + Comment, + Constant, + Enum, + EnumVariant, Field, Function, - Module, - Constant, + Keyword, + Lifetime, Macro, - Variable, - - TypeSelf, + Module, + NumericLiteral, + SelfType, + Static, + StringLiteral, + Struct, + Trait, + TypeAlias, TypeParam, - TypeLifetime, - - LiteralByte, - LiteralNumeric, - LiteralChar, - - Comment, - LiteralString, - Attribute, - - Keyword, + Union, + Local, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] #[repr(u8)] pub enum HighlightModifier { - Mutable = 0, - Unsafe, /// Used with keywords like `if` and `break`. - Control, + Control = 0, + /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is + /// not. + Definition, + Mutable, + Unsafe, } impl HighlightTag { fn as_str(self) -> &'static str { match self { - HighlightTag::Struct => "struct", - HighlightTag::Enum => "enum", - HighlightTag::Union => "union", - HighlightTag::Trait => "trait", - HighlightTag::TypeAlias => "type_alias", + HighlightTag::Attribute => "attribute", HighlightTag::BuiltinType => "builtin_type", - + HighlightTag::ByteLiteral => "byte_literal", + HighlightTag::CharLiteral => "char_literal", + HighlightTag::Comment => "comment", + HighlightTag::Constant => "constant", + HighlightTag::Enum => "enum", + HighlightTag::EnumVariant => "enum_variant", HighlightTag::Field => "field", HighlightTag::Function => "function", - HighlightTag::Module => "module", - HighlightTag::Constant => "constant", - HighlightTag::Macro => "macro", - HighlightTag::Variable => "variable", - HighlightTag::TypeSelf => "type.self", - HighlightTag::TypeParam => "type.param", - HighlightTag::TypeLifetime => "type.lifetime", - HighlightTag::LiteralByte => "literal.byte", - HighlightTag::LiteralNumeric => "literal.numeric", - HighlightTag::LiteralChar => "literal.char", - HighlightTag::Comment => "comment", - HighlightTag::LiteralString => "string", - HighlightTag::Attribute => "attribute", HighlightTag::Keyword => "keyword", + HighlightTag::Lifetime => "lifetime", + HighlightTag::Macro => "macro", + HighlightTag::Module => "module", + HighlightTag::NumericLiteral => "numeric_literal", + HighlightTag::SelfType => "self_type", + HighlightTag::Static => "static", + HighlightTag::StringLiteral => "string", + HighlightTag::Struct => "struct", + HighlightTag::Trait => "trait", + HighlightTag::TypeAlias => "type_alias", + HighlightTag::TypeParam => "type_param", + HighlightTag::Union => "union", + HighlightTag::Local => "variable", } } } @@ -94,9 +95,10 @@ impl HighlightModifier { fn as_str(self) -> &'static str { match self { + HighlightModifier::Control => "control", + HighlightModifier::Definition => "declaration", HighlightModifier::Mutable => "mutable", HighlightModifier::Unsafe => "unsafe", - HighlightModifier::Control => "control", } } -- cgit v1.2.3