simplify
This commit is contained in:
parent
3c7c5a7354
commit
9af525dbd6
crates/ra_ide_api/src/completion
@ -1,6 +1,6 @@
|
||||
use hir::{Ty, AdtDef};
|
||||
|
||||
use crate::completion::{CompletionContext, Completions, CompletionKind};
|
||||
use crate::completion::{CompletionContext, Completions};
|
||||
|
||||
/// Complete dot accesses, i.e. fields or methods (currently only fields).
|
||||
pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
@ -28,7 +28,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
|
||||
match def_id {
|
||||
AdtDef::Struct(s) => {
|
||||
for field in s.fields(ctx.db) {
|
||||
acc.add_field(CompletionKind::Reference, ctx, field, substs);
|
||||
acc.add_field(ctx, field, substs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
|
||||
}
|
||||
Ty::Tuple(fields) => {
|
||||
for (i, ty) in fields.iter().enumerate() {
|
||||
acc.add_pos_field(CompletionKind::Reference, ctx, i, ty);
|
||||
acc.add_pos_field(ctx, i, ty);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -50,7 +50,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty
|
||||
receiver.iterate_methods(ctx.db, |_ty, func| {
|
||||
let sig = func.signature(ctx.db);
|
||||
if sig.has_self_param() {
|
||||
acc.add_function(CompletionKind::Reference, ctx, func);
|
||||
acc.add_function(ctx, func);
|
||||
}
|
||||
None::<()>
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
hir::ImplItem::Method(func) => {
|
||||
let sig = func.signature(ctx.db);
|
||||
if !sig.has_self_param() {
|
||||
acc.add_function(CompletionKind::Reference, ctx, func);
|
||||
acc.add_function(ctx, func);
|
||||
}
|
||||
None::<()>
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use hir::{Ty, AdtDef};
|
||||
|
||||
use crate::completion::{CompletionContext, Completions, CompletionKind};
|
||||
use crate::completion::{CompletionContext, Completions};
|
||||
|
||||
/// Complete fields in fields literals.
|
||||
pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
@ -22,7 +22,7 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
|
||||
match adt {
|
||||
AdtDef::Struct(s) => {
|
||||
for field in s.fields(ctx.db) {
|
||||
acc.add_field(CompletionKind::Reference, ctx, field, substs);
|
||||
acc.add_field(ctx, field, substs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,47 +10,43 @@ use crate::completion::{
|
||||
impl Completions {
|
||||
pub(crate) fn add_field(
|
||||
&mut self,
|
||||
kind: CompletionKind,
|
||||
ctx: &CompletionContext,
|
||||
field: hir::StructField,
|
||||
substs: &hir::Substs,
|
||||
) {
|
||||
CompletionItem::new(kind, ctx.source_range(), field.name(ctx.db).to_string())
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(field.ty(ctx.db).subst(substs).to_string())
|
||||
.set_documentation(field.docs(ctx.db))
|
||||
.add_to(self);
|
||||
CompletionItem::new(
|
||||
CompletionKind::Reference,
|
||||
ctx.source_range(),
|
||||
field.name(ctx.db).to_string(),
|
||||
)
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(field.ty(ctx.db).subst(substs).to_string())
|
||||
.set_documentation(field.docs(ctx.db))
|
||||
.add_to(self);
|
||||
}
|
||||
|
||||
pub(crate) fn add_pos_field(
|
||||
&mut self,
|
||||
kind: CompletionKind,
|
||||
ctx: &CompletionContext,
|
||||
field: usize,
|
||||
ty: &hir::Ty,
|
||||
) {
|
||||
CompletionItem::new(kind, ctx.source_range(), field.to_string())
|
||||
pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) {
|
||||
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string())
|
||||
.kind(CompletionItemKind::Field)
|
||||
.detail(ty.to_string())
|
||||
.add_to(self);
|
||||
}
|
||||
|
||||
pub(crate) fn add_function(
|
||||
&mut self,
|
||||
kind: CompletionKind,
|
||||
ctx: &CompletionContext,
|
||||
func: hir::Function,
|
||||
) {
|
||||
pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) {
|
||||
let sig = func.signature(ctx.db);
|
||||
|
||||
let mut builder = CompletionItem::new(kind, ctx.source_range(), sig.name().to_string())
|
||||
.kind(if sig.has_self_param() {
|
||||
CompletionItemKind::Method
|
||||
} else {
|
||||
CompletionItemKind::Function
|
||||
})
|
||||
.set_documentation(func.docs(ctx.db))
|
||||
.set_detail(function_item_label(ctx, func));
|
||||
let mut builder = CompletionItem::new(
|
||||
CompletionKind::Reference,
|
||||
ctx.source_range(),
|
||||
sig.name().to_string(),
|
||||
)
|
||||
.kind(if sig.has_self_param() {
|
||||
CompletionItemKind::Method
|
||||
} else {
|
||||
CompletionItemKind::Function
|
||||
})
|
||||
.set_documentation(func.docs(ctx.db))
|
||||
.set_detail(function_item_label(ctx, func));
|
||||
// If not an import, add parenthesis automatically.
|
||||
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
||||
tested_by!(inserts_parens_for_function_calls);
|
||||
|
Loading…
x
Reference in New Issue
Block a user