mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
rename XSignature -> XData
This commit is contained in:
parent
1541b2d689
commit
0caec7d250
10 changed files with 66 additions and 70 deletions
|
@ -519,9 +519,8 @@ pub struct Function {
|
|||
pub(crate) id: FunctionId,
|
||||
}
|
||||
|
||||
/// The declared signature of a function.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FnSignature {
|
||||
pub struct FnData {
|
||||
pub(crate) name: Name,
|
||||
pub(crate) params: Vec<TypeRef>,
|
||||
pub(crate) ret_type: TypeRef,
|
||||
|
@ -530,11 +529,11 @@ pub struct FnSignature {
|
|||
pub(crate) has_self_param: bool,
|
||||
}
|
||||
|
||||
impl FnSignature {
|
||||
pub(crate) fn fn_signature_query(
|
||||
impl FnData {
|
||||
pub(crate) fn fn_data_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
func: Function,
|
||||
) -> Arc<FnSignature> {
|
||||
) -> Arc<FnData> {
|
||||
let src = func.source(db);
|
||||
let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
|
||||
let mut params = Vec::new();
|
||||
|
@ -569,7 +568,7 @@ impl FnSignature {
|
|||
TypeRef::unit()
|
||||
};
|
||||
|
||||
let sig = FnSignature { name, params, ret_type, has_self_param };
|
||||
let sig = FnData { name, params, ret_type, has_self_param };
|
||||
Arc::new(sig)
|
||||
}
|
||||
pub fn name(&self) -> &Name {
|
||||
|
@ -597,7 +596,7 @@ impl Function {
|
|||
}
|
||||
|
||||
pub fn name(self, db: &impl HirDatabase) -> Name {
|
||||
self.signature(db).name.clone()
|
||||
self.data(db).name.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
||||
|
@ -612,8 +611,8 @@ impl Function {
|
|||
db.type_for_def(self.into(), Namespace::Values)
|
||||
}
|
||||
|
||||
pub fn signature(self, db: &impl HirDatabase) -> Arc<FnSignature> {
|
||||
db.fn_signature(self)
|
||||
pub fn data(self, db: &impl HirDatabase) -> Arc<FnData> {
|
||||
db.fn_data(self)
|
||||
}
|
||||
|
||||
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
||||
|
@ -670,8 +669,8 @@ impl Const {
|
|||
self.id.module(db)
|
||||
}
|
||||
|
||||
pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> {
|
||||
db.const_signature(self)
|
||||
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
||||
db.const_data(self)
|
||||
}
|
||||
|
||||
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
||||
|
@ -696,14 +695,13 @@ impl Const {
|
|||
}
|
||||
}
|
||||
|
||||
/// The declared signature of a const.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ConstSignature {
|
||||
pub struct ConstData {
|
||||
pub(crate) name: Name,
|
||||
pub(crate) type_ref: TypeRef,
|
||||
}
|
||||
|
||||
impl ConstSignature {
|
||||
impl ConstData {
|
||||
pub fn name(&self) -> &Name {
|
||||
&self.name
|
||||
}
|
||||
|
@ -712,27 +710,27 @@ impl ConstSignature {
|
|||
&self.type_ref
|
||||
}
|
||||
|
||||
pub(crate) fn const_signature_query(
|
||||
pub(crate) fn const_data_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
konst: Const,
|
||||
) -> Arc<ConstSignature> {
|
||||
) -> Arc<ConstData> {
|
||||
let node = konst.source(db).ast;
|
||||
const_signature_for(&*node)
|
||||
const_data_for(&*node)
|
||||
}
|
||||
|
||||
pub(crate) fn static_signature_query(
|
||||
pub(crate) fn static_data_query(
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
konst: Static,
|
||||
) -> Arc<ConstSignature> {
|
||||
) -> Arc<ConstData> {
|
||||
let node = konst.source(db).ast;
|
||||
const_signature_for(&*node)
|
||||
const_data_for(&*node)
|
||||
}
|
||||
}
|
||||
|
||||
fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
|
||||
fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> {
|
||||
let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
|
||||
let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
|
||||
let sig = ConstSignature { name, type_ref };
|
||||
let sig = ConstData { name, type_ref };
|
||||
Arc::new(sig)
|
||||
}
|
||||
|
||||
|
@ -746,8 +744,8 @@ impl Static {
|
|||
self.id.module(db)
|
||||
}
|
||||
|
||||
pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> {
|
||||
db.static_signature(self)
|
||||
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
||||
db.static_data(self)
|
||||
}
|
||||
|
||||
/// Builds a resolver for code inside this item.
|
||||
|
|
|
@ -6,9 +6,9 @@ use ra_db::{SourceDatabase, salsa};
|
|||
|
||||
use crate::{
|
||||
HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, MacroCallLoc,
|
||||
Function, FnSignature, ExprScopes, TypeAlias,
|
||||
Function, FnData, ExprScopes, TypeAlias,
|
||||
Struct, Enum, StructField,
|
||||
Const, ConstSignature, Static,
|
||||
Const, ConstData, Static,
|
||||
DefWithBody, Trait,
|
||||
ids,
|
||||
nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap},
|
||||
|
@ -109,17 +109,17 @@ pub trait DefDatabase: SourceDatabase {
|
|||
#[salsa::invoke(crate::generics::GenericParams::generic_params_query)]
|
||||
fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>;
|
||||
|
||||
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
|
||||
fn fn_signature(&self, func: Function) -> Arc<FnSignature>;
|
||||
#[salsa::invoke(crate::FnData::fn_data_query)]
|
||||
fn fn_data(&self, func: Function) -> Arc<FnData>;
|
||||
|
||||
#[salsa::invoke(crate::type_alias::type_alias_data_query)]
|
||||
fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>;
|
||||
|
||||
#[salsa::invoke(crate::ConstSignature::const_signature_query)]
|
||||
fn const_signature(&self, konst: Const) -> Arc<ConstSignature>;
|
||||
#[salsa::invoke(crate::ConstData::const_data_query)]
|
||||
fn const_data(&self, konst: Const) -> Arc<ConstData>;
|
||||
|
||||
#[salsa::invoke(crate::ConstSignature::static_signature_query)]
|
||||
fn static_signature(&self, konst: Static) -> Arc<ConstSignature>;
|
||||
#[salsa::invoke(crate::ConstData::static_data_query)]
|
||||
fn static_data(&self, konst: Static) -> Arc<ConstData>;
|
||||
|
||||
#[salsa::invoke(crate::lang_item::LangItems::lang_items_query)]
|
||||
fn lang_items(&self, krate: Crate) -> Arc<LangItems>;
|
||||
|
|
|
@ -75,9 +75,9 @@ pub use self::code_model::{
|
|||
DefWithBody,
|
||||
Module, ModuleDef, ModuleSource,
|
||||
Struct, Union, Enum, EnumVariant,
|
||||
Function, FnSignature,
|
||||
Function, FnData,
|
||||
StructField, FieldSource,
|
||||
Static, Const, ConstSignature,
|
||||
Static, Const, ConstData,
|
||||
Trait, TypeAlias, MacroDef, Container,
|
||||
BuiltinType,
|
||||
src::{Source, HasSource},
|
||||
|
|
|
@ -27,7 +27,7 @@ use ra_prof::profile;
|
|||
use test_utils::tested_by;
|
||||
|
||||
use crate::{
|
||||
Function, StructField, Path, Name, FnSignature, AdtDef, ConstSignature, HirDatabase,
|
||||
Function, StructField, Path, Name, FnData, AdtDef, ConstData, HirDatabase,
|
||||
DefWithBody, ImplItem,
|
||||
type_ref::{TypeRef, Mutability},
|
||||
expr::{
|
||||
|
@ -59,9 +59,9 @@ pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResu
|
|||
let mut ctx = InferenceContext::new(db, body, resolver);
|
||||
|
||||
match def {
|
||||
DefWithBody::Const(ref c) => ctx.collect_const_signature(&c.signature(db)),
|
||||
DefWithBody::Function(ref f) => ctx.collect_fn_signature(&f.signature(db)),
|
||||
DefWithBody::Static(ref s) => ctx.collect_const_signature(&s.signature(db)),
|
||||
DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)),
|
||||
DefWithBody::Function(ref f) => ctx.collect_fn(&f.data(db)),
|
||||
DefWithBody::Static(ref s) => ctx.collect_const(&s.data(db)),
|
||||
}
|
||||
|
||||
ctx.infer_body();
|
||||
|
@ -509,8 +509,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
let item: crate::ModuleDef = ty.iterate_impl_items(self.db, krate, |item| {
|
||||
let matching_def: Option<crate::ModuleDef> = match item {
|
||||
crate::ImplItem::Method(func) => {
|
||||
let sig = func.signature(self.db);
|
||||
if segment.name == *sig.name() {
|
||||
if segment.name == func.name(self.db) {
|
||||
Some(func.into())
|
||||
} else {
|
||||
None
|
||||
|
@ -518,8 +517,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}
|
||||
|
||||
crate::ImplItem::Const(konst) => {
|
||||
let sig = konst.signature(self.db);
|
||||
if segment.name == *sig.name() {
|
||||
let data = konst.data(self.db);
|
||||
if segment.name == *data.name() {
|
||||
Some(konst.into())
|
||||
} else {
|
||||
None
|
||||
|
@ -1283,18 +1282,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
ty
|
||||
}
|
||||
|
||||
fn collect_const_signature(&mut self, signature: &ConstSignature) {
|
||||
self.return_ty = self.make_ty(signature.type_ref());
|
||||
fn collect_const(&mut self, data: &ConstData) {
|
||||
self.return_ty = self.make_ty(data.type_ref());
|
||||
}
|
||||
|
||||
fn collect_fn_signature(&mut self, signature: &FnSignature) {
|
||||
fn collect_fn(&mut self, data: &FnData) {
|
||||
let body = Arc::clone(&self.body); // avoid borrow checker problem
|
||||
for (type_ref, pat) in signature.params().iter().zip(body.params()) {
|
||||
for (type_ref, pat) in data.params().iter().zip(body.params()) {
|
||||
let ty = self.make_ty(type_ref);
|
||||
|
||||
self.infer_pat(*pat, &ty, BindingMode::default());
|
||||
}
|
||||
self.return_ty = self.make_ty(signature.ret_type());
|
||||
self.return_ty = self.make_ty(data.ret_type());
|
||||
}
|
||||
|
||||
fn infer_body(&mut self) {
|
||||
|
|
|
@ -353,11 +353,10 @@ pub(crate) fn generic_defaults(db: &impl HirDatabase, def: GenericDef) -> Substs
|
|||
}
|
||||
|
||||
fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig {
|
||||
let signature = def.signature(db);
|
||||
let data = def.data(db);
|
||||
let resolver = def.resolver(db);
|
||||
let params =
|
||||
signature.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>();
|
||||
let ret = Ty::from_hir(db, &resolver, signature.ret_type());
|
||||
let params = data.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>();
|
||||
let ret = Ty::from_hir(db, &resolver, data.ret_type());
|
||||
FnSig::from_params_and_return(params, ret)
|
||||
}
|
||||
|
||||
|
@ -371,18 +370,18 @@ fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty {
|
|||
|
||||
/// Build the declared type of a const.
|
||||
fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty {
|
||||
let signature = def.signature(db);
|
||||
let data = def.data(db);
|
||||
let resolver = def.resolver(db);
|
||||
|
||||
Ty::from_hir(db, &resolver, signature.type_ref())
|
||||
Ty::from_hir(db, &resolver, data.type_ref())
|
||||
}
|
||||
|
||||
/// Build the declared type of a static.
|
||||
fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty {
|
||||
let signature = def.signature(db);
|
||||
let data = def.data(db);
|
||||
let resolver = def.resolver(db);
|
||||
|
||||
Ty::from_hir(db, &resolver, signature.type_ref())
|
||||
Ty::from_hir(db, &resolver, data.type_ref())
|
||||
}
|
||||
|
||||
/// Build the declared type of a static.
|
||||
|
|
|
@ -192,8 +192,8 @@ fn iterate_trait_method_candidates<T>(
|
|||
let mut known_implemented = false;
|
||||
for item in data.items() {
|
||||
if let TraitItem::Function(m) = *item {
|
||||
let sig = m.signature(db);
|
||||
if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() {
|
||||
let data = m.data(db);
|
||||
if name.map_or(true, |name| data.name() == name) && data.has_self_param() {
|
||||
if !known_implemented {
|
||||
let trait_ref = canonical_trait_ref(db, t, ty.clone());
|
||||
if db.implements(krate, trait_ref).is_none() {
|
||||
|
@ -227,8 +227,8 @@ fn iterate_inherent_methods<T>(
|
|||
for impl_block in impls.lookup_impl_blocks(&ty.value) {
|
||||
for item in impl_block.items(db) {
|
||||
if let ImplItem::Method(f) = item {
|
||||
let sig = f.signature(db);
|
||||
if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() {
|
||||
let data = f.data(db);
|
||||
if name.map_or(true, |name| data.name() == name) && data.has_self_param() {
|
||||
if let Some(result) = callback(&ty.value, f) {
|
||||
return Some(result);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
|
|||
|
||||
// If we have a calling expression let's find which argument we are on
|
||||
let num_params = call_info.parameters().len();
|
||||
let has_self = function.signature(db).has_self_param();
|
||||
let has_self = function.data(db).has_self_param();
|
||||
|
||||
if num_params == 1 {
|
||||
if !has_self {
|
||||
|
|
|
@ -37,8 +37,8 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
|
|||
|
||||
fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
|
||||
ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| {
|
||||
let sig = func.signature(ctx.db);
|
||||
if sig.has_self_param() {
|
||||
let data = func.data(ctx.db);
|
||||
if data.has_self_param() {
|
||||
acc.add_function(ctx, func);
|
||||
}
|
||||
None::<()>
|
||||
|
|
|
@ -49,8 +49,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
ty.iterate_impl_items(ctx.db, krate, |item| {
|
||||
match item {
|
||||
hir::ImplItem::Method(func) => {
|
||||
let sig = func.signature(ctx.db);
|
||||
if !sig.has_self_param() {
|
||||
let data = func.data(ctx.db);
|
||||
if !data.has_self_param() {
|
||||
acc.add_function(ctx, func);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,13 +98,13 @@ impl Completions {
|
|||
name: Option<String>,
|
||||
func: hir::Function,
|
||||
) {
|
||||
let sig = func.signature(ctx.db);
|
||||
let name = name.unwrap_or_else(|| sig.name().to_string());
|
||||
let data = func.data(ctx.db);
|
||||
let name = name.unwrap_or_else(|| data.name().to_string());
|
||||
let ast_node = func.source(ctx.db).ast;
|
||||
let detail = function_label(&ast_node);
|
||||
|
||||
let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name)
|
||||
.kind(if sig.has_self_param() {
|
||||
.kind(if data.has_self_param() {
|
||||
CompletionItemKind::Method
|
||||
} else {
|
||||
CompletionItemKind::Function
|
||||
|
@ -115,10 +115,10 @@ impl Completions {
|
|||
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
||||
tested_by!(inserts_parens_for_function_calls);
|
||||
let snippet =
|
||||
if sig.params().is_empty() || sig.has_self_param() && sig.params().len() == 1 {
|
||||
format!("{}()$0", sig.name())
|
||||
if data.params().is_empty() || data.has_self_param() && data.params().len() == 1 {
|
||||
format!("{}()$0", data.name())
|
||||
} else {
|
||||
format!("{}($0)", sig.name())
|
||||
format!("{}($0)", data.name())
|
||||
};
|
||||
builder = builder.insert_snippet(snippet);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue