From 77c26c2bf111314cc3be7ef100b6318a698c8089 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 1 Nov 2019 00:15:15 +0100 Subject: Complete items on traits as well --- crates/ra_ide_api/src/completion/complete_path.rs | 48 ++++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 940858342..2aec8eb26 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -82,6 +82,20 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { }); } } + hir::ModuleDef::Trait(t) => { + for item in t.items(ctx.db) { + match item { + hir::AssocItem::Function(func) => { + let data = func.data(ctx.db); + if !data.has_self_param() { + acc.add_function(ctx, func); + } + } + hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), + hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), + } + } + } _ => {} }; } @@ -587,7 +601,22 @@ mod tests { fn foo() { let _ = Trait::<|> } " ), - @"[]" + @r###" + [ + CompletionItem { + label: "m()", + source_range: [73; 73), + delete: [73; 73), + insert: "m()$0", + kind: Function, + lookup: "m", + detail: "fn m()", + documentation: Documentation( + "A trait method", + ), + }, + ] + "### ); } @@ -644,7 +673,22 @@ mod tests { fn foo() { let _ = ::<|> } " ), - @"[]" + @r###" + [ + CompletionItem { + label: "m()", + source_range: [110; 110), + delete: [110; 110), + insert: "m()$0", + kind: Function, + lookup: "m", + detail: "fn m()", + documentation: Documentation( + "A trait method", + ), + }, + ] + "### ); } -- cgit v1.2.3