mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
simplify
This commit is contained in:
parent
3c7c5a7354
commit
9af525dbd6
4 changed files with 31 additions and 35 deletions
|
@ -1,6 +1,6 @@
|
||||||
use hir::{Ty, AdtDef};
|
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).
|
/// Complete dot accesses, i.e. fields or methods (currently only fields).
|
||||||
pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
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 {
|
match def_id {
|
||||||
AdtDef::Struct(s) => {
|
AdtDef::Struct(s) => {
|
||||||
for field in s.fields(ctx.db) {
|
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) => {
|
Ty::Tuple(fields) => {
|
||||||
for (i, ty) in fields.iter().enumerate() {
|
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| {
|
receiver.iterate_methods(ctx.db, |_ty, func| {
|
||||||
let sig = func.signature(ctx.db);
|
let sig = func.signature(ctx.db);
|
||||||
if sig.has_self_param() {
|
if sig.has_self_param() {
|
||||||
acc.add_function(CompletionKind::Reference, ctx, func);
|
acc.add_function(ctx, func);
|
||||||
}
|
}
|
||||||
None::<()>
|
None::<()>
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
hir::ImplItem::Method(func) => {
|
hir::ImplItem::Method(func) => {
|
||||||
let sig = func.signature(ctx.db);
|
let sig = func.signature(ctx.db);
|
||||||
if !sig.has_self_param() {
|
if !sig.has_self_param() {
|
||||||
acc.add_function(CompletionKind::Reference, ctx, func);
|
acc.add_function(ctx, func);
|
||||||
}
|
}
|
||||||
None::<()>
|
None::<()>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use hir::{Ty, AdtDef};
|
use hir::{Ty, AdtDef};
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, Completions, CompletionKind};
|
use crate::completion::{CompletionContext, Completions};
|
||||||
|
|
||||||
/// Complete fields in fields literals.
|
/// Complete fields in fields literals.
|
||||||
pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) {
|
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 {
|
match adt {
|
||||||
AdtDef::Struct(s) => {
|
AdtDef::Struct(s) => {
|
||||||
for field in s.fields(ctx.db) {
|
for field in s.fields(ctx.db) {
|
||||||
acc.add_field(CompletionKind::Reference, ctx, field, substs);
|
acc.add_field(ctx, field, substs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,40 +10,36 @@ use crate::completion::{
|
||||||
impl Completions {
|
impl Completions {
|
||||||
pub(crate) fn add_field(
|
pub(crate) fn add_field(
|
||||||
&mut self,
|
&mut self,
|
||||||
kind: CompletionKind,
|
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
field: hir::StructField,
|
field: hir::StructField,
|
||||||
substs: &hir::Substs,
|
substs: &hir::Substs,
|
||||||
) {
|
) {
|
||||||
CompletionItem::new(kind, ctx.source_range(), field.name(ctx.db).to_string())
|
CompletionItem::new(
|
||||||
|
CompletionKind::Reference,
|
||||||
|
ctx.source_range(),
|
||||||
|
field.name(ctx.db).to_string(),
|
||||||
|
)
|
||||||
.kind(CompletionItemKind::Field)
|
.kind(CompletionItemKind::Field)
|
||||||
.detail(field.ty(ctx.db).subst(substs).to_string())
|
.detail(field.ty(ctx.db).subst(substs).to_string())
|
||||||
.set_documentation(field.docs(ctx.db))
|
.set_documentation(field.docs(ctx.db))
|
||||||
.add_to(self);
|
.add_to(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_pos_field(
|
pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) {
|
||||||
&mut self,
|
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string())
|
||||||
kind: CompletionKind,
|
|
||||||
ctx: &CompletionContext,
|
|
||||||
field: usize,
|
|
||||||
ty: &hir::Ty,
|
|
||||||
) {
|
|
||||||
CompletionItem::new(kind, ctx.source_range(), field.to_string())
|
|
||||||
.kind(CompletionItemKind::Field)
|
.kind(CompletionItemKind::Field)
|
||||||
.detail(ty.to_string())
|
.detail(ty.to_string())
|
||||||
.add_to(self);
|
.add_to(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_function(
|
pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) {
|
||||||
&mut self,
|
|
||||||
kind: CompletionKind,
|
|
||||||
ctx: &CompletionContext,
|
|
||||||
func: hir::Function,
|
|
||||||
) {
|
|
||||||
let sig = func.signature(ctx.db);
|
let sig = func.signature(ctx.db);
|
||||||
|
|
||||||
let mut builder = CompletionItem::new(kind, ctx.source_range(), sig.name().to_string())
|
let mut builder = CompletionItem::new(
|
||||||
|
CompletionKind::Reference,
|
||||||
|
ctx.source_range(),
|
||||||
|
sig.name().to_string(),
|
||||||
|
)
|
||||||
.kind(if sig.has_self_param() {
|
.kind(if sig.has_self_param() {
|
||||||
CompletionItemKind::Method
|
CompletionItemKind::Method
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue