Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/annotations.rs')
| -rw-r--r-- | crates/ide/src/annotations.rs | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 472b396ac5..12c6852ea0 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -40,6 +40,7 @@ pub struct AnnotationConfig { pub annotate_impls: bool, pub annotate_references: bool, pub annotate_method_references: bool, + pub annotate_enum_variant_references: bool, } pub(crate) fn annotations( @@ -63,18 +64,33 @@ pub(crate) fn annotations( visit_file_defs(&Semantics::new(db), file_id, &mut |def| match def { Either::Left(def) => { - let range = match def { + let (range, ranges_enum_variants) = match def { hir::ModuleDef::Const(konst) => { - konst.source(db).and_then(|node| name_range(&node, file_id)) + (konst.source(db).and_then(|node| name_range(&node, file_id)), vec![]) } hir::ModuleDef::Trait(trait_) => { - trait_.source(db).and_then(|node| name_range(&node, file_id)) + (trait_.source(db).and_then(|node| name_range(&node, file_id)), vec![]) } - hir::ModuleDef::Adt(adt) => { - adt.source(db).and_then(|node| name_range(&node, file_id)) - } - _ => None, + hir::ModuleDef::Adt(adt) => match adt { + hir::Adt::Enum(enum_) => ( + enum_.source(db).and_then(|node| name_range(&node, file_id)), + if config.annotate_enum_variant_references { + enum_ + .variants(db) + .into_iter() + .map(|variant| { + variant.source(db).and_then(|node| name_range(&node, file_id)) + }) + .collect() + } else { + vec![] + }, + ), + _ => (adt.source(db).and_then(|node| name_range(&node, file_id)), vec![]), + }, + _ => (None, vec![]), }; + let (range, offset) = match range { Some(range) => (range, range.start()), None => return, @@ -99,6 +115,20 @@ pub(crate) fn annotations( }); } + if config.annotate_enum_variant_references { + for range_enum_variant in + ranges_enum_variants.into_iter().filter_map(std::convert::identity) + { + annotations.push(Annotation { + range: range_enum_variant, + kind: AnnotationKind::HasReferences { + position: FilePosition { file_id, offset: range_enum_variant.start() }, + data: None, + }, + }); + } + } + fn name_range<T: HasName>(node: &InFile<T>, file_id: FileId) -> Option<TextRange> { if node.file_id == file_id.into() { node.value.name().map(|it| it.syntax().text_range()) @@ -173,6 +203,7 @@ mod tests { annotate_impls: true, annotate_references: true, annotate_method_references: true, + annotate_enum_variant_references: true, }, file_id, ) |