mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Rebased
This commit is contained in:
parent
5313bd1984
commit
177ec82a41
3 changed files with 21 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
|
||||||
|
use syntax::ast::HasName;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
expr::{Array, BindingAnnotation, Literal, Statement},
|
expr::{Array, BindingAnnotation, Literal, Statement},
|
||||||
pretty::{print_generic_args, print_path, print_type_ref},
|
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)
|
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 };
|
let mut p = Printer { body, buf: header, indent_level: 0, needs_indent: false };
|
||||||
|
|
|
@ -964,6 +964,12 @@ impl HasVisibility for Enum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&Variant> for DefWithBodyId {
|
||||||
|
fn from(&v: &Variant) -> Self {
|
||||||
|
DefWithBodyId::VariantId(v.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Variant {
|
pub struct Variant {
|
||||||
pub(crate) parent: Enum,
|
pub(crate) parent: Enum,
|
||||||
|
@ -1179,6 +1185,7 @@ impl DefWithBody {
|
||||||
DefWithBody::Function(it) => it.id.into(),
|
DefWithBody::Function(it) => it.id.into(),
|
||||||
DefWithBody::Static(it) => it.id.into(),
|
DefWithBody::Static(it) => it.id.into(),
|
||||||
DefWithBody::Const(it) => it.id.into(),
|
DefWithBody::Const(it) => it.id.into(),
|
||||||
|
DefWithBody::Variant(it) => it.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ use std::fmt::Display;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{
|
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::{
|
use ide_db::{
|
||||||
base_db::SourceDatabase,
|
base_db::SourceDatabase,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue