Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/generate_function.rs')
| -rw-r--r-- | crates/ide-assists/src/handlers/generate_function.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs index 0768389281..850be21c30 100644 --- a/crates/ide-assists/src/handlers/generate_function.rs +++ b/crates/ide-assists/src/handlers/generate_function.rs @@ -196,7 +196,7 @@ fn add_func_to_accumulator( let mut func = function_template.to_string(ctx.config.snippet_cap); if let Some(name) = adt_name { // FIXME: adt may have generic params. - func = format!("\n{indent}impl {name} {{\n{func}\n{indent}}}"); + func = format!("\n{indent}impl {} {{\n{func}\n{indent}}}", name.display(ctx.db())); } builder.edit_file(file); match ctx.config.snippet_cap { @@ -378,6 +378,8 @@ impl FunctionBuilder { fn_body, self.ret_type, self.is_async, + false, // FIXME : const and unsafe are not handled yet. + false, ); let leading_ws; let trailing_ws; @@ -438,7 +440,7 @@ fn make_return_type( Some(ty) if ty.is_unit() => (None, false), Some(ty) => { necessary_generic_params.extend(ty.generic_params(ctx.db())); - let rendered = ty.display_source_code(ctx.db(), target_module.into()); + let rendered = ty.display_source_code(ctx.db(), target_module.into(), true); match rendered { Ok(rendered) => (Some(make::ty(&rendered)), false), Err(_) => (Some(make::ty_placeholder()), true), @@ -893,14 +895,14 @@ fn filter_bounds_in_scope( let target_impl = target.parent().ancestors().find_map(ast::Impl::cast)?; let target_impl = ctx.sema.to_def(&target_impl)?; // It's sufficient to test only the first element of `generic_params` because of the order of - // insertion (see `relevant_parmas_and_where_clauses()`). + // insertion (see `params_and_where_preds_in_scope()`). let def = generic_params.first()?.self_ty_param.parent(); if def != hir::GenericDef::Impl(target_impl) { return None; } // Now we know every element that belongs to an impl would be in scope at `target`, we can - // filter them out just by lookint at their parent. + // filter them out just by looking at their parent. generic_params.retain(|it| !matches!(it.self_ty_param.parent(), hir::GenericDef::Impl(_))); where_preds.retain(|it| { it.node.syntax().parent().and_then(|it| it.parent()).and_then(ast::Impl::cast).is_none() @@ -992,9 +994,9 @@ fn fn_arg_type( let famous_defs = &FamousDefs(&ctx.sema, ctx.sema.scope(fn_arg.syntax())?.krate()); convert_reference_type(ty.strip_references(), ctx.db(), famous_defs) .map(|conversion| conversion.convert_type(ctx.db())) - .or_else(|| ty.display_source_code(ctx.db(), target_module.into()).ok()) + .or_else(|| ty.display_source_code(ctx.db(), target_module.into(), true).ok()) } else { - ty.display_source_code(ctx.db(), target_module.into()).ok() + ty.display_source_code(ctx.db(), target_module.into(), true).ok() } } @@ -1087,7 +1089,7 @@ fn calculate_necessary_visibility( } } -// This is never intended to be used as a generic graph strucuture. If there's ever another need of +// This is never intended to be used as a generic graph structure. If there's ever another need of // graph algorithm, consider adding a library for that (and replace the following). /// Minimally implemented directed graph structure represented by adjacency list. struct Graph { @@ -1910,7 +1912,6 @@ fn bar(new: fn) ${0:-> _} { #[test] fn add_function_with_closure_arg() { - // FIXME: The argument in `bar` is wrong. check_assist( generate_function, r" @@ -1925,7 +1926,7 @@ fn foo() { bar(closure) } -fn bar(closure: _) { +fn bar(closure: impl Fn(i64) -> i64) { ${0:todo!()} } ", @@ -2381,7 +2382,7 @@ mod s { } #[test] - fn create_method_with_cursor_anywhere_on_call_expresion() { + fn create_method_with_cursor_anywhere_on_call_expression() { check_assist( generate_function, r" @@ -2488,7 +2489,7 @@ fn foo() {s::S::bar();} } #[test] - fn create_static_method_with_cursor_anywhere_on_call_expresion() { + fn create_static_method_with_cursor_anywhere_on_call_expression() { check_assist( generate_function, r" |