aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index d147bd11d..528655fbc 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -97,7 +97,8 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
97 for item in missing_items { 97 for item in missing_items {
98 match item { 98 match item {
99 hir::AssocItem::Function(f) => add_function_impl(acc, ctx, f), 99 hir::AssocItem::Function(f) => add_function_impl(acc, ctx, f),
100 _ => {} 100 hir::AssocItem::TypeAlias(t) => add_type_alias_impl(acc, ctx, t),
101 _ => {},
101 } 102 }
102 } 103 }
103} 104}
@@ -121,7 +122,7 @@ fn resolve_target_trait(
121 } 122 }
122} 123}
123 124
124pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext, func: &hir::Function) { 125fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext, func: &hir::Function) {
125 use crate::display::FunctionSignature; 126 use crate::display::FunctionSignature;
126 127
127 let display = FunctionSignature::from_hir(ctx.db, func.clone()); 128 let display = FunctionSignature::from_hir(ctx.db, func.clone());
@@ -135,7 +136,8 @@ pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext,
135 }; 136 };
136 137
137 let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label.clone()) 138 let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label.clone())
138 .lookup_by(label); 139 .lookup_by(label)
140 .set_documentation(func.docs(ctx.db));
139 141
140 let completion_kind = if func.has_self_param(ctx.db) { 142 let completion_kind = if func.has_self_param(ctx.db) {
141 CompletionItemKind::Method 143 CompletionItemKind::Method
@@ -155,6 +157,16 @@ pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext,
155 .add_to(acc); 157 .add_to(acc);
156} 158}
157 159
160fn add_type_alias_impl(acc: &mut Completions, ctx: &CompletionContext, type_alias: &hir::TypeAlias) {
161 let snippet = format!("type {} = ", type_alias.name(ctx.db).to_string());
162
163 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
164 .insert_text(snippet)
165 .kind(CompletionItemKind::TypeAlias)
166 .set_documentation(type_alias.docs(ctx.db))
167 .add_to(acc);
168}
169
158#[cfg(test)] 170#[cfg(test)]
159mod tests { 171mod tests {
160 use crate::completion::{do_completion, CompletionItem, CompletionKind}; 172 use crate::completion::{do_completion, CompletionItem, CompletionKind};