mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
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 <aramisnoah@gmail.com>
This commit is contained in:
commit
8b049ec393
10 changed files with 124 additions and 62 deletions
|
@ -551,10 +551,6 @@ impl Struct {
|
|||
Module { id: self.id.lookup(db.upcast()).container }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
|
||||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Name {
|
||||
db.struct_data(self.id).name.clone()
|
||||
}
|
||||
|
@ -639,10 +635,6 @@ impl Enum {
|
|||
Module { id: self.id.lookup(db.upcast()).container }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
|
||||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Name {
|
||||
db.enum_data(self.id).name.clone()
|
||||
}
|
||||
|
@ -672,6 +664,7 @@ impl Variant {
|
|||
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
||||
self.parent.module(db)
|
||||
}
|
||||
|
||||
pub fn parent_enum(self, _db: &dyn HirDatabase) -> Enum {
|
||||
self.parent
|
||||
}
|
||||
|
@ -728,10 +721,6 @@ impl Adt {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
|
||||
self.module(db).krate()
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Name {
|
||||
match self {
|
||||
Adt::Struct(s) => s.name(db),
|
||||
|
@ -820,10 +809,6 @@ impl Function {
|
|||
self.id.lookup(db.upcast()).module(db.upcast()).into()
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
|
||||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Name {
|
||||
db.function_data(self.id).name.clone()
|
||||
}
|
||||
|
@ -1013,10 +998,6 @@ impl Const {
|
|||
Module { id: self.id.lookup(db.upcast()).module(db.upcast()) }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
|
||||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
|
||||
db.const_data(self.id).name.clone()
|
||||
}
|
||||
|
@ -1044,10 +1025,6 @@ impl Static {
|
|||
Module { id: self.id.lookup(db.upcast()).module(db.upcast()) }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
|
||||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
|
||||
db.static_data(self.id).name.clone()
|
||||
}
|
||||
|
@ -1111,10 +1088,6 @@ impl TypeAlias {
|
|||
Module { id: self.id.lookup(db.upcast()).module(db.upcast()) }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
|
||||
self.module(db).krate()
|
||||
}
|
||||
|
||||
pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> {
|
||||
db.type_alias_data(self.id).type_ref.as_deref().cloned()
|
||||
}
|
||||
|
@ -1666,10 +1639,6 @@ impl Impl {
|
|||
self.id.lookup(db.upcast()).container.into()
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &dyn HirDatabase) -> Crate {
|
||||
Crate { id: self.module(db).id.krate() }
|
||||
}
|
||||
|
||||
pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> {
|
||||
let src = self.source(db)?;
|
||||
let item = src.file_id.is_builtin_derive(db.upcast())?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue