1 use hir::{Adt, HasSource, HirDisplay, Module, Semantics, TypeInfo};
4 defs::{Definition, NameRefClass},
5 famous_defs::FamousDefs,
6 FxHashMap, FxHashSet, RootDatabase, SnippetCap,
8 use stdx::to_lower_snake_case;
12 edit::{AstNodeEdit, IndentLevel},
13 make, AstNode, CallExpr, HasArgList, HasModuleItem,
15 SyntaxKind, SyntaxNode, TextRange, TextSize,
19 utils::convert_reference_type,
20 utils::{find_struct_impl, render_snippet, Cursor},
21 AssistContext, AssistId, AssistKind, Assists,
24 // Assist: generate_function
26 // Adds a stub function with a signature matching the function under the cursor.
30 // fn baz() -> Baz { Baz }
39 // fn baz() -> Baz { Baz }
44 // fn bar(arg: &str, baz: Baz) ${0:-> _} {
49 pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
50 gen_fn(acc, ctx).or_else(|| gen_method(acc, ctx))
53 fn gen_fn(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
54 let path_expr: ast::PathExpr = ctx.find_node_at_offset()?;
55 let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?;
56 let path = path_expr.path()?;
57 let name_ref = path.segment()?.name_ref()?;
58 if ctx.sema.resolve_path(&path).is_some() {
59 // The function call already resolves, no need to add a function
63 let fn_name = &*name_ref.text();
64 let TargetInfo { target_module, adt_name, target, file, insert_offset } =
65 fn_target_info(ctx, path, &call, fn_name)?;
66 let function_builder = FunctionBuilder::from_call(ctx, &call, fn_name, target_module, target)?;
67 let text_range = call.syntax().text_range();
68 let label = format!("Generate {} function", function_builder.fn_name);
69 add_func_to_accumulator(
82 target_module: Option<Module>,
83 adt_name: Option<hir::Name>,
84 target: GeneratedFunctionTarget,
86 insert_offset: TextSize,
91 target_module: Option<Module>,
92 adt_name: Option<hir::Name>,
93 target: GeneratedFunctionTarget,
95 insert_offset: TextSize,
97 Self { target_module, adt_name, target, file, insert_offset }
102 ctx: &AssistContext<'_>,
106 ) -> Option<TargetInfo> {
107 match path.qualifier() {
108 Some(qualifier) => match ctx.sema.resolve_path(&qualifier) {
109 Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) => {
110 get_fn_target_info(ctx, &Some(module), call.clone())
112 Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => {
113 if let hir::Adt::Enum(_) = adt {
114 // Don't suggest generating function if the name starts with an uppercase letter
115 if fn_name.starts_with(char::is_uppercase) {
120 assoc_fn_target_info(ctx, call, adt, fn_name)
122 Some(hir::PathResolution::SelfType(impl_)) => {
123 let adt = impl_.self_ty(ctx.db()).as_adt()?;
124 assoc_fn_target_info(ctx, call, adt, fn_name)
128 _ => get_fn_target_info(ctx, &None, call.clone()),
132 fn gen_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
133 let call: ast::MethodCallExpr = ctx.find_node_at_offset()?;
134 if ctx.sema.resolve_method_call(&call).is_some() {
138 let fn_name = call.name_ref()?;
139 let adt = ctx.sema.type_of_expr(&call.receiver()?)?.original().strip_references().as_adt()?;
141 let current_module = ctx.sema.scope(call.syntax())?.module();
142 let target_module = adt.module(ctx.sema.db);
144 if current_module.krate() != target_module.krate() {
147 let (impl_, file) = get_adt_source(ctx, &adt, fn_name.text().as_str())?;
148 let (target, insert_offset) = get_method_target(ctx, &impl_, &adt)?;
150 let function_builder =
151 FunctionBuilder::from_method_call(ctx, &call, &fn_name, target_module, target)?;
152 let text_range = call.syntax().text_range();
153 let adt_name = if impl_.is_none() { Some(adt.name(ctx.sema.db)) } else { None };
154 let label = format!("Generate {} method", function_builder.fn_name);
155 add_func_to_accumulator(
167 fn add_func_to_accumulator(
169 ctx: &AssistContext<'_>,
170 text_range: TextRange,
171 function_builder: FunctionBuilder,
172 insert_offset: TextSize,
174 adt_name: Option<hir::Name>,
177 acc.add(AssistId("generate_function", AssistKind::Generate), label, text_range, |builder| {
178 let indent = IndentLevel::from_node(function_builder.target.syntax());
179 let function_template = function_builder.render(adt_name.is_some());
180 let mut func = function_template.to_string(ctx.config.snippet_cap);
181 if let Some(name) = adt_name {
182 func = format!("\n{}impl {} {{\n{}\n{}}}", indent, name, func, indent);
184 builder.edit_file(file);
185 match ctx.config.snippet_cap {
186 Some(cap) => builder.insert_snippet(cap, insert_offset, func),
187 None => builder.insert(insert_offset, func),
193 ctx: &AssistContext<'_>,
196 ) -> Option<(Option<ast::Impl>, FileId)> {
197 let range = adt.source(ctx.sema.db)?.syntax().original_file_range(ctx.sema.db);
198 let file = ctx.sema.parse(range.file_id);
200 ctx.sema.find_node_at_offset_with_macros(file.syntax(), range.range.start())?;
201 find_struct_impl(ctx, &adt_source, fn_name).map(|impl_| (impl_, range.file_id))
204 struct FunctionTemplate {
207 ret_type: Option<ast::RetType>,
208 should_focus_return_type: bool,
210 tail_expr: ast::Expr,
213 impl FunctionTemplate {
214 fn to_string(&self, cap: Option<SnippetCap>) -> String {
217 let cursor = if self.should_focus_return_type {
218 // Focus the return type if there is one
219 match self.ret_type {
220 Some(ref ret_type) => ret_type.syntax(),
221 None => self.tail_expr.syntax(),
224 self.tail_expr.syntax()
226 render_snippet(cap, self.fn_def.syntax(), Cursor::Replace(cursor))
228 None => self.fn_def.to_string(),
231 format!("{}{}{}", self.leading_ws, f, self.trailing_ws)
235 struct FunctionBuilder {
236 target: GeneratedFunctionTarget,
238 type_params: Option<ast::GenericParamList>,
239 params: ast::ParamList,
240 ret_type: Option<ast::RetType>,
241 should_focus_return_type: bool,
246 impl FunctionBuilder {
247 /// Prepares a generated function that matches `call`.
248 /// The function is generated in `target_module` or next to `call`
250 ctx: &AssistContext<'_>,
251 call: &ast::CallExpr,
253 target_module: Option<hir::Module>,
254 target: GeneratedFunctionTarget,
256 let needs_pub = target_module.is_some();
258 target_module.or_else(|| ctx.sema.scope(target.syntax()).map(|it| it.module()))?;
259 let fn_name = make::name(fn_name);
260 let (type_params, params) =
261 fn_args(ctx, target_module, ast::CallableExpr::Call(call.clone()))?;
263 let await_expr = call.syntax().parent().and_then(ast::AwaitExpr::cast);
264 let is_async = await_expr.is_some();
266 let (ret_type, should_focus_return_type) =
267 make_return_type(ctx, &ast::Expr::CallExpr(call.clone()), target_module);
275 should_focus_return_type,
282 ctx: &AssistContext<'_>,
283 call: &ast::MethodCallExpr,
285 target_module: Module,
286 target: GeneratedFunctionTarget,
289 !module_is_descendant(&ctx.sema.scope(call.syntax())?.module(), &target_module, ctx);
290 let fn_name = make::name(&name.text());
291 let (type_params, params) =
292 fn_args(ctx, target_module, ast::CallableExpr::MethodCall(call.clone()))?;
294 let await_expr = call.syntax().parent().and_then(ast::AwaitExpr::cast);
295 let is_async = await_expr.is_some();
297 let (ret_type, should_focus_return_type) =
298 make_return_type(ctx, &ast::Expr::MethodCallExpr(call.clone()), target_module);
306 should_focus_return_type,
312 fn render(self, is_method: bool) -> FunctionTemplate {
313 let placeholder_expr = make::ext::expr_todo();
314 let fn_body = make::block_expr(vec![], Some(placeholder_expr));
315 let visibility = if self.needs_pub { Some(make::visibility_pub_crate()) } else { None };
316 let mut fn_def = make::fn_(
329 GeneratedFunctionTarget::BehindItem(it) => {
330 let mut indent = IndentLevel::from_node(&it);
333 leading_ws = format!("{}", indent);
335 leading_ws = format!("\n\n{}", indent);
338 fn_def = fn_def.indent(indent);
339 trailing_ws = String::new();
341 GeneratedFunctionTarget::InEmptyItemList(it) => {
342 let indent = IndentLevel::from_node(&it);
343 leading_ws = format!("\n{}", indent + 1);
344 fn_def = fn_def.indent(indent + 1);
345 trailing_ws = format!("\n{}", indent);
351 ret_type: fn_def.ret_type(),
352 // PANIC: we guarantee we always create a function body with a tail expr
353 tail_expr: fn_def.body().unwrap().tail_expr().unwrap(),
354 should_focus_return_type: self.should_focus_return_type,
361 /// Makes an optional return type along with whether the return type should be focused by the cursor.
362 /// If we cannot infer what the return type should be, we create a placeholder type.
364 /// The rule for whether we focus a return type or not (and thus focus the function body),
365 /// is rather simple:
366 /// * If we could *not* infer what the return type should be, focus it (so the user can fill-in
367 /// the correct return type).
368 /// * If we could infer the return type, don't focus it (and thus focus the function body) so the
369 /// user can change the `todo!` function body.
371 ctx: &AssistContext<'_>,
373 target_module: Module,
374 ) -> (Option<ast::RetType>, bool) {
375 let (ret_ty, should_focus_return_type) = {
376 match ctx.sema.type_of_expr(call).map(TypeInfo::original) {
377 Some(ty) if ty.is_unknown() => (Some(make::ty_placeholder()), true),
378 None => (Some(make::ty_placeholder()), true),
379 Some(ty) if ty.is_unit() => (None, false),
381 let rendered = ty.display_source_code(ctx.db(), target_module.into());
383 Ok(rendered) => (Some(make::ty(&rendered)), false),
384 Err(_) => (Some(make::ty_placeholder()), true),
389 let ret_type = ret_ty.map(make::ret_type);
390 (ret_type, should_focus_return_type)
393 fn get_fn_target_info(
394 ctx: &AssistContext<'_>,
395 target_module: &Option<Module>,
397 ) -> Option<TargetInfo> {
398 let (target, file, insert_offset) = get_fn_target(ctx, target_module, call)?;
399 Some(TargetInfo::new(*target_module, None, target, file, insert_offset))
403 ctx: &AssistContext<'_>,
404 target_module: &Option<Module>,
406 ) -> Option<(GeneratedFunctionTarget, FileId, TextSize)> {
407 let mut file = ctx.file_id();
408 let target = match target_module {
409 Some(target_module) => {
410 let module_source = target_module.definition_source(ctx.db());
411 let (in_file, target) = next_space_for_fn_in_module(ctx.sema.db, &module_source)?;
415 None => next_space_for_fn_after_call_site(ast::CallableExpr::Call(call))?,
417 Some((target.clone(), file, get_insert_offset(&target)))
420 fn get_method_target(
421 ctx: &AssistContext<'_>,
422 impl_: &Option<ast::Impl>,
424 ) -> Option<(GeneratedFunctionTarget, TextSize)> {
425 let target = match impl_ {
426 Some(impl_) => next_space_for_fn_in_impl(impl_)?,
428 GeneratedFunctionTarget::BehindItem(adt.source(ctx.sema.db)?.syntax().value.clone())
431 Some((target.clone(), get_insert_offset(&target)))
434 fn assoc_fn_target_info(
435 ctx: &AssistContext<'_>,
439 ) -> Option<TargetInfo> {
440 let current_module = ctx.sema.scope(call.syntax())?.module();
441 let module = adt.module(ctx.sema.db);
442 let target_module = if current_module == module { None } else { Some(module) };
443 if current_module.krate() != module.krate() {
446 let (impl_, file) = get_adt_source(ctx, &adt, fn_name)?;
447 let (target, insert_offset) = get_method_target(ctx, &impl_, &adt)?;
448 let adt_name = if impl_.is_none() { Some(adt.name(ctx.sema.db)) } else { None };
449 Some(TargetInfo::new(target_module, adt_name, target, file, insert_offset))
452 fn get_insert_offset(target: &GeneratedFunctionTarget) -> TextSize {
454 GeneratedFunctionTarget::BehindItem(it) => it.text_range().end(),
455 GeneratedFunctionTarget::InEmptyItemList(it) => it.text_range().start() + TextSize::of('{'),
460 enum GeneratedFunctionTarget {
461 BehindItem(SyntaxNode),
462 InEmptyItemList(SyntaxNode),
465 impl GeneratedFunctionTarget {
466 fn syntax(&self) -> &SyntaxNode {
468 GeneratedFunctionTarget::BehindItem(it) => it,
469 GeneratedFunctionTarget::InEmptyItemList(it) => it,
474 /// Computes the type variables and arguments required for the generated function
476 ctx: &AssistContext<'_>,
477 target_module: hir::Module,
478 call: ast::CallableExpr,
479 ) -> Option<(Option<ast::GenericParamList>, ast::ParamList)> {
480 let mut arg_names = Vec::new();
481 let mut arg_types = Vec::new();
482 for arg in call.arg_list()?.args() {
483 arg_names.push(fn_arg_name(&ctx.sema, &arg));
484 arg_types.push(fn_arg_type(ctx, target_module, &arg));
486 deduplicate_arg_names(&mut arg_names);
487 let params = arg_names.into_iter().zip(arg_types).map(|(name, ty)| {
488 make::param(make::ext::simple_ident_pat(make::name(&name)).into(), make::ty(&ty))
495 ast::CallableExpr::Call(_) => None,
496 ast::CallableExpr::MethodCall(_) => Some(make::self_param()),
503 /// Makes duplicate argument names unique by appending incrementing numbers.
506 /// let mut names: Vec<String> =
507 /// vec!["foo".into(), "foo".into(), "bar".into(), "baz".into(), "bar".into()];
508 /// deduplicate_arg_names(&mut names);
509 /// let expected: Vec<String> =
510 /// vec!["foo_1".into(), "foo_2".into(), "bar_1".into(), "baz".into(), "bar_2".into()];
511 /// assert_eq!(names, expected);
513 fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
514 let mut arg_name_counts = FxHashMap::default();
515 for name in arg_names.iter() {
516 *arg_name_counts.entry(name).or_insert(0) += 1;
518 let duplicate_arg_names: FxHashSet<String> = arg_name_counts
520 .filter(|(_, count)| *count >= 2)
521 .map(|(name, _)| name.clone())
524 let mut counter_per_name = FxHashMap::default();
525 for arg_name in arg_names.iter_mut() {
526 if duplicate_arg_names.contains(arg_name) {
527 let counter = counter_per_name.entry(arg_name.clone()).or_insert(1);
529 arg_name.push_str(&counter.to_string());
535 fn fn_arg_name(sema: &Semantics<'_, RootDatabase>, arg_expr: &ast::Expr) -> String {
536 let name = (|| match arg_expr {
537 ast::Expr::CastExpr(cast_expr) => Some(fn_arg_name(sema, &cast_expr.expr()?)),
542 .filter_map(ast::NameRef::cast)
543 .filter(|name| name.ident_token().is_some())
545 if let Some(NameRefClass::Definition(Definition::Const(_) | Definition::Static(_))) =
546 NameRefClass::classify(sema, &name_ref)
548 return Some(name_ref.to_string().to_lowercase());
550 Some(to_lower_snake_case(&name_ref.to_string()))
554 Some(mut name) if name.starts_with(|c: char| c.is_ascii_digit()) => {
555 name.insert_str(0, "arg");
559 None => "arg".to_string(),
563 fn fn_arg_type(ctx: &AssistContext<'_>, target_module: hir::Module, fn_arg: &ast::Expr) -> String {
564 fn maybe_displayed_type(
565 ctx: &AssistContext<'_>,
566 target_module: hir::Module,
568 ) -> Option<String> {
569 let ty = ctx.sema.type_of_expr(fn_arg)?.adjusted();
574 if ty.is_reference() || ty.is_mutable_reference() {
575 let famous_defs = &FamousDefs(&ctx.sema, ctx.sema.scope(fn_arg.syntax())?.krate());
576 convert_reference_type(ty.strip_references(), ctx.db(), famous_defs)
577 .map(|conversion| conversion.convert_type(ctx.db()))
578 .or_else(|| ty.display_source_code(ctx.db(), target_module.into()).ok())
580 ty.display_source_code(ctx.db(), target_module.into()).ok()
584 maybe_displayed_type(ctx, target_module, fn_arg).unwrap_or_else(|| String::from("_"))
587 /// Returns the position inside the current mod or file
588 /// directly after the current block
589 /// We want to write the generated function directly after
590 /// fns, impls or macro calls, but inside mods
591 fn next_space_for_fn_after_call_site(expr: ast::CallableExpr) -> Option<GeneratedFunctionTarget> {
592 let mut ancestors = expr.syntax().ancestors().peekable();
593 let mut last_ancestor: Option<SyntaxNode> = None;
594 while let Some(next_ancestor) = ancestors.next() {
595 match next_ancestor.kind() {
596 SyntaxKind::SOURCE_FILE => {
599 SyntaxKind::ITEM_LIST => {
600 if ancestors.peek().map(|a| a.kind()) == Some(SyntaxKind::MODULE) {
606 last_ancestor = Some(next_ancestor);
608 last_ancestor.map(GeneratedFunctionTarget::BehindItem)
611 fn next_space_for_fn_in_module(
612 db: &dyn hir::db::AstDatabase,
613 module_source: &hir::InFile<hir::ModuleSource>,
614 ) -> Option<(FileId, GeneratedFunctionTarget)> {
615 let file = module_source.file_id.original_file(db);
616 let assist_item = match &module_source.value {
617 hir::ModuleSource::SourceFile(it) => match it.items().last() {
618 Some(last_item) => GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()),
619 None => GeneratedFunctionTarget::BehindItem(it.syntax().clone()),
621 hir::ModuleSource::Module(it) => match it.item_list().and_then(|it| it.items().last()) {
622 Some(last_item) => GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()),
623 None => GeneratedFunctionTarget::InEmptyItemList(it.item_list()?.syntax().clone()),
625 hir::ModuleSource::BlockExpr(it) => {
626 if let Some(last_item) =
627 it.statements().take_while(|stmt| matches!(stmt, ast::Stmt::Item(_))).last()
629 GeneratedFunctionTarget::BehindItem(last_item.syntax().clone())
631 GeneratedFunctionTarget::InEmptyItemList(it.syntax().clone())
635 Some((file, assist_item))
638 fn next_space_for_fn_in_impl(impl_: &ast::Impl) -> Option<GeneratedFunctionTarget> {
639 if let Some(last_item) = impl_.assoc_item_list().and_then(|it| it.assoc_items().last()) {
640 Some(GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()))
642 Some(GeneratedFunctionTarget::InEmptyItemList(impl_.assoc_item_list()?.syntax().clone()))
646 fn module_is_descendant(module: &hir::Module, ans: &hir::Module, ctx: &AssistContext<'_>) -> bool {
650 for c in ans.children(ctx.sema.db) {
651 if module_is_descendant(module, &c, ctx) {
660 use crate::tests::{check_assist, check_assist_not_applicable};
665 fn add_function_with_no_args() {
686 fn add_function_from_method() {
687 // This ensures that the function is correctly generated
688 // in the next outer mod or file
713 fn add_function_directly_after_current_block() {
714 // The new fn should not be created at the end of the file or module
739 fn add_function_with_no_args_in_same_module() {
764 fn add_function_with_upper_camel_case_arg() {
779 fn bar(baz_baz: BazBaz) ${0:-> _} {
787 fn add_function_with_upper_camel_case_arg_as_cast() {
793 bar$0(&BazBaz as *const BazBaz);
799 bar(&BazBaz as *const BazBaz);
802 fn bar(baz_baz: *const BazBaz) ${0:-> _} {
810 fn add_function_with_function_call_arg() {
815 fn baz() -> Baz { todo!() }
822 fn baz() -> Baz { todo!() }
827 fn bar(baz: Baz) ${0:-> _} {
835 fn add_function_with_method_call_arg() {
841 fn foo(&self) -> Baz {
844 fn baz(&self) -> Baz {
852 fn foo(&self) -> Baz {
855 fn baz(&self) -> Baz {
860 fn bar(baz: Baz) -> Baz {
868 fn add_function_with_string_literal_arg() {
889 fn add_function_with_char_literal_arg() {
910 fn add_function_with_int_literal_arg() {
931 fn add_function_with_cast_int_literal_arg() {
952 fn name_of_cast_variable_is_used() {
953 // Ensures that the name of the cast type isn't used
954 // in the generated function signature.
977 fn add_function_with_variable_arg() {
1000 fn add_function_with_impl_trait_arg() {
1006 fn foo() -> impl Foo {
1015 fn foo() -> impl Foo {
1022 fn bar(foo: impl Foo) {
1035 fn baz() -> Baz { todo!() }
1043 fn baz() -> Baz { todo!() }
1057 fn add_function_with_qualified_path_arg() {
1063 pub fn baz() -> Bof { Bof }
1072 pub fn baz() -> Bof { Bof }
1078 fn bar(baz: Baz::Bof) {
1086 fn add_function_with_generic_arg() {
1087 // FIXME: This is wrong, generated `bar` should include generic parameter.
1108 fn add_function_with_fn_arg() {
1109 // FIXME: The argument in `bar` is wrong.
1115 fn new() -> Self { Baz }
1124 fn new() -> Self { Baz }
1130 fn bar(new: fn) ${0:-> _} {
1138 fn add_function_with_closure_arg() {
1139 // FIXME: The argument in `bar` is wrong.
1144 let closure = |x: i64| x - 1;
1150 let closure = |x: i64| x - 1;
1154 fn bar(closure: _) {
1162 fn unresolveable_types_default_to_placeholder() {
1183 fn arg_names_dont_overlap() {
1188 fn baz() -> Baz { Baz }
1195 fn baz() -> Baz { Baz }
1200 fn bar(baz_1: Baz, baz_2: Baz) {
1208 fn arg_name_counters_start_at_1_per_name() {
1213 fn baz() -> Baz { Baz }
1215 $0bar(baz(), baz(), "foo", "bar")
1220 fn baz() -> Baz { Baz }
1222 bar(baz(), baz(), "foo", "bar")
1225 fn bar(baz_1: Baz, baz_2: Baz, arg_1: &str, arg_2: &str) {
1233 fn add_function_in_module() {
1245 pub(crate) fn my_fn() {
1258 fn qualified_path_uses_correct_scope() {
1281 fn baz(foo: foo::Foo) {
1289 fn add_function_in_module_containing_other_items() {
1294 fn something_else() {}
1303 fn something_else() {}
1305 pub(crate) fn my_fn() {
1318 fn add_function_in_nested_module() {
1333 pub(crate) fn my_fn() {
1347 fn add_function_in_another_file() {
1362 pub(crate) fn bar() {
1369 fn add_function_with_return_type() {
1374 let x: u32 = foo$0();
1390 fn add_function_not_applicable_if_function_already_exists() {
1391 check_assist_not_applicable(
1404 fn add_function_not_applicable_if_unresolved_variable_in_call_is_selected() {
1405 check_assist_not_applicable(
1406 // bar is resolved, but baz isn't.
1407 // The assist is only active if the cursor is on an unresolved path,
1408 // but the assist should only be offered if the path is a function call.
1421 fn create_method_with_no_args() {
1439 fn bar(&self) ${0:-> _} {
1448 fn create_function_with_async() {
1461 async fn bar(arg: i32) ${0:-> _} {
1469 fn create_method() {
1474 fn foo() {S.bar$0();}
1479 fn bar(&self) ${0:-> _} {
1489 fn create_method_within_an_impl() {
1494 fn foo() {S.bar$0();}
1502 fn bar(&self) ${0:-> _} {
1512 fn create_method_from_different_module() {
1519 fn foo() {s::S.bar$0();}
1525 pub(crate) fn bar(&self) ${0:-> _} {
1530 fn foo() {s::S.bar();}
1536 fn create_method_from_descendant_module() {
1551 fn bar(&self) ${0:-> _} {
1566 fn create_method_with_cursor_anywhere_on_call_expresion() {
1571 fn foo() {$0S.bar();}
1576 fn bar(&self) ${0:-> _} {
1586 fn create_static_method() {
1591 fn foo() {S::bar$0();}
1596 fn bar() ${0:-> _} {
1600 fn foo() {S::bar();}
1606 fn create_static_method_within_an_impl() {
1611 fn foo() {S::bar$0();}
1617 fn foo() {S::bar();}
1619 fn bar() ${0:-> _} {
1629 fn create_static_method_from_different_module() {
1636 fn foo() {s::S::bar$0();}
1642 pub(crate) fn bar() ${0:-> _} {
1647 fn foo() {s::S::bar();}
1653 fn create_static_method_with_cursor_anywhere_on_call_expresion() {
1658 fn foo() {$0S::bar();}
1663 fn bar() ${0:-> _} {
1667 fn foo() {S::bar();}
1673 fn create_static_method_within_an_impl_with_self_syntax() {
1691 fn bar() ${0:-> _} {
1700 fn no_panic_on_invalid_global_path() {
1713 fn foo() ${0:-> _} {
1721 fn handle_tuple_indexing() {
1736 fn foo(a: ()) ${0:-> _} {
1744 fn add_function_with_const_arg() {
1748 const VALUE: usize = 0;
1754 const VALUE: usize = 0;
1759 fn foo(value: usize) ${0:-> _} {
1767 fn add_function_with_static_arg() {
1771 static VALUE: usize = 0;
1777 static VALUE: usize = 0;
1782 fn foo(value: usize) ${0:-> _} {
1790 fn add_function_with_static_mut_arg() {
1794 static mut VALUE: usize = 0;
1800 static mut VALUE: usize = 0;
1805 fn foo(value: usize) ${0:-> _} {
1813 fn not_applicable_for_enum_variant() {
1814 check_assist_not_applicable(
1826 fn applicable_for_enum_method() {
1838 fn new() ${0:-> _} {