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