9734: semantic highlighting: add reference hlmod r=matklad a=jhgg

This PR adds the "reference" highlight modifier! 

I basically went around and looked for `HlMod::Mutable` to find the callsites to add a reference. I think these all make sense! 

Co-authored-by: Jake Heinz <jh@discordapp.com>
Co-authored-by: Jake <jh@discordapp.com>
This commit is contained in:
bors[bot] 2021-08-04 09:37:30 +00:00 committed by GitHub
commit 1b02cafa43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 81 additions and 44 deletions

View file

@ -1861,6 +1861,14 @@ impl Local {
matches!(&body[self.pat_id], Pat::Bind { mode: BindingAnnotation::Mutable, .. })
}
pub fn is_ref(self, db: &dyn HirDatabase) -> bool {
let body = db.body(self.parent);
matches!(
&body[self.pat_id],
Pat::Bind { mode: BindingAnnotation::Ref | BindingAnnotation::RefMut, .. }
)
}
pub fn parent(self, _db: &dyn HirDatabase) -> DefWithBody {
self.parent.into()
}
@ -2216,6 +2224,10 @@ impl Type {
matches!(self.ty.kind(&Interner), TyKind::Ref(hir_ty::Mutability::Mut, ..))
}
pub fn is_reference(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Ref(..))
}
pub fn is_usize(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
}