Align code_model name with ungrammar

This commit is contained in:
Aleksey Kladov 2020-12-20 10:05:24 +03:00
parent 87886e8986
commit f6ed16674c
22 changed files with 88 additions and 102 deletions

View file

@ -1,7 +1,7 @@
use std::iter; use std::iter;
use either::Either; use either::Either;
use hir::{AsName, EnumVariant, Module, ModuleDef, Name}; use hir::{AsName, Module, ModuleDef, Name, Variant};
use ide_db::helpers::{ use ide_db::helpers::{
insert_use::{insert_use, ImportScope}, insert_use::{insert_use, ImportScope},
mod_path_to_ast, mod_path_to_ast,
@ -53,7 +53,7 @@ pub(crate) fn extract_struct_from_enum_variant(
let variant_hir_name = variant_hir.name(ctx.db()); let variant_hir_name = variant_hir.name(ctx.db());
let enum_module_def = ModuleDef::from(enum_hir); let enum_module_def = ModuleDef::from(enum_hir);
let usages = let usages =
Definition::ModuleDef(ModuleDef::EnumVariant(variant_hir)).usages(&ctx.sema).all(); Definition::ModuleDef(ModuleDef::Variant(variant_hir)).usages(&ctx.sema).all();
let mut visited_modules_set = FxHashSet::default(); let mut visited_modules_set = FxHashSet::default();
let current_module = enum_hir.module(ctx.db()); let current_module = enum_hir.module(ctx.db());
@ -109,7 +109,7 @@ fn extract_field_list_if_applicable(
} }
} }
fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &EnumVariant) -> bool { fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &Variant) -> bool {
variant variant
.parent_enum(db) .parent_enum(db)
.module(db) .module(db)
@ -119,7 +119,7 @@ fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &En
// only check type-namespace // only check type-namespace
hir::ScopeDef::ModuleDef(def) => matches!(def, hir::ScopeDef::ModuleDef(def) => matches!(def,
ModuleDef::Module(_) | ModuleDef::Adt(_) | ModuleDef::Module(_) | ModuleDef::Adt(_) |
ModuleDef::EnumVariant(_) | ModuleDef::Trait(_) | ModuleDef::Variant(_) | ModuleDef::Trait(_) |
ModuleDef::TypeAlias(_) | ModuleDef::BuiltinType(_) ModuleDef::TypeAlias(_) | ModuleDef::BuiltinType(_)
), ),
_ => false, _ => false,

View file

@ -192,7 +192,7 @@ fn resolve_tuple_of_enum_def(
.collect() .collect()
} }
fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option<ast::Pat> { fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::Variant) -> Option<ast::Pat> {
let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?); let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?);
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though

View file

@ -201,7 +201,7 @@ fn target_data_for_def(
(vis_offset(syntax), in_file_source.value.visibility(), syntax.text_range(), file_id) (vis_offset(syntax), in_file_source.value.visibility(), syntax.text_range(), file_id)
} }
// Enum variants can't be private, we can't modify builtin types // Enum variants can't be private, we can't modify builtin types
hir::ModuleDef::EnumVariant(_) | hir::ModuleDef::BuiltinType(_) => return None, hir::ModuleDef::Variant(_) | hir::ModuleDef::BuiltinType(_) => return None,
}; };
Some((offset, current_visibility, target, target_file, target_name)) Some((offset, current_visibility, target, target_file, target_name))

View file

@ -19,7 +19,7 @@ use hir::{ModPath, ScopeDef, Type};
use crate::{ use crate::{
item::Builder, item::Builder,
render::{ render::{
const_::render_const, enum_variant::render_enum_variant, function::render_fn, const_::render_const, enum_variant::render_variant, function::render_fn,
macro_::render_macro, render_field, render_resolution, render_tuple_field, macro_::render_macro, render_field, render_resolution, render_tuple_field,
type_alias::render_type_alias, RenderContext, type_alias::render_type_alias, RenderContext,
}, },
@ -120,20 +120,20 @@ impl Completions {
pub(crate) fn add_qualified_enum_variant( pub(crate) fn add_qualified_enum_variant(
&mut self, &mut self,
ctx: &CompletionContext, ctx: &CompletionContext,
variant: hir::EnumVariant, variant: hir::Variant,
path: ModPath, path: ModPath,
) { ) {
let item = render_enum_variant(RenderContext::new(ctx), None, None, variant, Some(path)); let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path));
self.add(item); self.add(item);
} }
pub(crate) fn add_enum_variant( pub(crate) fn add_enum_variant(
&mut self, &mut self,
ctx: &CompletionContext, ctx: &CompletionContext,
variant: hir::EnumVariant, variant: hir::Variant,
local_name: Option<String>, local_name: Option<String>,
) { ) {
let item = render_enum_variant(RenderContext::new(ctx), None, local_name, variant, None); let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None);
self.add(item); self.add(item);
} }
} }

View file

@ -23,7 +23,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
def, def,
hir::ModuleDef::Adt(hir::Adt::Enum(..)) hir::ModuleDef::Adt(hir::Adt::Enum(..))
| hir::ModuleDef::Adt(hir::Adt::Struct(..)) | hir::ModuleDef::Adt(hir::Adt::Struct(..))
| hir::ModuleDef::EnumVariant(..) | hir::ModuleDef::Variant(..)
| hir::ModuleDef::Const(..) | hir::ModuleDef::Const(..)
| hir::ModuleDef::Module(..) | hir::ModuleDef::Module(..)
) )

View file

@ -19,7 +19,7 @@ use crate::{
CompletionKind, CompletionScore, CompletionKind, CompletionScore,
}; };
use crate::render::{enum_variant::render_enum_variant, function::render_fn, macro_::render_macro}; use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro};
pub(crate) fn render_field<'a>( pub(crate) fn render_field<'a>(
ctx: RenderContext<'a>, ctx: RenderContext<'a>,
@ -159,9 +159,8 @@ impl<'a> Render<'a> {
let item = render_fn(self.ctx, import_to_add, Some(local_name), *func); let item = render_fn(self.ctx, import_to_add, Some(local_name), *func);
return Some(item); return Some(item);
} }
ScopeDef::ModuleDef(EnumVariant(var)) => { ScopeDef::ModuleDef(Variant(var)) => {
let item = let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None);
render_enum_variant(self.ctx, import_to_add, Some(local_name), *var, None);
return Some(item); return Some(item);
} }
ScopeDef::MacroDef(mac) => { ScopeDef::MacroDef(mac) => {
@ -257,7 +256,7 @@ impl<'a> Render<'a> {
match resolution { match resolution {
ScopeDef::ModuleDef(Module(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Module(it)) => it.docs(self.ctx.db()),
ScopeDef::ModuleDef(Adt(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Adt(it)) => it.docs(self.ctx.db()),
ScopeDef::ModuleDef(EnumVariant(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Variant(it)) => it.docs(self.ctx.db()),
ScopeDef::ModuleDef(Const(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Const(it)) => it.docs(self.ctx.db()),
ScopeDef::ModuleDef(Static(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Static(it)) => it.docs(self.ctx.db()),
ScopeDef::ModuleDef(Trait(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Trait(it)) => it.docs(self.ctx.db()),

View file

@ -9,35 +9,35 @@ use crate::{
render::{builder_ext::Params, RenderContext}, render::{builder_ext::Params, RenderContext},
}; };
pub(crate) fn render_enum_variant<'a>( pub(crate) fn render_variant<'a>(
ctx: RenderContext<'a>, ctx: RenderContext<'a>,
import_to_add: Option<ImportEdit>, import_to_add: Option<ImportEdit>,
local_name: Option<String>, local_name: Option<String>,
variant: hir::EnumVariant, variant: hir::Variant,
path: Option<ModPath>, path: Option<ModPath>,
) -> CompletionItem { ) -> CompletionItem {
let _p = profile::span("render_enum_variant"); let _p = profile::span("render_enum_variant");
EnumVariantRender::new(ctx, local_name, variant, path).render(import_to_add) EnumRender::new(ctx, local_name, variant, path).render(import_to_add)
} }
#[derive(Debug)] #[derive(Debug)]
struct EnumVariantRender<'a> { struct EnumRender<'a> {
ctx: RenderContext<'a>, ctx: RenderContext<'a>,
name: String, name: String,
variant: hir::EnumVariant, variant: hir::Variant,
path: Option<ModPath>, path: Option<ModPath>,
qualified_name: String, qualified_name: String,
short_qualified_name: String, short_qualified_name: String,
variant_kind: StructKind, variant_kind: StructKind,
} }
impl<'a> EnumVariantRender<'a> { impl<'a> EnumRender<'a> {
fn new( fn new(
ctx: RenderContext<'a>, ctx: RenderContext<'a>,
local_name: Option<String>, local_name: Option<String>,
variant: hir::EnumVariant, variant: hir::Variant,
path: Option<ModPath>, path: Option<ModPath>,
) -> EnumVariantRender<'a> { ) -> EnumRender<'a> {
let name = local_name.unwrap_or_else(|| variant.name(ctx.db()).to_string()); let name = local_name.unwrap_or_else(|| variant.name(ctx.db()).to_string());
let variant_kind = variant.kind(ctx.db()); let variant_kind = variant.kind(ctx.db());
@ -51,15 +51,7 @@ impl<'a> EnumVariantRender<'a> {
None => (name.to_string(), name.to_string()), None => (name.to_string(), name.to_string()),
}; };
EnumVariantRender { EnumRender { ctx, name, variant, path, qualified_name, short_qualified_name, variant_kind }
ctx,
name,
variant,
path,
qualified_name,
short_qualified_name,
variant_kind,
}
} }
fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {

View file

@ -10,8 +10,8 @@ use hir_ty::db::HirDatabase;
use syntax::ast; use syntax::ast;
use crate::{ use crate::{
Adt, Const, Enum, EnumVariant, Field, Function, MacroDef, Module, ModuleDef, Static, Struct, Adt, Const, Enum, Field, Function, MacroDef, Module, ModuleDef, Static, Struct, Trait,
Trait, TypeAlias, Union, TypeAlias, Union, Variant,
}; };
pub trait HasAttrs { pub trait HasAttrs {
@ -53,7 +53,7 @@ macro_rules! impl_has_attrs {
impl_has_attrs![ impl_has_attrs![
(Field, FieldId), (Field, FieldId),
(EnumVariant, EnumVariantId), (Variant, EnumVariantId),
(Static, StaticId), (Static, StaticId),
(Const, ConstId), (Const, ConstId),
(Trait, TraitId), (Trait, TraitId),

View file

@ -161,7 +161,7 @@ pub enum ModuleDef {
Function(Function), Function(Function),
Adt(Adt), Adt(Adt),
// Can't be directly declared, but can be imported. // Can't be directly declared, but can be imported.
EnumVariant(EnumVariant), Variant(Variant),
Const(Const), Const(Const),
Static(Static), Static(Static),
Trait(Trait), Trait(Trait),
@ -172,7 +172,7 @@ impl_from!(
Module, Module,
Function, Function,
Adt(Struct, Enum, Union), Adt(Struct, Enum, Union),
EnumVariant, Variant,
Const, Const,
Static, Static,
Trait, Trait,
@ -186,7 +186,7 @@ impl From<VariantDef> for ModuleDef {
match var { match var {
VariantDef::Struct(t) => Adt::from(t).into(), VariantDef::Struct(t) => Adt::from(t).into(),
VariantDef::Union(t) => Adt::from(t).into(), VariantDef::Union(t) => Adt::from(t).into(),
VariantDef::EnumVariant(t) => t.into(), VariantDef::Variant(t) => t.into(),
} }
} }
} }
@ -197,7 +197,7 @@ impl ModuleDef {
ModuleDef::Module(it) => it.parent(db), ModuleDef::Module(it) => it.parent(db),
ModuleDef::Function(it) => Some(it.module(db)), ModuleDef::Function(it) => Some(it.module(db)),
ModuleDef::Adt(it) => Some(it.module(db)), ModuleDef::Adt(it) => Some(it.module(db)),
ModuleDef::EnumVariant(it) => Some(it.module(db)), ModuleDef::Variant(it) => Some(it.module(db)),
ModuleDef::Const(it) => Some(it.module(db)), ModuleDef::Const(it) => Some(it.module(db)),
ModuleDef::Static(it) => Some(it.module(db)), ModuleDef::Static(it) => Some(it.module(db)),
ModuleDef::Trait(it) => Some(it.module(db)), ModuleDef::Trait(it) => Some(it.module(db)),
@ -221,7 +221,7 @@ impl ModuleDef {
ModuleDef::Module(it) => it.parent(db)?, ModuleDef::Module(it) => it.parent(db)?,
ModuleDef::Function(it) => return Some(it.visibility(db)), ModuleDef::Function(it) => return Some(it.visibility(db)),
ModuleDef::Adt(it) => it.module(db), ModuleDef::Adt(it) => it.module(db),
ModuleDef::EnumVariant(it) => { ModuleDef::Variant(it) => {
let parent = it.parent_enum(db); let parent = it.parent_enum(db);
let module = it.module(db); let module = it.module(db);
return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent))); return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent)));
@ -241,7 +241,7 @@ impl ModuleDef {
ModuleDef::Adt(it) => Some(it.name(db)), ModuleDef::Adt(it) => Some(it.name(db)),
ModuleDef::Trait(it) => Some(it.name(db)), ModuleDef::Trait(it) => Some(it.name(db)),
ModuleDef::Function(it) => Some(it.name(db)), ModuleDef::Function(it) => Some(it.name(db)),
ModuleDef::EnumVariant(it) => Some(it.name(db)), ModuleDef::Variant(it) => Some(it.name(db)),
ModuleDef::TypeAlias(it) => Some(it.name(db)), ModuleDef::TypeAlias(it) => Some(it.name(db)),
ModuleDef::Module(it) => it.name(db), ModuleDef::Module(it) => it.name(db),
ModuleDef::Const(it) => it.name(db), ModuleDef::Const(it) => it.name(db),
@ -455,7 +455,7 @@ impl Field {
let generic_def_id: GenericDefId = match self.parent { let generic_def_id: GenericDefId = match self.parent {
VariantDef::Struct(it) => it.id.into(), VariantDef::Struct(it) => it.id.into(),
VariantDef::Union(it) => it.id.into(), VariantDef::Union(it) => it.id.into(),
VariantDef::EnumVariant(it) => it.parent.id.into(), VariantDef::Variant(it) => it.parent.id.into(),
}; };
let substs = Substs::type_params(db, generic_def_id); let substs = Substs::type_params(db, generic_def_id);
let ty = db.field_types(var_id)[self.id].clone().subst(&substs); let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
@ -566,12 +566,8 @@ impl Enum {
db.enum_data(self.id).name.clone() db.enum_data(self.id).name.clone()
} }
pub fn variants(self, db: &dyn HirDatabase) -> Vec<EnumVariant> { pub fn variants(self, db: &dyn HirDatabase) -> Vec<Variant> {
db.enum_data(self.id) db.enum_data(self.id).variants.iter().map(|(id, _)| Variant { parent: self, id }).collect()
.variants
.iter()
.map(|(id, _)| EnumVariant { parent: self, id })
.collect()
} }
pub fn ty(self, db: &dyn HirDatabase) -> Type { pub fn ty(self, db: &dyn HirDatabase) -> Type {
@ -580,12 +576,12 @@ impl Enum {
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct EnumVariant { pub struct Variant {
pub(crate) parent: Enum, pub(crate) parent: Enum,
pub(crate) id: LocalEnumVariantId, pub(crate) id: LocalEnumVariantId,
} }
impl EnumVariant { impl Variant {
pub fn module(self, db: &dyn HirDatabase) -> Module { pub fn module(self, db: &dyn HirDatabase) -> Module {
self.parent.module(db) self.parent.module(db)
} }
@ -662,16 +658,16 @@ impl Adt {
pub enum VariantDef { pub enum VariantDef {
Struct(Struct), Struct(Struct),
Union(Union), Union(Union),
EnumVariant(EnumVariant), Variant(Variant),
} }
impl_from!(Struct, Union, EnumVariant for VariantDef); impl_from!(Struct, Union, Variant for VariantDef);
impl VariantDef { impl VariantDef {
pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
match self { match self {
VariantDef::Struct(it) => it.fields(db), VariantDef::Struct(it) => it.fields(db),
VariantDef::Union(it) => it.fields(db), VariantDef::Union(it) => it.fields(db),
VariantDef::EnumVariant(it) => it.fields(db), VariantDef::Variant(it) => it.fields(db),
} }
} }
@ -679,7 +675,7 @@ impl VariantDef {
match self { match self {
VariantDef::Struct(it) => it.module(db), VariantDef::Struct(it) => it.module(db),
VariantDef::Union(it) => it.module(db), VariantDef::Union(it) => it.module(db),
VariantDef::EnumVariant(it) => it.module(db), VariantDef::Variant(it) => it.module(db),
} }
} }
@ -687,7 +683,7 @@ impl VariantDef {
match self { match self {
VariantDef::Struct(s) => s.name(db), VariantDef::Struct(s) => s.name(db),
VariantDef::Union(u) => u.name(db), VariantDef::Union(u) => u.name(db),
VariantDef::EnumVariant(e) => e.name(db), VariantDef::Variant(e) => e.name(db),
} }
} }
@ -695,7 +691,7 @@ impl VariantDef {
match self { match self {
VariantDef::Struct(it) => it.variant_data(db), VariantDef::Struct(it) => it.variant_data(db),
VariantDef::Union(it) => it.variant_data(db), VariantDef::Union(it) => it.variant_data(db),
VariantDef::EnumVariant(it) => it.variant_data(db), VariantDef::Variant(it) => it.variant_data(db),
} }
} }
} }
@ -1095,7 +1091,7 @@ pub enum GenericDef {
Impl(Impl), Impl(Impl),
// enum variants cannot have generics themselves, but their parent enums // enum variants cannot have generics themselves, but their parent enums
// can, and this makes some code easier to write // can, and this makes some code easier to write
EnumVariant(EnumVariant), Variant(Variant),
// consts can have type parameters from their parents (i.e. associated consts of traits) // consts can have type parameters from their parents (i.e. associated consts of traits)
Const(Const), Const(Const),
} }
@ -1105,7 +1101,7 @@ impl_from!(
Trait, Trait,
TypeAlias, TypeAlias,
Impl, Impl,
EnumVariant, Variant,
Const Const
for GenericDef for GenericDef
); );
@ -1847,7 +1843,7 @@ pub struct Callable {
pub enum CallableKind { pub enum CallableKind {
Function(Function), Function(Function),
TupleStruct(Struct), TupleStruct(Struct),
TupleEnumVariant(EnumVariant), TupleEnumVariant(Variant),
Closure, Closure,
} }

View file

@ -9,8 +9,7 @@ use hir_def::{
}; };
use crate::{ use crate::{
Adt, AssocItem, DefWithBody, EnumVariant, Field, GenericDef, Local, MacroDef, ModuleDef, Adt, AssocItem, DefWithBody, Field, GenericDef, Local, MacroDef, ModuleDef, Variant, VariantDef,
VariantDef,
}; };
macro_rules! from_id { macro_rules! from_id {
@ -65,14 +64,14 @@ impl From<Adt> for AdtId {
} }
} }
impl From<EnumVariantId> for EnumVariant { impl From<EnumVariantId> for Variant {
fn from(id: EnumVariantId) -> Self { fn from(id: EnumVariantId) -> Self {
EnumVariant { parent: id.parent.into(), id: id.local_id } Variant { parent: id.parent.into(), id: id.local_id }
} }
} }
impl From<EnumVariant> for EnumVariantId { impl From<Variant> for EnumVariantId {
fn from(def: EnumVariant) -> Self { fn from(def: Variant) -> Self {
EnumVariantId { parent: def.parent.id, local_id: def.id } EnumVariantId { parent: def.parent.id, local_id: def.id }
} }
} }
@ -83,7 +82,7 @@ impl From<ModuleDefId> for ModuleDef {
ModuleDefId::ModuleId(it) => ModuleDef::Module(it.into()), ModuleDefId::ModuleId(it) => ModuleDef::Module(it.into()),
ModuleDefId::FunctionId(it) => ModuleDef::Function(it.into()), ModuleDefId::FunctionId(it) => ModuleDef::Function(it.into()),
ModuleDefId::AdtId(it) => ModuleDef::Adt(it.into()), ModuleDefId::AdtId(it) => ModuleDef::Adt(it.into()),
ModuleDefId::EnumVariantId(it) => ModuleDef::EnumVariant(it.into()), ModuleDefId::EnumVariantId(it) => ModuleDef::Variant(it.into()),
ModuleDefId::ConstId(it) => ModuleDef::Const(it.into()), ModuleDefId::ConstId(it) => ModuleDef::Const(it.into()),
ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()), ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()),
ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()), ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()),
@ -99,7 +98,7 @@ impl From<ModuleDef> for ModuleDefId {
ModuleDef::Module(it) => ModuleDefId::ModuleId(it.into()), ModuleDef::Module(it) => ModuleDefId::ModuleId(it.into()),
ModuleDef::Function(it) => ModuleDefId::FunctionId(it.into()), ModuleDef::Function(it) => ModuleDefId::FunctionId(it.into()),
ModuleDef::Adt(it) => ModuleDefId::AdtId(it.into()), ModuleDef::Adt(it) => ModuleDefId::AdtId(it.into()),
ModuleDef::EnumVariant(it) => ModuleDefId::EnumVariantId(it.into()), ModuleDef::Variant(it) => ModuleDefId::EnumVariantId(it.into()),
ModuleDef::Const(it) => ModuleDefId::ConstId(it.into()), ModuleDef::Const(it) => ModuleDefId::ConstId(it.into()),
ModuleDef::Static(it) => ModuleDefId::StaticId(it.into()), ModuleDef::Static(it) => ModuleDefId::StaticId(it.into()),
ModuleDef::Trait(it) => ModuleDefId::TraitId(it.into()), ModuleDef::Trait(it) => ModuleDefId::TraitId(it.into()),
@ -147,7 +146,7 @@ impl From<GenericDef> for GenericDefId {
GenericDef::Trait(it) => GenericDefId::TraitId(it.id), GenericDef::Trait(it) => GenericDefId::TraitId(it.id),
GenericDef::TypeAlias(it) => GenericDefId::TypeAliasId(it.id), GenericDef::TypeAlias(it) => GenericDefId::TypeAliasId(it.id),
GenericDef::Impl(it) => GenericDefId::ImplId(it.id), GenericDef::Impl(it) => GenericDefId::ImplId(it.id),
GenericDef::EnumVariant(it) => { GenericDef::Variant(it) => {
GenericDefId::EnumVariantId(EnumVariantId { parent: it.parent.id, local_id: it.id }) GenericDefId::EnumVariantId(EnumVariantId { parent: it.parent.id, local_id: it.id })
} }
GenericDef::Const(it) => GenericDefId::ConstId(it.id), GenericDef::Const(it) => GenericDefId::ConstId(it.id),
@ -164,7 +163,7 @@ impl From<GenericDefId> for GenericDef {
GenericDefId::TypeAliasId(it) => GenericDef::TypeAlias(it.into()), GenericDefId::TypeAliasId(it) => GenericDef::TypeAlias(it.into()),
GenericDefId::ImplId(it) => GenericDef::Impl(it.into()), GenericDefId::ImplId(it) => GenericDef::Impl(it.into()),
GenericDefId::EnumVariantId(it) => { GenericDefId::EnumVariantId(it) => {
GenericDef::EnumVariant(EnumVariant { parent: it.parent.into(), id: it.local_id }) GenericDef::Variant(Variant { parent: it.parent.into(), id: it.local_id })
} }
GenericDefId::ConstId(it) => GenericDef::Const(it.into()), GenericDefId::ConstId(it) => GenericDef::Const(it.into()),
} }
@ -185,7 +184,7 @@ impl From<VariantId> for VariantDef {
fn from(def: VariantId) -> Self { fn from(def: VariantId) -> Self {
match def { match def {
VariantId::StructId(it) => VariantDef::Struct(it.into()), VariantId::StructId(it) => VariantDef::Struct(it.into()),
VariantId::EnumVariantId(it) => VariantDef::EnumVariant(it.into()), VariantId::EnumVariantId(it) => VariantDef::Variant(it.into()),
VariantId::UnionId(it) => VariantDef::Union(it.into()), VariantId::UnionId(it) => VariantDef::Union(it.into()),
} }
} }
@ -195,7 +194,7 @@ impl From<VariantDef> for VariantId {
fn from(def: VariantDef) -> Self { fn from(def: VariantDef) -> Self {
match def { match def {
VariantDef::Struct(it) => VariantId::StructId(it.id), VariantDef::Struct(it) => VariantId::StructId(it.id),
VariantDef::EnumVariant(it) => VariantId::EnumVariantId(it.into()), VariantDef::Variant(it) => VariantId::EnumVariantId(it.into()),
VariantDef::Union(it) => VariantId::UnionId(it.id), VariantDef::Union(it) => VariantId::UnionId(it.id),
} }
} }

View file

@ -10,8 +10,8 @@ use hir_expand::InFile;
use syntax::ast; use syntax::ast;
use crate::{ use crate::{
db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, Impl, LifetimeParam, db::HirDatabase, Const, Enum, Field, FieldSource, Function, Impl, LifetimeParam, MacroDef,
MacroDef, Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, Variant,
}; };
pub trait HasSource { pub trait HasSource {
@ -73,7 +73,7 @@ impl HasSource for Enum {
self.id.lookup(db.upcast()).source(db.upcast()) self.id.lookup(db.upcast()).source(db.upcast())
} }
} }
impl HasSource for EnumVariant { impl HasSource for Variant {
type Ast = ast::Variant; type Ast = ast::Variant;
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Variant> { fn source(self, db: &dyn HirDatabase) -> InFile<ast::Variant> {
self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone()) self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone())

View file

@ -34,9 +34,9 @@ pub use crate::{
attrs::{HasAttrs, Namespace}, attrs::{HasAttrs, Namespace},
code_model::{ code_model::{
Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const,
Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, Crate, CrateDependency, DefWithBody, Enum, Field, FieldSource, Function, GenericDef,
GenericDef, HasVisibility, Impl, LifetimeParam, Local, MacroDef, Module, ModuleDef, HasVisibility, Impl, LifetimeParam, Local, MacroDef, Module, ModuleDef, ScopeDef, Static,
ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Struct, Trait, Type, TypeAlias, TypeParam, Union, Variant, VariantDef,
}, },
has_source::HasSource, has_source::HasSource,
semantics::{PathResolution, Semantics, SemanticsScope}, semantics::{PathResolution, Semantics, SemanticsScope},

View file

@ -51,7 +51,7 @@ impl PathResolution {
Some(TypeNs::BuiltinType(*builtin)) Some(TypeNs::BuiltinType(*builtin))
} }
PathResolution::Def(ModuleDef::Const(_)) PathResolution::Def(ModuleDef::Const(_))
| PathResolution::Def(ModuleDef::EnumVariant(_)) | PathResolution::Def(ModuleDef::Variant(_))
| PathResolution::Def(ModuleDef::Function(_)) | PathResolution::Def(ModuleDef::Function(_))
| PathResolution::Def(ModuleDef::Module(_)) | PathResolution::Def(ModuleDef::Module(_))
| PathResolution::Def(ModuleDef::Static(_)) | PathResolution::Def(ModuleDef::Static(_))
@ -715,7 +715,7 @@ to_def_impls![
(crate::Function, ast::Fn, fn_to_def), (crate::Function, ast::Fn, fn_to_def),
(crate::Field, ast::RecordField, record_field_to_def), (crate::Field, ast::RecordField, record_field_to_def),
(crate::Field, ast::TupleField, tuple_field_to_def), (crate::Field, ast::TupleField, tuple_field_to_def),
(crate::EnumVariant, ast::Variant, enum_variant_to_def), (crate::Variant, ast::Variant, enum_variant_to_def),
(crate::TypeParam, ast::TypeParam, type_param_to_def), (crate::TypeParam, ast::TypeParam, type_param_to_def),
(crate::LifetimeParam, ast::LifetimeParam, lifetime_param_to_def), (crate::LifetimeParam, ast::LifetimeParam, lifetime_param_to_def),
(crate::MacroDef, ast::MacroRules, macro_rules_to_def), (crate::MacroDef, ast::MacroRules, macro_rules_to_def),

View file

@ -28,8 +28,8 @@ use syntax::{
}; };
use crate::{ use crate::{
db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Field, Function, Local, db::HirDatabase, semantics::PathResolution, Adt, Const, Field, Function, Local, MacroDef,
MacroDef, ModuleDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, ModuleDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Variant,
}; };
use base_db::CrateId; use base_db::CrateId;
@ -230,7 +230,7 @@ impl SourceAnalyzer {
if let Some(VariantId::EnumVariantId(variant)) = if let Some(VariantId::EnumVariantId(variant)) =
self.infer.as_ref()?.variant_resolution_for_expr(expr_id) self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
{ {
return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
} }
} }
@ -242,7 +242,7 @@ impl SourceAnalyzer {
if let Some(VariantId::EnumVariantId(variant)) = if let Some(VariantId::EnumVariantId(variant)) =
self.infer.as_ref()?.variant_resolution_for_pat(pat_id) self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
{ {
return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
} }
} }
@ -251,7 +251,7 @@ impl SourceAnalyzer {
if let Some(VariantId::EnumVariantId(variant)) = if let Some(VariantId::EnumVariantId(variant)) =
self.infer.as_ref()?.variant_resolution_for_expr(expr_id) self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
{ {
return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
} }
} }
@ -260,7 +260,7 @@ impl SourceAnalyzer {
if let Some(VariantId::EnumVariantId(variant)) = if let Some(VariantId::EnumVariantId(variant)) =
self.infer.as_ref()?.variant_resolution_for_pat(pat_id) self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
{ {
return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
} }
} }
@ -459,7 +459,7 @@ pub(crate) fn resolve_hir_path(
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => {
PathResolution::Def(Adt::from(it).into()) PathResolution::Def(Adt::from(it).into())
} }
TypeNs::EnumVariantId(it) => PathResolution::Def(EnumVariant::from(it).into()), TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), TypeNs::BuiltinType(it) => PathResolution::Def(it.into()),
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
@ -477,7 +477,7 @@ pub(crate) fn resolve_hir_path(
ValueNs::ConstId(it) => PathResolution::Def(Const::from(it).into()), ValueNs::ConstId(it) => PathResolution::Def(Const::from(it).into()),
ValueNs::StaticId(it) => PathResolution::Def(Static::from(it).into()), ValueNs::StaticId(it) => PathResolution::Def(Static::from(it).into()),
ValueNs::StructId(it) => PathResolution::Def(Struct::from(it).into()), ValueNs::StructId(it) => PathResolution::Def(Struct::from(it).into()),
ValueNs::EnumVariantId(it) => PathResolution::Def(EnumVariant::from(it).into()), ValueNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
ValueNs::ImplSelf(impl_id) => PathResolution::SelfType(impl_id.into()), ValueNs::ImplSelf(impl_id) => PathResolution::SelfType(impl_id.into()),
}; };
Some(res) Some(res)
@ -526,7 +526,7 @@ fn resolve_hir_path_qualifier(
TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }), TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }),
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()), TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()),
TypeNs::EnumVariantId(it) => PathResolution::Def(EnumVariant::from(it).into()), TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), TypeNs::BuiltinType(it) => PathResolution::Def(it.into()),
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),

View file

@ -166,7 +166,7 @@ fn missing_record_expr_field_fix(
def_file_id = source.file_id; def_file_id = source.file_id;
source.value.record_field_list()? source.value.record_field_list()?
} }
VariantDef::EnumVariant(e) => { VariantDef::Variant(e) => {
module = e.module(sema.db); module = e.module(sema.db);
let source = e.source(sema.db); let source = e.source(sema.db);
def_file_id = source.file_id; def_file_id = source.file_id;

View file

@ -233,7 +233,7 @@ impl TryToNav for hir::ModuleDef {
hir::ModuleDef::Module(it) => it.to_nav(db), hir::ModuleDef::Module(it) => it.to_nav(db),
hir::ModuleDef::Function(it) => it.to_nav(db), hir::ModuleDef::Function(it) => it.to_nav(db),
hir::ModuleDef::Adt(it) => it.to_nav(db), hir::ModuleDef::Adt(it) => it.to_nav(db),
hir::ModuleDef::EnumVariant(it) => it.to_nav(db), hir::ModuleDef::Variant(it) => it.to_nav(db),
hir::ModuleDef::Const(it) => it.to_nav(db), hir::ModuleDef::Const(it) => it.to_nav(db),
hir::ModuleDef::Static(it) => it.to_nav(db), hir::ModuleDef::Static(it) => it.to_nav(db),
hir::ModuleDef::Trait(it) => it.to_nav(db), hir::ModuleDef::Trait(it) => it.to_nav(db),
@ -262,7 +262,7 @@ impl ToNavFromAst for hir::Struct {
impl ToNavFromAst for hir::Enum { impl ToNavFromAst for hir::Enum {
const KIND: SymbolKind = SymbolKind::Enum; const KIND: SymbolKind = SymbolKind::Enum;
} }
impl ToNavFromAst for hir::EnumVariant { impl ToNavFromAst for hir::Variant {
const KIND: SymbolKind = SymbolKind::Variant; const KIND: SymbolKind = SymbolKind::Variant;
} }
impl ToNavFromAst for hir::Union { impl ToNavFromAst for hir::Union {

View file

@ -181,7 +181,7 @@ fn rewrite_intra_doc_link(
ModuleDef::Module(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Module(it) => it.resolve_doc_path(db, link, ns),
ModuleDef::Function(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Function(it) => it.resolve_doc_path(db, link, ns),
ModuleDef::Adt(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Adt(it) => it.resolve_doc_path(db, link, ns),
ModuleDef::EnumVariant(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Variant(it) => it.resolve_doc_path(db, link, ns),
ModuleDef::Const(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Const(it) => it.resolve_doc_path(db, link, ns),
ModuleDef::Static(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Static(it) => it.resolve_doc_path(db, link, ns),
ModuleDef::Trait(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Trait(it) => it.resolve_doc_path(db, link, ns),
@ -390,7 +390,7 @@ fn get_symbol_filename(db: &dyn HirDatabase, definition: &ModuleDef) -> Option<S
ModuleDef::TypeAlias(t) => format!("type.{}.html", t.name(db)), ModuleDef::TypeAlias(t) => format!("type.{}.html", t.name(db)),
ModuleDef::BuiltinType(t) => format!("primitive.{}.html", t.as_name()), ModuleDef::BuiltinType(t) => format!("primitive.{}.html", t.as_name()),
ModuleDef::Function(f) => format!("fn.{}.html", f.name(db)), ModuleDef::Function(f) => format!("fn.{}.html", f.name(db)),
ModuleDef::EnumVariant(ev) => { ModuleDef::Variant(ev) => {
format!("enum.{}.html#variant.{}", ev.parent_enum(db).name(db), ev.name(db)) format!("enum.{}.html#variant.{}", ev.parent_enum(db).name(db), ev.name(db))
} }
ModuleDef::Const(c) => format!("const.{}.html", c.name(db)?), ModuleDef::Const(c) => format!("const.{}.html", c.name(db)?),

View file

@ -297,7 +297,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
AssocItemContainer::Trait(t) => Some(t.name(db)), AssocItemContainer::Trait(t) => Some(t.name(db)),
AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)), AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
}, },
ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)), ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
_ => None, _ => None,
}, },
_ => None, _ => None,
@ -355,7 +355,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path), ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path),
ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path), ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path),
ModuleDef::EnumVariant(it) => from_def_source(db, it, mod_path), ModuleDef::Variant(it) => from_def_source(db, it, mod_path),
ModuleDef::Const(it) => from_def_source(db, it, mod_path), ModuleDef::Const(it) => from_def_source(db, it, mod_path),
ModuleDef::Static(it) => from_def_source(db, it, mod_path), ModuleDef::Static(it) => from_def_source(db, it, mod_path),
ModuleDef::Trait(it) => from_def_source(db, it, mod_path), ModuleDef::Trait(it) => from_def_source(db, it, mod_path),

View file

@ -167,7 +167,7 @@ fn module_def_doctest(sema: &Semantics<RootDatabase>, def: hir::ModuleDef) -> Op
hir::ModuleDef::Module(it) => it.attrs(sema.db), hir::ModuleDef::Module(it) => it.attrs(sema.db),
hir::ModuleDef::Function(it) => it.attrs(sema.db), hir::ModuleDef::Function(it) => it.attrs(sema.db),
hir::ModuleDef::Adt(it) => it.attrs(sema.db), hir::ModuleDef::Adt(it) => it.attrs(sema.db),
hir::ModuleDef::EnumVariant(it) => it.attrs(sema.db), hir::ModuleDef::Variant(it) => it.attrs(sema.db),
hir::ModuleDef::Const(it) => it.attrs(sema.db), hir::ModuleDef::Const(it) => it.attrs(sema.db),
hir::ModuleDef::Static(it) => it.attrs(sema.db), hir::ModuleDef::Static(it) => it.attrs(sema.db),
hir::ModuleDef::Trait(it) => it.attrs(sema.db), hir::ModuleDef::Trait(it) => it.attrs(sema.db),

View file

@ -781,7 +781,7 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Symbol(SymbolKind::Struct), hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Symbol(SymbolKind::Struct),
hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum), hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum),
hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union), hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union),
hir::ModuleDef::EnumVariant(_) => HighlightTag::Symbol(SymbolKind::Variant), hir::ModuleDef::Variant(_) => HighlightTag::Symbol(SymbolKind::Variant),
hir::ModuleDef::Const(konst) => { hir::ModuleDef::Const(konst) => {
let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Const)); let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Const));
if konst.as_assoc_item(db).is_some() { if konst.as_assoc_item(db).is_some() {

View file

@ -66,7 +66,7 @@ impl Definition {
hir::Adt::Union(it) => it.name(db), hir::Adt::Union(it) => it.name(db),
hir::Adt::Enum(it) => it.name(db), hir::Adt::Enum(it) => it.name(db),
}, },
hir::ModuleDef::EnumVariant(it) => it.name(db), hir::ModuleDef::Variant(it) => it.name(db),
hir::ModuleDef::Const(it) => it.name(db)?, hir::ModuleDef::Const(it) => it.name(db)?,
hir::ModuleDef::Static(it) => it.name(db)?, hir::ModuleDef::Static(it) => it.name(db)?,
hir::ModuleDef::Trait(it) => it.name(db), hir::ModuleDef::Trait(it) => it.name(db),
@ -207,7 +207,7 @@ impl NameClass {
Some(NameClass::Definition(Definition::ModuleDef(def.into()))) Some(NameClass::Definition(Definition::ModuleDef(def.into())))
}, },
ast::Variant(it) => { ast::Variant(it) => {
let def: hir::EnumVariant = sema.to_def(&it)?; let def: hir::Variant = sema.to_def(&it)?;
Some(NameClass::Definition(Definition::ModuleDef(def.into()))) Some(NameClass::Definition(Definition::ModuleDef(def.into())))
}, },
ast::Fn(it) => { ast::Fn(it) => {

View file

@ -141,7 +141,7 @@ impl Definition {
hir::GenericDef::Trait(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::Trait(it) => it.source(db).value.syntax().text_range(),
hir::GenericDef::TypeAlias(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::TypeAlias(it) => it.source(db).value.syntax().text_range(),
hir::GenericDef::Impl(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::Impl(it) => it.source(db).value.syntax().text_range(),
hir::GenericDef::EnumVariant(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::Variant(it) => it.source(db).value.syntax().text_range(),
hir::GenericDef::Const(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::Const(it) => it.source(db).value.syntax().text_range(),
}; };
let mut res = FxHashMap::default(); let mut res = FxHashMap::default();