mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Fix syntax highlighting not highlighting derives anymore
This commit is contained in:
parent
f13c98034b
commit
1bbef5af85
@ -160,6 +160,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
|||||||
self.imp.is_attr_macro_call(item)
|
self.imp.is_attr_macro_call(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_derive_annotated(&self, item: &ast::Adt) -> bool {
|
||||||
|
self.imp.is_derive_annotated(item)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn speculative_expand(
|
pub fn speculative_expand(
|
||||||
&self,
|
&self,
|
||||||
actual_macro_call: &ast::MacroCall,
|
actual_macro_call: &ast::MacroCall,
|
||||||
@ -470,6 +474,12 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_derive_annotated(&self, adt: &ast::Adt) -> bool {
|
||||||
|
let file_id = self.find_file(adt.syntax()).file_id;
|
||||||
|
let adt = InFile::new(file_id, adt);
|
||||||
|
self.with_ctx(|ctx| ctx.has_derives(adt))
|
||||||
|
}
|
||||||
|
|
||||||
fn is_attr_macro_call(&self, item: &ast::Item) -> bool {
|
fn is_attr_macro_call(&self, item: &ast::Item) -> bool {
|
||||||
let file_id = self.find_file(item.syntax()).file_id;
|
let file_id = self.find_file(item.syntax()).file_id;
|
||||||
let src = InFile::new(file_id, item.clone());
|
let src = InFile::new(file_id, item.clone());
|
||||||
|
@ -255,6 +255,9 @@ impl SourceToDefCtx<'_, '_> {
|
|||||||
.get(&src.value)
|
.get(&src.value)
|
||||||
.map(|&(attr_id, call_id, ref ids)| (attr_id, call_id, &**ids))
|
.map(|&(attr_id, call_id, ref ids)| (attr_id, call_id, &**ids))
|
||||||
}
|
}
|
||||||
|
pub(super) fn has_derives(&mut self, adt: InFile<&ast::Adt>) -> bool {
|
||||||
|
self.dyn_map(adt).as_ref().map_or(false, |map| !map[keys::DERIVE_MACRO_CALL].is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
fn to_def<Ast: AstNode + 'static, ID: Copy + 'static>(
|
fn to_def<Ast: AstNode + 'static, ID: Copy + 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -54,6 +54,7 @@ pub trait Policy {
|
|||||||
|
|
||||||
fn insert(map: &mut DynMap, key: Self::K, value: Self::V);
|
fn insert(map: &mut DynMap, key: Self::K, value: Self::V);
|
||||||
fn get<'a>(map: &'a DynMap, key: &Self::K) -> Option<&'a Self::V>;
|
fn get<'a>(map: &'a DynMap, key: &Self::K) -> Option<&'a Self::V>;
|
||||||
|
fn is_empty(map: &DynMap) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Hash + Eq + 'static, V: 'static> Policy for (K, V) {
|
impl<K: Hash + Eq + 'static, V: 'static> Policy for (K, V) {
|
||||||
@ -65,6 +66,9 @@ impl<K: Hash + Eq + 'static, V: 'static> Policy for (K, V) {
|
|||||||
fn get<'a>(map: &'a DynMap, key: &K) -> Option<&'a V> {
|
fn get<'a>(map: &'a DynMap, key: &K) -> Option<&'a V> {
|
||||||
map.map.get::<FxHashMap<K, V>>()?.get(key)
|
map.map.get::<FxHashMap<K, V>>()?.get(key)
|
||||||
}
|
}
|
||||||
|
fn is_empty(map: &DynMap) -> bool {
|
||||||
|
map.map.get::<FxHashMap<K, V>>().map_or(true, |it| it.is_empty())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DynMap {
|
pub struct DynMap {
|
||||||
@ -90,6 +94,10 @@ impl<P: Policy> KeyMap<Key<P::K, P::V, P>> {
|
|||||||
pub fn get(&self, key: &P::K) -> Option<&P::V> {
|
pub fn get(&self, key: &P::K) -> Option<&P::V> {
|
||||||
P::get(&self.map, key)
|
P::get(&self.map, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
P::is_empty(&self.map)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: Policy> Index<Key<P::K, P::V, P>> for DynMap {
|
impl<P: Policy> Index<Key<P::K, P::V, P>> for DynMap {
|
||||||
|
@ -61,4 +61,7 @@ impl<AST: AstNode + 'static, ID: 'static> Policy for AstPtrPolicy<AST, ID> {
|
|||||||
let key = AstPtr::new(key);
|
let key = AstPtr::new(key);
|
||||||
map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(&key)
|
map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(&key)
|
||||||
}
|
}
|
||||||
|
fn is_empty(map: &DynMap) -> bool {
|
||||||
|
map.map.get::<FxHashMap<AstPtr<AST>, ID>>().map_or(true, |it| it.is_empty())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +237,20 @@ fn traverse(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Some(item) if sema.is_attr_macro_call(&item) => current_attr_call = Some(item),
|
Some(item) if sema.is_attr_macro_call(&item) => current_attr_call = Some(item),
|
||||||
|
Some(item) if current_attr_call.is_none() => {
|
||||||
|
let adt = match item {
|
||||||
|
ast::Item::Enum(it) => Some(ast::Adt::Enum(it)),
|
||||||
|
ast::Item::Struct(it) => Some(ast::Adt::Struct(it)),
|
||||||
|
ast::Item::Union(it) => Some(ast::Adt::Union(it)),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
match adt {
|
||||||
|
Some(adt) if sema.is_derive_annotated(&adt) => {
|
||||||
|
current_attr_call = Some(adt.into());
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
None if ast::Attr::can_cast(node.kind()) => inside_attribute = true,
|
None if ast::Attr::can_cast(node.kind()) => inside_attribute = true,
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user