diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-25 03:30:47 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-25 03:30:47 +0100 |
commit | 8b049ec393230e4b9fea3022a3ebf34e2af5395d (patch) | |
tree | d75b9290e907898027eab2e723ed1c0040e43e4e /crates/hir/src | |
parent | 6d473c0a8f6acecbae680b69528b3f88a31dc5fc (diff) | |
parent | d75277b66b07e3fa4fed5088b92c6f65b2de8fe9 (diff) |
Merge #8942
8942: Add `library` semantic token modifier to items from other crates r=arzg a=arzg
Closes #5772.
A lot of code here is pretty repetitive; please let me know if you have any ideas how to improve it, or whether it’s fine as-is.
Side-note: How can I add tests for this? I don’t see a way for the test Rust code in `test_highlighting` to reference other crates to observe the new behaviour.
Co-authored-by: Aramis Razzaghipour <[email protected]>
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/lib.rs | 33 |
1 files changed, 1 insertions, 32 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index ca9a7f7fa..cdf65a044 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -551,10 +551,6 @@ impl Struct { | |||
551 | Module { id: self.id.lookup(db.upcast()).container } | 551 | Module { id: self.id.lookup(db.upcast()).container } |
552 | } | 552 | } |
553 | 553 | ||
554 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
555 | Some(self.module(db).krate()) | ||
556 | } | ||
557 | |||
558 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 554 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
559 | db.struct_data(self.id).name.clone() | 555 | db.struct_data(self.id).name.clone() |
560 | } | 556 | } |
@@ -639,10 +635,6 @@ impl Enum { | |||
639 | Module { id: self.id.lookup(db.upcast()).container } | 635 | Module { id: self.id.lookup(db.upcast()).container } |
640 | } | 636 | } |
641 | 637 | ||
642 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
643 | Some(self.module(db).krate()) | ||
644 | } | ||
645 | |||
646 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 638 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
647 | db.enum_data(self.id).name.clone() | 639 | db.enum_data(self.id).name.clone() |
648 | } | 640 | } |
@@ -672,6 +664,7 @@ impl Variant { | |||
672 | pub fn module(self, db: &dyn HirDatabase) -> Module { | 664 | pub fn module(self, db: &dyn HirDatabase) -> Module { |
673 | self.parent.module(db) | 665 | self.parent.module(db) |
674 | } | 666 | } |
667 | |||
675 | pub fn parent_enum(self, _db: &dyn HirDatabase) -> Enum { | 668 | pub fn parent_enum(self, _db: &dyn HirDatabase) -> Enum { |
676 | self.parent | 669 | self.parent |
677 | } | 670 | } |
@@ -728,10 +721,6 @@ impl Adt { | |||
728 | } | 721 | } |
729 | } | 722 | } |
730 | 723 | ||
731 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
732 | self.module(db).krate() | ||
733 | } | ||
734 | |||
735 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 724 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
736 | match self { | 725 | match self { |
737 | Adt::Struct(s) => s.name(db), | 726 | Adt::Struct(s) => s.name(db), |
@@ -820,10 +809,6 @@ impl Function { | |||
820 | self.id.lookup(db.upcast()).module(db.upcast()).into() | 809 | self.id.lookup(db.upcast()).module(db.upcast()).into() |
821 | } | 810 | } |
822 | 811 | ||
823 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
824 | Some(self.module(db).krate()) | ||
825 | } | ||
826 | |||
827 | pub fn name(self, db: &dyn HirDatabase) -> Name { | 812 | pub fn name(self, db: &dyn HirDatabase) -> Name { |
828 | db.function_data(self.id).name.clone() | 813 | db.function_data(self.id).name.clone() |
829 | } | 814 | } |
@@ -1013,10 +998,6 @@ impl Const { | |||
1013 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } | 998 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } |
1014 | } | 999 | } |
1015 | 1000 | ||
1016 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
1017 | Some(self.module(db).krate()) | ||
1018 | } | ||
1019 | |||
1020 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 1001 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
1021 | db.const_data(self.id).name.clone() | 1002 | db.const_data(self.id).name.clone() |
1022 | } | 1003 | } |
@@ -1044,10 +1025,6 @@ impl Static { | |||
1044 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } | 1025 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } |
1045 | } | 1026 | } |
1046 | 1027 | ||
1047 | pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { | ||
1048 | Some(self.module(db).krate()) | ||
1049 | } | ||
1050 | |||
1051 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 1028 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
1052 | db.static_data(self.id).name.clone() | 1029 | db.static_data(self.id).name.clone() |
1053 | } | 1030 | } |
@@ -1111,10 +1088,6 @@ impl TypeAlias { | |||
1111 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } | 1088 | Module { id: self.id.lookup(db.upcast()).module(db.upcast()) } |
1112 | } | 1089 | } |
1113 | 1090 | ||
1114 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
1115 | self.module(db).krate() | ||
1116 | } | ||
1117 | |||
1118 | pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> { | 1091 | pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> { |
1119 | db.type_alias_data(self.id).type_ref.as_deref().cloned() | 1092 | db.type_alias_data(self.id).type_ref.as_deref().cloned() |
1120 | } | 1093 | } |
@@ -1666,10 +1639,6 @@ impl Impl { | |||
1666 | self.id.lookup(db.upcast()).container.into() | 1639 | self.id.lookup(db.upcast()).container.into() |
1667 | } | 1640 | } |
1668 | 1641 | ||
1669 | pub fn krate(self, db: &dyn HirDatabase) -> Crate { | ||
1670 | Crate { id: self.module(db).id.krate() } | ||
1671 | } | ||
1672 | |||
1673 | pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> { | 1642 | pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> { |
1674 | let src = self.source(db)?; | 1643 | let src = self.source(db)?; |
1675 | let item = src.file_id.is_builtin_derive(db.upcast())?; | 1644 | let item = src.file_id.is_builtin_derive(db.upcast())?; |