aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/syntax_highlighting/highlight.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-23 00:58:59 +0100
committerGitHub <[email protected]>2021-06-23 00:58:59 +0100
commit3381c2e4a8bcea2db3edd1741a7dd3fcdb15231b (patch)
treefc99fe5bc5ff7d6826303d166cb911b63125f33d /crates/ide/src/syntax_highlighting/highlight.rs
parent3762cb4535dce9eaf7c3dbd4aa9c33bf6dd30c87 (diff)
parent3e7472f76c70c3b0a31bb72f6f318c1aa1aba83d (diff)
Merge #9031
9031: Add `public` semantic token modifier for public items r=Veykril a=arzg Closes #8943. Co-authored-by: Aramis Razzaghipour <[email protected]>
Diffstat (limited to 'crates/ide/src/syntax_highlighting/highlight.rs')
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index 6834fe11a..82e16a51b 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -1,6 +1,6 @@
1//! Computes color for a single element. 1//! Computes color for a single element.
2 2
3use hir::{AsAssocItem, Semantics}; 3use hir::{AsAssocItem, HasVisibility, Semantics};
4use ide_db::{ 4use ide_db::{
5 defs::{Definition, NameClass, NameRefClass}, 5 defs::{Definition, NameClass, NameRefClass},
6 RootDatabase, SymbolKind, 6 RootDatabase, SymbolKind,
@@ -439,9 +439,12 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition)
439 439
440 let is_from_other_crate = def.module(db).map(hir::Module::krate) != krate; 440 let is_from_other_crate = def.module(db).map(hir::Module::krate) != krate;
441 let is_builtin_type = matches!(def, Definition::ModuleDef(hir::ModuleDef::BuiltinType(_))); 441 let is_builtin_type = matches!(def, Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)));
442 let is_public = def.visibility(db) == Some(hir::Visibility::Public);
442 443
443 if is_from_other_crate && !is_builtin_type { 444 match (is_from_other_crate, is_builtin_type, is_public) {
444 h |= HlMod::Library; 445 (true, false, _) => h |= HlMod::Library,
446 (false, _, true) => h |= HlMod::Public,
447 _ => {}
445 } 448 }
446 449
447 h 450 h
@@ -475,8 +478,14 @@ fn highlight_method_call(
475 if func.as_assoc_item(sema.db).and_then(|it| it.containing_trait(sema.db)).is_some() { 478 if func.as_assoc_item(sema.db).and_then(|it| it.containing_trait(sema.db)).is_some() {
476 h |= HlMod::Trait; 479 h |= HlMod::Trait;
477 } 480 }
478 if Some(func.module(sema.db).krate()) != krate { 481
482 let is_from_other_crate = Some(func.module(sema.db).krate()) != krate;
483 let is_public = func.visibility(sema.db) == hir::Visibility::Public;
484
485 if is_from_other_crate {
479 h |= HlMod::Library; 486 h |= HlMod::Library;
487 } else if is_public {
488 h |= HlMod::Public;
480 } 489 }
481 490
482 if let Some(self_param) = func.self_param(sema.db) { 491 if let Some(self_param) = func.self_param(sema.db) {