Skip to content

Commit f221676

Browse files
committed
Auto merge of #12186 - Veykril:completion-rev, r=Veykril
minor: Move inferred type completions
2 parents 6f6e4ef + 1dc83f5 commit f221676

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

crates/ide-completion/src/completions.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,19 @@ pub(crate) mod vis;
2222

2323
use std::iter;
2424

25-
use hir::{db::HirDatabase, known, HirDisplay, ScopeDef};
25+
use hir::{db::HirDatabase, known, ScopeDef};
2626
use ide_db::SymbolKind;
2727

2828
use crate::{
2929
context::Visible,
3030
item::Builder,
31-
patterns::{ImmediateLocation, TypeAnnotation},
3231
render::{
3332
const_::render_const,
3433
function::{render_fn, render_method},
3534
literal::{render_struct_literal, render_variant_lit},
3635
macro_::render_macro,
3736
pattern::{render_struct_pat, render_variant_pat},
3837
render_field, render_resolution, render_resolution_simple, render_tuple_field,
39-
render_type_inference,
4038
type_alias::{render_type_alias, render_type_alias_with_eq},
4139
union_literal::render_union_literal,
4240
RenderContext,
@@ -401,19 +399,3 @@ fn enum_variants_with_paths(
401399
}
402400
}
403401
}
404-
405-
pub(crate) fn inferred_type(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
406-
use TypeAnnotation::*;
407-
let pat = match &ctx.completion_location {
408-
Some(ImmediateLocation::TypeAnnotation(t)) => t,
409-
_ => return None,
410-
};
411-
let x = match pat {
412-
Let(pat) | FnParam(pat) => ctx.sema.type_of_pat(pat.as_ref()?),
413-
Const(exp) | RetType(exp) => ctx.sema.type_of_expr(exp.as_ref()?),
414-
}?
415-
.adjusted();
416-
let ty_string = x.display_source_code(ctx.db, ctx.module.into()).ok()?;
417-
acc.add(render_type_inference(ty_string, ctx));
418-
None
419-
}

crates/ide-completion/src/completions/type.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! Completion of names from the current scope in type position.
22
3-
use hir::ScopeDef;
3+
use hir::{HirDisplay, ScopeDef};
44
use ide_db::FxHashSet;
55
use syntax::{ast, AstNode};
66

77
use crate::{
88
context::{PathCompletionCtx, PathKind, PathQualifierCtx},
9-
patterns::ImmediateLocation,
9+
patterns::{ImmediateLocation, TypeAnnotation},
10+
render::render_type_inference,
1011
CompletionContext, Completions,
1112
};
1213

@@ -184,6 +185,22 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
184185
}
185186
}
186187

188+
pub(crate) fn complete_inferred_type(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
189+
use TypeAnnotation::*;
190+
let pat = match &ctx.completion_location {
191+
Some(ImmediateLocation::TypeAnnotation(t)) => t,
192+
_ => return None,
193+
};
194+
let x = match pat {
195+
Let(pat) | FnParam(pat) => ctx.sema.type_of_pat(pat.as_ref()?),
196+
Const(exp) | RetType(exp) => ctx.sema.type_of_expr(exp.as_ref()?),
197+
}?
198+
.adjusted();
199+
let ty_string = x.display_source_code(ctx.db, ctx.module.into()).ok()?;
200+
acc.add(render_type_inference(ty_string, ctx));
201+
None
202+
}
203+
187204
fn add_assoc_item(acc: &mut Completions, ctx: &CompletionContext, item: hir::AssocItem) {
188205
match item {
189206
hir::AssocItem::Const(ct) if ctx.expects_generic_arg() => acc.add_const(ctx, ct),

crates/ide-completion/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub struct CompletionRelevance {
149149
pub is_private_editable: bool,
150150
/// Set for postfix snippet item completions
151151
pub postfix_match: Option<CompletionRelevancePostfixMatch>,
152-
/// This is setted for type inference results
152+
/// This is set for type inference results
153153
pub is_definite: bool,
154154
}
155155

crates/ide-completion/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ pub fn completions(
159159
completions::fn_param::complete_fn_param(acc, ctx);
160160
completions::format_string::format_string(acc, ctx);
161161
completions::item_list::complete_item_list(acc, ctx);
162-
completions::inferred_type(acc, ctx);
163162
completions::keyword::complete_expr_keyword(acc, ctx);
164163
completions::lifetime::complete_label(acc, ctx);
165164
completions::lifetime::complete_lifetime(acc, ctx);
@@ -172,6 +171,7 @@ pub fn completions(
172171
completions::snippet::complete_item_snippet(acc, ctx);
173172
completions::trait_impl::complete_trait_impl(acc, ctx);
174173
completions::r#type::complete_type_path(acc, ctx);
174+
completions::r#type::complete_inferred_type(acc, ctx);
175175
completions::use_::complete_use_tree(acc, ctx);
176176
completions::vis::complete_vis(acc, ctx);
177177
}

0 commit comments

Comments
 (0)