Skip to content

Commit 22caf98

Browse files
committed
Added associated type completion.
1 parent 5c0c189 commit 22caf98

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

crates/ra_ide/src/completion/complete_trait_impl.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
9797
for item in missing_items {
9898
match item {
9999
hir::AssocItem::Function(f) => add_function_impl(acc, ctx, f),
100-
_ => {}
100+
hir::AssocItem::TypeAlias(t) => add_type_alias_impl(acc, ctx, t),
101+
_ => {},
101102
}
102103
}
103104
}
@@ -121,7 +122,7 @@ fn resolve_target_trait(
121122
}
122123
}
123124

124-
pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext, func: &hir::Function) {
125+
fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext, func: &hir::Function) {
125126
use crate::display::FunctionSignature;
126127

127128
let display = FunctionSignature::from_hir(ctx.db, func.clone());
@@ -135,7 +136,8 @@ pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext,
135136
};
136137

137138
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));
139141

140142
let completion_kind = if func.has_self_param(ctx.db) {
141143
CompletionItemKind::Method
@@ -155,6 +157,16 @@ pub(crate) fn add_function_impl(acc: &mut Completions, ctx: &CompletionContext,
155157
.add_to(acc);
156158
}
157159

160+
fn 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+
158170
#[cfg(test)]
159171
mod tests {
160172
use crate::completion::{do_completion, CompletionItem, CompletionKind};

0 commit comments

Comments
 (0)