diff options
author | Aramis Razzaghipour <[email protected]> | 2021-05-23 12:43:23 +0100 |
---|---|---|
committer | Aramis Razzaghipour <[email protected]> | 2021-05-23 12:45:10 +0100 |
commit | 4d4dbcfead82eb6af1f4ef781b197a6926788b15 (patch) | |
tree | 395729f98518d6f4ac5996d3cbfd4b65d04a85f1 /crates/ide/src | |
parent | 57eedd906688d6cfa332bd40bca5234043e7293e (diff) |
Give ‘unsafe’ semantic token modifier to unsafe traits
Diffstat (limited to 'crates/ide/src')
4 files changed, 16 insertions, 3 deletions
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 { | |||
338 | 338 | ||
339 | return h; | 339 | return h; |
340 | } | 340 | } |
341 | hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait), | 341 | hir::ModuleDef::Trait(trait_) => { |
342 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Trait)); | ||
343 | |||
344 | if trait_.is_unsafe(db) { | ||
345 | h |= HlMod::Unsafe; | ||
346 | } | ||
347 | return h; | ||
348 | } | ||
342 | hir::ModuleDef::TypeAlias(type_) => { | 349 | hir::ModuleDef::TypeAlias(type_) => { |
343 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); | 350 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); |
344 | if let Some(item) = type_.as_assoc_item(db) { | 351 | 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 { | |||
68 | /// Used with keywords like `async` and `await`. | 68 | /// Used with keywords like `async` and `await`. |
69 | Async, | 69 | Async, |
70 | // Keep this last! | 70 | // Keep this last! |
71 | /// Used for unsafe functions, mutable statics, union accesses and unsafe operations. | 71 | /// Used for unsafe functions, unsafe traits, mutable statics, union accesses and unsafe operations. |
72 | Unsafe, | 72 | Unsafe, |
73 | } | 73 | } |
74 | 74 | ||
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 | |||
245 | <span class="keyword">let</span> <span class="variable declaration">f1</span> <span class="operator">=</span> <span class="function async">learn_and_sing</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 245 | <span class="keyword">let</span> <span class="variable declaration">f1</span> <span class="operator">=</span> <span class="function async">learn_and_sing</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
246 | <span class="keyword">let</span> <span class="variable declaration">f2</span> <span class="operator">=</span> <span class="unresolved_reference">dance</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 246 | <span class="keyword">let</span> <span class="variable declaration">f2</span> <span class="operator">=</span> <span class="unresolved_reference">dance</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
247 | futures::<span class="macro">join!</span><span class="parenthesis">(</span>f1<span class="comma">,</span> f2<span class="parenthesis">)</span><span class="semicolon">;</span> | 247 | futures::<span class="macro">join!</span><span class="parenthesis">(</span>f1<span class="comma">,</span> f2<span class="parenthesis">)</span><span class="semicolon">;</span> |
248 | <span class="brace">}</span></code></pre> \ No newline at end of file | 248 | <span class="brace">}</span> |
249 | |||
250 | <span class="keyword unsafe">unsafe</span> <span class="keyword">trait</span> <span class="trait declaration unsafe">Dangerous</span> <span class="brace">{</span><span class="brace">}</span> | ||
251 | <span class="keyword">impl</span> <span class="trait unsafe">Dangerous</span> <span class="keyword">for</span> <span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span></code></pre> \ 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() { | |||
219 | let f2 = dance(); | 219 | let f2 = dance(); |
220 | futures::join!(f1, f2); | 220 | futures::join!(f1, f2); |
221 | } | 221 | } |
222 | |||
223 | unsafe trait Dangerous {} | ||
224 | impl Dangerous for () {} | ||
222 | "# | 225 | "# |
223 | .trim(), | 226 | .trim(), |
224 | expect_file!["./test_data/highlighting.html"], | 227 | expect_file!["./test_data/highlighting.html"], |