mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Rename NomialDef -> AdtDef
This commit is contained in:
parent
3d28292157
commit
76202a2c73
5 changed files with 28 additions and 28 deletions
|
@ -26,7 +26,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
|||
// ```
|
||||
pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
let cap = ctx.config.snippet_cap?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
|
||||
let node_start = derive_insertion_offset(&nominal)?;
|
||||
let target = nominal.syntax().text_range();
|
||||
acc.add(
|
||||
|
@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<
|
|||
}
|
||||
|
||||
// Insert `derive` after doc comments.
|
||||
fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> {
|
||||
fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option<TextSize> {
|
||||
let non_ws_child = nominal
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
|
|
|
@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
|||
// }
|
||||
// ```
|
||||
pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
|
||||
let name = nominal.name()?;
|
||||
let target = nominal.syntax().text_range();
|
||||
acc.add(
|
||||
|
|
|
@ -23,7 +23,7 @@ pub(crate) fn goto_implementation(
|
|||
|
||||
let krate = sema.to_module_def(position.file_id)?.krate();
|
||||
|
||||
if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) {
|
||||
if let Some(nominal_def) = find_node_at_offset::<ast::AdtDef>(&syntax, position.offset) {
|
||||
return Some(RangeInfo::new(
|
||||
nominal_def.syntax().text_range(),
|
||||
impls_for_def(&sema, &nominal_def, krate)?,
|
||||
|
@ -40,13 +40,13 @@ pub(crate) fn goto_implementation(
|
|||
|
||||
fn impls_for_def(
|
||||
sema: &Semantics<RootDatabase>,
|
||||
node: &ast::NominalDef,
|
||||
node: &ast::AdtDef,
|
||||
krate: Crate,
|
||||
) -> Option<Vec<NavigationTarget>> {
|
||||
let ty = match node {
|
||||
ast::NominalDef::StructDef(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::NominalDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::NominalDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::AdtDef::StructDef(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db),
|
||||
ast::AdtDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db),
|
||||
};
|
||||
|
||||
let impls = ImplDef::all_in_crate(sema.db, krate);
|
||||
|
|
|
@ -1376,15 +1376,15 @@ impl ast::AttrsOwner for ExternItem {}
|
|||
impl ast::NameOwner for ExternItem {}
|
||||
impl ast::VisibilityOwner for ExternItem {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum NominalDef {
|
||||
pub enum AdtDef {
|
||||
StructDef(StructDef),
|
||||
EnumDef(EnumDef),
|
||||
UnionDef(UnionDef),
|
||||
}
|
||||
impl ast::AttrsOwner for NominalDef {}
|
||||
impl ast::NameOwner for NominalDef {}
|
||||
impl ast::TypeParamsOwner for NominalDef {}
|
||||
impl ast::VisibilityOwner for NominalDef {}
|
||||
impl ast::AttrsOwner for AdtDef {}
|
||||
impl ast::NameOwner for AdtDef {}
|
||||
impl ast::TypeParamsOwner for AdtDef {}
|
||||
impl ast::VisibilityOwner for AdtDef {}
|
||||
impl AstNode for SourceFile {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -3345,16 +3345,16 @@ impl AstNode for ExternItem {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl From<StructDef> for NominalDef {
|
||||
fn from(node: StructDef) -> NominalDef { NominalDef::StructDef(node) }
|
||||
impl From<StructDef> for AdtDef {
|
||||
fn from(node: StructDef) -> AdtDef { AdtDef::StructDef(node) }
|
||||
}
|
||||
impl From<EnumDef> for NominalDef {
|
||||
fn from(node: EnumDef) -> NominalDef { NominalDef::EnumDef(node) }
|
||||
impl From<EnumDef> for AdtDef {
|
||||
fn from(node: EnumDef) -> AdtDef { AdtDef::EnumDef(node) }
|
||||
}
|
||||
impl From<UnionDef> for NominalDef {
|
||||
fn from(node: UnionDef) -> NominalDef { NominalDef::UnionDef(node) }
|
||||
impl From<UnionDef> for AdtDef {
|
||||
fn from(node: UnionDef) -> AdtDef { AdtDef::UnionDef(node) }
|
||||
}
|
||||
impl AstNode for NominalDef {
|
||||
impl AstNode for AdtDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
|
||||
|
@ -3363,18 +3363,18 @@ impl AstNode for NominalDef {
|
|||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
|
||||
ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
|
||||
UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
|
||||
STRUCT_DEF => AdtDef::StructDef(StructDef { syntax }),
|
||||
ENUM_DEF => AdtDef::EnumDef(EnumDef { syntax }),
|
||||
UNION_DEF => AdtDef::UnionDef(UnionDef { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
NominalDef::StructDef(it) => &it.syntax,
|
||||
NominalDef::EnumDef(it) => &it.syntax,
|
||||
NominalDef::UnionDef(it) => &it.syntax,
|
||||
AdtDef::StructDef(it) => &it.syntax,
|
||||
AdtDef::EnumDef(it) => &it.syntax,
|
||||
AdtDef::UnionDef(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3423,7 +3423,7 @@ impl std::fmt::Display for ExternItem {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for NominalDef {
|
||||
impl std::fmt::Display for AdtDef {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
|
|
|
@ -426,7 +426,7 @@ ExternItemList =
|
|||
MetaItem =
|
||||
Path '=' AttrInput nested_meta_items:MetaItem*
|
||||
|
||||
NominalDef =
|
||||
AdtDef =
|
||||
StructDef
|
||||
| EnumDef
|
||||
| UnionDef
|
||||
|
|
Loading…
Reference in a new issue