mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Merge #4126
4126: Don't omit methods with self from path completion r=matklad a=jonas-schievink It's sometimes useful to create a reference to these items (eg. for use as a function pointer). Perhaps these should be given lower score though, if that's possible? Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
bdd22eb8bd
1 changed files with 38 additions and 6 deletions
|
@ -57,10 +57,8 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
}
|
}
|
||||||
match item {
|
match item {
|
||||||
hir::AssocItem::Function(func) => {
|
hir::AssocItem::Function(func) => {
|
||||||
if !func.has_self_param(ctx.db) {
|
|
||||||
acc.add_function(ctx, func, None);
|
acc.add_function(ctx, func, None);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
||||||
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
||||||
}
|
}
|
||||||
|
@ -86,10 +84,8 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
}
|
}
|
||||||
match item {
|
match item {
|
||||||
hir::AssocItem::Function(func) => {
|
hir::AssocItem::Function(func) => {
|
||||||
if !func.has_self_param(ctx.db) {
|
|
||||||
acc.add_function(ctx, func, None);
|
acc.add_function(ctx, func, None);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
||||||
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
||||||
}
|
}
|
||||||
|
@ -482,6 +478,42 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn completes_struct_associated_method_with_self() {
|
||||||
|
assert_debug_snapshot!(
|
||||||
|
do_reference_completion(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
/// A Struct
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
/// An associated method
|
||||||
|
fn m(&self) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() { let _ = S::<|> }
|
||||||
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
[
|
||||||
|
CompletionItem {
|
||||||
|
label: "m()",
|
||||||
|
source_range: [105; 105),
|
||||||
|
delete: [105; 105),
|
||||||
|
insert: "m()$0",
|
||||||
|
kind: Method,
|
||||||
|
lookup: "m",
|
||||||
|
detail: "fn m(&self)",
|
||||||
|
documentation: Documentation(
|
||||||
|
"An associated method",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_struct_associated_const() {
|
fn completes_struct_associated_const() {
|
||||||
assert_debug_snapshot!(
|
assert_debug_snapshot!(
|
||||||
|
|
Loading…
Reference in a new issue