From 4d4dbcfead82eb6af1f4ef781b197a6926788b15 Mon Sep 17 00:00:00 2001 From: Aramis Razzaghipour Date: Sun, 23 May 2021 21:43:23 +1000 Subject: =?UTF-8?q?Give=20=E2=80=98unsafe=E2=80=99=20semantic=20token=20mo?= =?UTF-8?q?difier=20to=20unsafe=20traits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/hir/src/lib.rs | 4 ++++ crates/ide/src/syntax_highlighting/highlight.rs | 9 ++++++++- crates/ide/src/syntax_highlighting/tags.rs | 2 +- crates/ide/src/syntax_highlighting/test_data/highlighting.html | 5 ++++- crates/ide/src/syntax_highlighting/tests.rs | 3 +++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 800101c91..a7c42ca1e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1085,6 +1085,10 @@ impl Trait { pub fn is_auto(self, db: &dyn HirDatabase) -> bool { db.trait_data(self.id).is_auto } + + pub fn is_unsafe(&self, db: &dyn HirDatabase) -> bool { + db.trait_data(self.id).is_unsafe + } } impl HasVisibility for Trait { diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index baed8e217..058e37ff0 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -338,7 +338,14 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { return h; } - hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait), + hir::ModuleDef::Trait(trait_) => { + let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Trait)); + + if trait_.is_unsafe(db) { + h |= HlMod::Unsafe; + } + return h; + } hir::ModuleDef::TypeAlias(type_) => { let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); if let Some(item) = type_.as_assoc_item(db) { diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index f4a2e7506..27473a2f9 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -68,7 +68,7 @@ pub enum HlMod { /// Used with keywords like `async` and `await`. Async, // Keep this last! - /// Used for unsafe functions, mutable statics, union accesses and unsafe operations. + /// Used for unsafe functions, unsafe traits, mutable statics, union accesses and unsafe operations. Unsafe, } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 0d325f3f3..878431b56 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html @@ -245,4 +245,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd let f1 = learn_and_sing(); let f2 = dance(); futures::join!(f1, f2); -} \ No newline at end of file +} + +unsafe trait Dangerous {} +impl Dangerous for () {} \ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 8c8878d36..9ce26e930 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -219,6 +219,9 @@ async fn async_main() { let f2 = dance(); futures::join!(f1, f2); } + +unsafe trait Dangerous {} +impl Dangerous for () {} "# .trim(), expect_file!["./test_data/highlighting.html"], -- cgit v1.2.3