This commit is contained in:
OleStrohm 2022-09-12 21:02:30 +01:00
parent 5313bd1984
commit 177ec82a41
3 changed files with 21 additions and 1 deletions

View File

@ -2,6 +2,8 @@
use std::fmt::{self, Write};
use syntax::ast::HasName;
use crate::{
expr::{Array, BindingAnnotation, Literal, Statement},
pretty::{print_generic_args, print_path, print_type_ref},
@ -32,6 +34,16 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
};
format!("const {} = ", name)
}
DefWithBodyId::VariantId(it) => {
needs_semi = false;
let src = it.parent.child_source(db);
let variant = &src.value[it.local_id];
let name = match &variant.name() {
Some(name) => name.to_string(),
None => "_".to_string(),
};
format!("{}", name)
}
};
let mut p = Printer { body, buf: header, indent_level: 0, needs_indent: false };

View File

@ -964,6 +964,12 @@ fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
}
}
impl From<&Variant> for DefWithBodyId {
fn from(&v: &Variant) -> Self {
DefWithBodyId::VariantId(v.into())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Variant {
pub(crate) parent: Enum,
@ -1179,6 +1185,7 @@ fn id(&self) -> DefWithBodyId {
DefWithBody::Function(it) => it.id.into(),
DefWithBody::Static(it) => it.id.into(),
DefWithBody::Const(it) => it.id.into(),
DefWithBody::Variant(it) => it.into(),
}
}

View File

@ -3,7 +3,8 @@
use either::Either;
use hir::{
db::HirDatabase, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics, StructKind, TypeInfo,
db::HirDatabase, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics,
StructKind, TypeInfo,
};
use ide_db::{
base_db::SourceDatabase,